diff options
| author | raysan5 <[email protected]> | 2021-03-31 19:59:23 +0200 |
|---|---|---|
| committer | raysan5 <[email protected]> | 2021-03-31 19:59:23 +0200 |
| commit | c772de702b844d99adf38342d929ee48dd22d21d (patch) | |
| tree | d8785b45e8bbc9dce2d5f37ae690653991c70294 /examples | |
| parent | 434a3a276df2f0a3dfe48b522a9e20abe8562fef (diff) | |
| download | raylib-c772de702b844d99adf38342d929ee48dd22d21d.tar.gz raylib-c772de702b844d99adf38342d929ee48dd22d21d.zip | |
REVIEWED: DrawMeshInstanced() matrix computations
Simplified some parts and reviewed for a correct computation of matrices, considering stereo render view/projection per eye transformations
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/shaders/resources/shaders/glsl330/base_lighting_instanced.vs | 12 | ||||
| -rw-r--r-- | examples/shaders/shaders_mesh_instancing.c | 3 |
2 files changed, 8 insertions, 7 deletions
diff --git a/examples/shaders/resources/shaders/glsl330/base_lighting_instanced.vs b/examples/shaders/resources/shaders/glsl330/base_lighting_instanced.vs index 5e5430b3..7b709094 100644 --- a/examples/shaders/resources/shaders/glsl330/base_lighting_instanced.vs +++ b/examples/shaders/resources/shaders/glsl330/base_lighting_instanced.vs @@ -6,7 +6,7 @@ in vec2 vertexTexCoord; in vec3 vertexNormal; in vec4 vertexColor; -layout (location = 12) in mat4 instance; +in mat4 instanceTransform; // Input uniform values uniform mat4 mvp; @@ -22,15 +22,15 @@ out vec3 fragNormal; void main() { // Send vertex attributes to fragment shader - fragPosition = vec3(instance * vec4(vertexPosition, 1.0)); + fragPosition = vec3(vec4(vertexPosition, 1.0)); fragTexCoord = vertexTexCoord; fragColor = vertexColor; - mat3 normalMatrix = transpose(inverse(mat3(instance))); - fragNormal = normalize(normalMatrix * vertexNormal); + mat3 normalMatrix = transpose(inverse(mat3(instanceTransform))); + fragNormal = normalize(normalMatrix*vertexNormal); - mat4 mvpi = mvp * instance; + mat4 mvpi = mvp*instanceTransform; // Calculate final vertex position - gl_Position = mvpi * vec4(vertexPosition, 1.0); + gl_Position = mvpi*vec4(vertexPosition, 1.0); } diff --git a/examples/shaders/shaders_mesh_instancing.c b/examples/shaders/shaders_mesh_instancing.c index 95548234..520a2d65 100644 --- a/examples/shaders/shaders_mesh_instancing.c +++ b/examples/shaders/shaders_mesh_instancing.c @@ -89,7 +89,7 @@ int main(void) // Get some shader loactions shader.locs[SHADER_LOC_MATRIX_MVP] = GetShaderLocation(shader, "mvp"); shader.locs[SHADER_LOC_VECTOR_VIEW] = GetShaderLocation(shader, "viewPos"); - shader.locs[SHADER_LOC_MATRIX_MODEL] = GetShaderLocationAttrib(shader, "instance"); + shader.locs[SHADER_LOC_MATRIX_MODEL] = GetShaderLocationAttrib(shader, "instanceTransform"); // Ambient light level int ambientLoc = GetShaderLocation(shader, "ambient"); @@ -173,6 +173,7 @@ int main(void) ClearBackground(RAYWHITE); BeginMode3D(camera); + //DrawMesh(cube, material, MatrixIdentity()); DrawMeshInstanced(cube, material, transforms, instances); EndMode3D(); |
