diff options
| author | raysan5 <[email protected]> | 2021-03-31 20:44:16 +0200 |
|---|---|---|
| committer | raysan5 <[email protected]> | 2021-03-31 20:44:16 +0200 |
| commit | cdc3754449da5cf8c83843f395dd97e71a7eba30 (patch) | |
| tree | 2b850fbf711c08985840db841b778ab9584f2e2b /examples/shaders/resources | |
| parent | 2488d361b6c9e65ba8e4ebc29bbc58a9bc3365ea (diff) | |
| download | raylib-cdc3754449da5cf8c83843f395dd97e71a7eba30.tar.gz raylib-cdc3754449da5cf8c83843f395dd97e71a7eba30.zip | |
ADDED: Support model normal matrix location #1691
Diffstat (limited to 'examples/shaders/resources')
| -rw-r--r-- | examples/shaders/resources/shaders/glsl330/base_lighting.vs | 5 | ||||
| -rw-r--r-- | examples/shaders/resources/shaders/glsl330/base_lighting_instanced.vs | 12 |
2 files changed, 8 insertions, 9 deletions
diff --git a/examples/shaders/resources/shaders/glsl330/base_lighting.vs b/examples/shaders/resources/shaders/glsl330/base_lighting.vs index f1b75d79..f8ec45f1 100644 --- a/examples/shaders/resources/shaders/glsl330/base_lighting.vs +++ b/examples/shaders/resources/shaders/glsl330/base_lighting.vs @@ -9,6 +9,7 @@ in vec4 vertexColor; // Input uniform values uniform mat4 mvp; uniform mat4 matModel; +uniform mat4 matNormal; // Output vertex attributes (to fragment shader) out vec3 fragPosition; @@ -24,9 +25,7 @@ void main() fragPosition = vec3(matModel*vec4(vertexPosition, 1.0)); fragTexCoord = vertexTexCoord; fragColor = vertexColor; - - mat3 normalMatrix = transpose(inverse(mat3(matModel))); - fragNormal = normalize(normalMatrix*vertexNormal); + fragNormal = normalize(vec3(matNormal*vec4(vertexNormal, 1.0))); // Calculate final vertex position gl_Position = mvp*vec4(vertexPosition, 1.0); diff --git a/examples/shaders/resources/shaders/glsl330/base_lighting_instanced.vs b/examples/shaders/resources/shaders/glsl330/base_lighting_instanced.vs index 7b709094..d198efe1 100644 --- a/examples/shaders/resources/shaders/glsl330/base_lighting_instanced.vs +++ b/examples/shaders/resources/shaders/glsl330/base_lighting_instanced.vs @@ -10,6 +10,7 @@ in mat4 instanceTransform; // Input uniform values uniform mat4 mvp; +uniform mat4 matNormal; // Output vertex attributes (to fragment shader) out vec3 fragPosition; @@ -21,15 +22,14 @@ out vec3 fragNormal; void main() { + // Compute MVP for current instance + mat4 mvpi = mvp*instanceTransform; + // Send vertex attributes to fragment shader - fragPosition = vec3(vec4(vertexPosition, 1.0)); + fragPosition = vec3(mvpi*vec4(vertexPosition, 1.0)); fragTexCoord = vertexTexCoord; fragColor = vertexColor; - - mat3 normalMatrix = transpose(inverse(mat3(instanceTransform))); - fragNormal = normalize(normalMatrix*vertexNormal); - - mat4 mvpi = mvp*instanceTransform; + fragNormal = normalize(vec3(matNormal*vec4(vertexNormal, 1.0))); // Calculate final vertex position gl_Position = mvpi*vec4(vertexPosition, 1.0); |
