SHADE_Y3/Assets/Shaders/TestCube_VS.glsl

63 lines
1.4 KiB
Plaintext
Raw Normal View History

2022-09-19 00:00:07 +08:00
#version 450
#extension GL_KHR_vulkan_glsl : enable
//#include "ShaderDescriptorDefinitions.glsl"
2022-09-19 00:00:07 +08:00
layout(location = 0) in vec3 aVertexPos;
layout(location = 1) in vec2 aUV;
layout(location = 2) in vec3 aNormal;
layout(location = 3) in vec3 aTangent;
layout(location = 4) in mat4 worldTransform;
layout(location = 8) in uvec2 integerData;
2022-09-19 00:00:07 +08:00
layout(location = 0) out struct
{
vec4 vertPos; // location 0
vec2 uv; // location = 1
vec4 normal; // location = 2
2022-09-19 00:00:07 +08:00
} Out;
// material stuff
layout(location = 3) out struct
{
int materialIndex;
uint eid;
uint lightLayerIndex;
} Out2;
layout(set = 2, binding = 0) uniform CameraData
{
vec4 position;
mat4 vpMat;
mat4 viewMat;
2022-10-31 20:49:28 +08:00
mat4 projMat;
} cameraData;
2022-09-19 00:00:07 +08:00
void main()
{
Out2.materialIndex = gl_InstanceIndex;
Out2.eid = integerData[0];
Out2.lightLayerIndex = integerData[1];
2022-10-30 16:52:40 +08:00
// for transforming gBuffer position and normal data
mat4 modelViewMat = cameraData.viewMat * worldTransform;
// gBuffer position will be in view space
Out.vertPos = modelViewMat * vec4(aVertexPos, 1.0f);
// uvs for texturing in fragment shader
Out.uv = aUV;
2022-10-30 16:52:40 +08:00
2022-10-31 20:49:28 +08:00
mat3 transposeInv = mat3 (transpose(inverse(modelViewMat)));
2022-10-30 16:52:40 +08:00
// normals are also in view space
2022-10-31 20:49:28 +08:00
Out.normal.rgb = transposeInv * aNormal.rgb;
Out.normal.rgb = normalize (Out.normal.rgb);
2022-10-30 16:52:40 +08:00
// clip space for rendering
gl_Position = cameraData.vpMat * worldTransform * vec4 (aVertexPos, 1.0f);
2022-09-19 00:00:07 +08:00
}