Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* vertex shader */
- #shader vertex
- #version 330 core
- layout(location = 0) in vec4 position_modelSpace;
- layout(location = 1) in vec2 UV;
- layout(location = 2) in vec3 normal_modelSpace;
- layout(location = 3) in vec3 tangent_modelSpace;
- layout(location = 4) in vec3 bitangent_modelSpace;
- out struct VSout {
- vec4 position_screenSpace;
- vec2 UV;
- mat3 worldToTangent;
- } v;
- uniform mat4 toWorldSpace;
- uniform mat4 toViewSpace;
- uniform mat4 toScreenSpace;
- void main()
- {
- mat4 MVP = toScreenSpace * toViewSpace * toWorldSpace;
- mat3 toWorldSpaceMAT3 = mat3(toWorldSpace);
- vec3 normal_worldSpace = toWorldSpaceMAT3 * normalize(normal_modelSpace);
- vec3 tangent_worldSpace = toWorldSpaceMAT3 * normalize(tangent_modelSpace);
- vec3 bitangent_worldSpace = toWorldSpaceMAT3 * normalize(bitangent_modelSpace);
- v.position_screenSpace = MVP * position_modelSpace;
- v.UV = UV;
- v.worldToTangent = transpose(mat3(
- tangent_worldSpace,
- bitangent_worldSpace,
- normal_worldSpace
- ));
- gl_Position = v.position_screenSpace;
- }
- /* fragment shader */
- #shader fragment
- #version 330 core
- in struct VSout {
- vec4 position_screenSpace;
- vec2 UV;
- mat3 worldToTangent;
- } v;
- out vec4 color;
- uniform mat4 toWorldSpace;
- uniform mat4 toViewSpace;
- uniform mat4 toScreenSpace;
- uniform sampler2D diffuseTexture; //slot 0
- uniform sampler2D normalMap; //slot 1
- vec4 lightDir_worldSpace = -vec4(1.f, 1.f, 1.f, 0.f);
- void main()
- {
- vec4 normalMapRGB = texture(normalMap, v.UV);
- vec3 normal_tangentSpace = normalize(normalMapRGB.xyz * 2.f - 1.f);
- vec3 lightDir_tangentSpace = normalize(lightDir_worldSpace.xyz * v.worldToTangent);
- color = texture(diffuseTexture, v.UV);
- color.rgb = color.rgb * clamp( dot(normal_tangentSpace, lightDir_tangentSpace), 0, 1 );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement