#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; // 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); } #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; // Uniforms uniform int u_objectID; void main() { // Directional light vec3 lightDir = normalize(vec3(1.0, 7.0, 3.0)); // Base light intensity float light = clamp(dot(normalWS, lightDir) * 0.8 + 0.2, 0.0, 1.0); // Gradient from purple (dark) to cyan (lit) vec3 gradientColor = mix( vec3(0.1137, 0.0471, 0.0112), vec3(0.7255, 0.9725, 0.5), light ); // Rim/fresnel effect float rim = 0.5 - dot(normalWS, normalize(lightDir)) * 0.5; float rimValue = rim * rim * rim * rim * clamp(dot(lightDir, normalWS), 0, 1); vec3 rimColor = vec3(1.0, 0.8, 0.5) * rimValue; vec3 mixedColor = mix( gradientColor, vec3(1, 1, 1) , rimValue ); //float fresnel = dot(, vec3(0, 0, -1)); //fresnel = fresnel * fresnel; float fresnel = 1 + dot(normalize(positionVS), normalize(normalVS)); fresnel = fresnel * fresnel * fresnel * fresnel * clamp(dot(lightDir, normalWS), 0, 1); // Combine everything fragColor = vec4(gradientColor + vec3(fresnel, fresnel, fresnel), 1.0); // Object ID output objectID = u_objectID; }