-
-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open shader core API by ShaderLab #274
Changes from 81 commits
4555409
2083f73
f7000ef
b5537a3
4f52bb1
4277188
6f1bb85
9de2d4a
f9fa541
6528327
ac62e5a
271ab34
46b29f0
2aeb827
b77eedc
a0b9812
9f1b534
91e1b69
cff36bc
c1a8901
f2b8a00
f51f874
008bb2d
d249f37
0f7e615
1825da4
073f951
db9703f
640fddd
480b43d
1d8a2bb
4005483
702a574
d850b70
19dd765
0c50d1a
0d455e8
5189541
022a9f2
4326a2e
8c8bdfb
24b96a6
c3bd539
93161ae
9285572
bb48d43
dbf5d2d
26a48cf
190609d
412549e
4f2f373
9e07c00
7aba925
562c128
0c8faa5
e78d604
054c43e
544c5d4
9e7f2d2
761f107
d86f3f4
15adf57
b196c78
7d87e38
94d142f
178ef1d
b1874b2
f358db7
0fadeea
8791680
460bc03
14b03d1
99b02e7
0d28e97
f85cc8d
71c39db
7384531
7802c98
459e8d7
dfca3ab
561c531
de4af12
a6a2151
57945a5
67fdc58
c8ac015
7403430
1cbf9be
0ad84df
9eac515
f6ebf97
d21e3c6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,7 +71,7 @@ | |
}, | ||
"pnpm": { | ||
"overrides": { | ||
"@galacean/engine": "^1.2.0-alpha.5" | ||
"@galacean/engine": "^1.2.0-beta.1" | ||
} | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,23 @@ | ||
export { GSLPBRMaterial } from "./GSLPBRMaterial"; | ||
import { Shader, ShaderFactory } from "@galacean/engine"; | ||
import { PBRSource, fragmentList } from "./shaders"; | ||
|
||
let includeRegistered = false; | ||
let shaderRegistered = false; | ||
|
||
export function registerIncludes() { | ||
if (includeRegistered) return; | ||
|
||
for (const sourceFragment of fragmentList) { | ||
ShaderFactory.registerInclude(sourceFragment.includeKey, sourceFragment.source); | ||
} | ||
|
||
includeRegistered = true; | ||
} | ||
|
||
export function registerShader() { | ||
if (shaderRegistered) return; | ||
|
||
Shader.create(PBRSource); | ||
|
||
shaderRegistered = true; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#ifndef BLENDSHAPE_INCLUDED | ||
#define BLENDSHAPE_INCLUDED | ||
|
||
#ifdef RENDERER_HAS_BLENDSHAPE | ||
#ifdef RENDERER_BLENDSHAPE_USE_TEXTURE | ||
mediump sampler2DArray renderer_BlendShapeTexture; | ||
ivec3 renderer_BlendShapeTextureInfo; | ||
float renderer_BlendShapeWeights[RENDERER_BLENDSHAPE_COUNT]; | ||
|
||
vec3 getBlendShapeVertexElement(int blendShapeIndex, int vertexElementIndex){ | ||
int y = vertexElementIndex / renderer_BlendShapeTextureInfo.y; | ||
int x = vertexElementIndex - y * renderer_BlendShapeTextureInfo.y; | ||
ivec3 uv = ivec3(x, y , blendShapeIndex); | ||
return (texelFetch(renderer_BlendShapeTexture, uv, 0)).xyz; | ||
} | ||
#else | ||
#if defined( RENDERER_BLENDSHAPE_HAS_NORMAL ) && defined( RENDERER_BLENDSHAPE_HAS_TANGENT ) | ||
float renderer_BlendShapeWeights[2]; | ||
#else | ||
#if defined( RENDERER_BLENDSHAPE_HAS_NORMAL ) || defined( RENDERER_BLENDSHAPE_HAS_TANGENT ) | ||
float renderer_BlendShapeWeights[4]; | ||
#else | ||
float renderer_BlendShapeWeights[8]; | ||
#endif | ||
#endif | ||
#endif | ||
|
||
void calculateBlendShape(Attributes attr, inout vec4 position | ||
#ifdef RENDERER_HAS_NORMAL | ||
,inout vec3 normal | ||
#endif | ||
#ifdef RENDERER_HAS_TANGENT | ||
,inout vec4 tangent | ||
#endif | ||
){ | ||
#ifdef RENDERER_BLENDSHAPE_USE_TEXTURE | ||
int vertexOffset = gl_VertexID * renderer_BlendShapeTextureInfo.x; | ||
for(int i = 0; i < RENDERER_BLENDSHAPE_COUNT; i++){ | ||
int vertexElementOffset = vertexOffset; | ||
float weight = renderer_BlendShapeWeights[i]; | ||
// Warnning: Multiplying by 0 creates weird precision issues, causing rendering anomalies in Ace2 Android13 | ||
if(weight != 0.0){ | ||
position.xyz += getBlendShapeVertexElement(i, vertexElementOffset) * weight; | ||
|
||
#if defined( RENDERER_HAS_NORMAL ) && defined( RENDERER_BLENDSHAPE_HAS_NORMAL ) | ||
vertexElementOffset += 1; | ||
normal += getBlendShapeVertexElement(i, vertexElementOffset) * weight; | ||
#endif | ||
|
||
#if defined( RENDERER_HAS_TANGENT ) && defined(RENDERER_BLENDSHAPE_HAS_TANGENT) | ||
vertexElementOffset += 1; | ||
tangent.xyz += getBlendShapeVertexElement(i, vertexElementOffset) * weight; | ||
#endif | ||
} | ||
|
||
} | ||
#else | ||
position.xyz += attr.POSITION_BS0 * renderer_BlendShapeWeights[0]; | ||
position.xyz += attr.POSITION_BS1 * renderer_BlendShapeWeights[1]; | ||
|
||
#if defined( RENDERER_BLENDSHAPE_HAS_NORMAL ) && defined( RENDERER_BLENDSHAPE_HAS_TANGENT ) | ||
#ifdef RENDERER_HAS_NORMAL | ||
normal += attr.NORMAL_BS0 * renderer_BlendShapeWeights[0]; | ||
normal += attr.NORMAL_BS1 * renderer_BlendShapeWeights[1]; | ||
#endif | ||
|
||
#ifdef RENDERER_HAS_TANGENT | ||
tangent.xyz += attr.TANGENT_BS0 * renderer_BlendShapeWeights[0]; | ||
tangent.xyz += attr.TANGENT_BS1 * renderer_BlendShapeWeights[1]; | ||
#endif | ||
#else | ||
#if defined( RENDERER_BLENDSHAPE_HAS_NORMAL ) || defined( RENDERER_BLENDSHAPE_HAS_TANGENT ) | ||
position.xyz += attr.POSITION_BS2 * renderer_BlendShapeWeights[2]; | ||
position.xyz += attr.POSITION_BS3 * renderer_BlendShapeWeights[3]; | ||
|
||
#if defined( RENDERER_BLENDSHAPE_HAS_NORMAL ) && defined( RENDERER_HAS_NORMAL ) | ||
normal += attr.NORMAL_BS0 * renderer_BlendShapeWeights[0]; | ||
normal += attr.NORMAL_BS1 * renderer_BlendShapeWeights[1]; | ||
normal += attr.NORMAL_BS2 * renderer_BlendShapeWeights[2]; | ||
normal += attr.NORMAL_BS3 * renderer_BlendShapeWeights[3]; | ||
#endif | ||
|
||
#if defined(RENDERER_BLENDSHAPE_HAS_TANGENT) && defined( RENDERER_HAS_TANGENT ) | ||
tangent.xyz += attr.TANGENT_BS0 * renderer_BlendShapeWeights[0]; | ||
tangent.xyz += attr.TANGENT_BS1 * renderer_BlendShapeWeights[1]; | ||
tangent.xyz += attr.TANGENT_BS2 * renderer_BlendShapeWeights[2]; | ||
tangent.xyz += attr.TANGENT_BS3 * renderer_BlendShapeWeights[3]; | ||
#endif | ||
#else | ||
position.xyz += attr.POSITION_BS2 * renderer_BlendShapeWeights[2]; | ||
position.xyz += attr.POSITION_BS3 * renderer_BlendShapeWeights[3]; | ||
position.xyz += attr.POSITION_BS4 * renderer_BlendShapeWeights[4]; | ||
position.xyz += attr.POSITION_BS5 * renderer_BlendShapeWeights[5]; | ||
position.xyz += attr.POSITION_BS6 * renderer_BlendShapeWeights[6]; | ||
position.xyz += attr.POSITION_BS7 * renderer_BlendShapeWeights[7]; | ||
#endif | ||
#endif | ||
#endif | ||
} | ||
|
||
#endif | ||
|
||
|
||
#endif | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thorough Analysis of BlendShape.glsl The file effectively handles various configurations for blend shapes, allowing for a flexible shader setup that can adapt based on the renderer's capabilities. The use of conditional compilation is appropriate and well-implemented. However, consider adding comments explaining the blend shape calculations and their expected effects, especially for complex conditional paths, to enhance maintainability and readability. Would you like me to help document these complex sections for better clarity? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#ifndef FOG_INCLUDED | ||
#define FOG_INCLUDED | ||
|
||
#if SCENE_FOG_MODE != 0 | ||
vec4 scene_FogColor; | ||
vec4 scene_FogParams; // (-1/(end-start), end/(end-start), density/ln(2),density/sprt(ln(2))); | ||
|
||
vec4 fog(vec4 color, vec3 positionVS){ | ||
float fogDepth = length(positionVS); | ||
|
||
#if SCENE_FOG_MODE == 1 | ||
// (end-z) / (end-start) = z * (-1/(end-start)) + (end/(end-start)) | ||
float fogIntensity = clamp(fogDepth * scene_FogParams.x + scene_FogParams.y, 0.0, 1.0); | ||
#elif SCENE_FOG_MODE == 2 | ||
// exp(-z * density) = exp2((-z * density)/ln(2)) = exp2(-z * density/ln(2)) | ||
float fogIntensity = clamp(exp2(-fogDepth * scene_FogParams.z), 0.0, 1.0); | ||
#elif SCENE_FOG_MODE == 3 | ||
// exp(-(z * density)^2) = exp2(-(z * density)^2/ln(2)) = exp2(-(z * density/sprt(ln(2)))^2) | ||
float factor = fogDepth * scene_FogParams.w; | ||
float fogIntensity = clamp(exp2(-factor * factor), 0.0, 1.0); | ||
#endif | ||
|
||
color.rgb = mix(scene_FogColor.rgb, color.rgb, fogIntensity); | ||
|
||
return color; | ||
} | ||
#endif | ||
|
||
|
||
#endif |
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Attributes attribute