DeerEngine/Resources/shader_uv.glsl
2026-03-01 17:48:56 +01:00

77 lines
1.7 KiB
GLSL

#type vertex
#version 410 core
// Vertex attributes
layout(location = 0) in vec3 v_position;
layout(location = 1) in vec3 v_normal;
layout(location = 2) in vec2 v_UV;
// Outputs to fragment shader
out vec3 normalWS;
out vec3 normalVS;
out vec3 positionVS;
out vec2 uv;
// Uniforms
uniform mat4 u_worldMatrix;
uniform mat4 u_viewMatrix;
void main()
{
gl_Position = u_viewMatrix * u_worldMatrix * vec4(v_position, 1.0);
positionVS = gl_Position.xyz;
mat3 normalMatrix = transpose(inverse(mat3(u_worldMatrix)));
normalWS = normalize(normalMatrix * v_normal);
mat3 normalMatrixView = transpose(inverse(mat3(u_viewMatrix * u_worldMatrix)));
normalVS = normalize(normalMatrixView * v_normal);
uv = v_UV;
}
#type fragment
#version 410 core
// Fragment outputs
layout(location = 0) out vec4 fragColor;
layout(location = 1) out int objectID;
// Inputs from vertex shader
in vec3 normalWS;
in vec3 normalVS;
in vec3 positionVS;
in vec2 uv;
// Uniforms
uniform int u_objectID;
uniform sampler2D u_texture;
void main()
{
// Directional light
vec3 lightDir = normalize(vec3(1.0, 7.0, 3.0));
// Base light intensity
float light = clamp(dot(normalWS, lightDir) * 5, 0.0, 1.0);
vec3 tex = texture(u_texture, uv).rgb;
// Gradient from purple (dark) to cyan (lit)
vec3 gradientColor = mix(
vec3(0.3137, 0.2471, 0.5412) * tex,
vec3(1.0, 1.0, 1.0) * tex,
light
);
//float fresnel = dot(, vec3(0, 0, -1));
//fresnel = fresnel * fresnel;
float fresnel = 1 + dot(normalize(positionVS), normalize(normalVS));
fresnel = fresnel * fresnel * light;
// Combine everything
fragColor = vec4(tex, 1.0);
// Object ID output
objectID = u_objectID;
}