feat: support uniform blocks
This commit is contained in:
@ -1,13 +1,23 @@
|
|||||||
#version 410 core
|
#version 460 core
|
||||||
|
|
||||||
// Input vertex attributes
|
// Input vertex attributes
|
||||||
layout (location = 0) in vec3 position; // Vertex position in local space (model space)
|
layout (location = 0) in vec3 position; // Vertex position in local space (model space)
|
||||||
|
layout (location = 3) in mat4 instanceModel; // Vertex texture uv
|
||||||
|
|
||||||
|
// layout (std140, binding = 1) uniform Matrices
|
||||||
|
// {
|
||||||
|
// mat4 projection;
|
||||||
|
// mat4 view;
|
||||||
|
// };
|
||||||
|
|
||||||
// Uniforms for transformation matrices
|
// Uniforms for transformation matrices
|
||||||
uniform mat4 u_model; // Model matrix: transforms from local space to world space
|
uniform mat4 u_model; // Model matrix: transforms from local space to world space
|
||||||
uniform mat4 u_lightSpace;
|
uniform mat4 u_lightSpace;
|
||||||
|
uniform bool u_isInstanced;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = u_lightSpace * u_model * vec4(position, 1.0);
|
mat4 model = u_isInstanced ? instanceModel : u_model;
|
||||||
|
|
||||||
|
gl_Position = u_lightSpace * model * vec4(position, 1.0);
|
||||||
}
|
}
|
||||||
@ -6,6 +6,12 @@ layout (location = 1) in vec3 normal; // vertex normal
|
|||||||
layout (location = 2) in vec2 texCoord; // Vertex texture uv
|
layout (location = 2) in vec2 texCoord; // Vertex texture uv
|
||||||
layout (location = 3) in mat4 instanceModel; // Vertex texture uv
|
layout (location = 3) in mat4 instanceModel; // Vertex texture uv
|
||||||
|
|
||||||
|
layout (std140, binding = 1) uniform Matrices
|
||||||
|
{
|
||||||
|
mat4 projection;
|
||||||
|
mat4 view;
|
||||||
|
};
|
||||||
|
|
||||||
// Output to fragment shader
|
// Output to fragment shader
|
||||||
out vec3 vertexPos;
|
out vec3 vertexPos;
|
||||||
out vec3 vertexNormal;
|
out vec3 vertexNormal;
|
||||||
@ -14,8 +20,8 @@ out vec4 fragPosLightSpace;
|
|||||||
|
|
||||||
// Uniforms for transformation matrices
|
// Uniforms for transformation matrices
|
||||||
uniform mat4 u_model; // Model matrix: transforms from local space to world space
|
uniform mat4 u_model; // Model matrix: transforms from local space to world space
|
||||||
uniform mat4 u_view; // View matrix: transforms from world space to camera space (view space)
|
// uniform mat4 u_view;
|
||||||
uniform mat4 u_projection; // Projection matrix: transforms from camera space to clip space
|
// uniform mat4 u_projection;
|
||||||
uniform bool u_isInstanced;
|
uniform bool u_isInstanced;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
@ -32,5 +38,5 @@ void main()
|
|||||||
|
|
||||||
// fragPosLightSpace = u_lightSpace * vec4(vertexPos, 1.0);
|
// fragPosLightSpace = u_lightSpace * vec4(vertexPos, 1.0);
|
||||||
|
|
||||||
gl_Position = u_projection * u_view * vec4(vertexPos, 1.0);
|
gl_Position = projection * view * vec4(vertexPos, 1.0);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user