Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /////////////////////////////////////////////////////
- ////////////////////VERTEX SHADER////////////////////
- /////////////////////////////////////////////////////
- #version 330
- layout(location = 0) in vec3 inPosition;
- layout(location = 1) in vec3 inNormal;
- layout(location = 2) in vec2 inTexCoord;
- out vec3 Gouraud;
- out vec2 texCoord;
- uniform mat4 viewMatrix;
- uniform mat4 modelMatrix;
- uniform mat4 projectionMatrix;
- uniform mat3 normalMatrix;
- uniform vec3 camPosIn;
- uniform vec3 lightPosIn;
- uniform vec3 lightColour;
- void main()
- {
- vec3 position = vec3(0.0);
- vec3 normals = vec3(0.0);
- vec3 diffuse = vec3(0.0);
- vec3 specular = vec3(0.0);
- vec3 ambientColour = vec3(0.0);
- position = vec3((viewMatrix * modelMatrix) * vec4(inPosition, 1.0));
- normals = normalize(normalMatrix * inNormal);
- texCoord = inTexCoord;
- vec3 camDir = normalize(camPosIn - position);
- for (int i = 0; i < 1; i++)
- {
- float radius = 50.0;
- vec3 lightDir = normalize(lightPosIn - position);
- vec3 halfAngle = normalize(camDir + lightDir);
- float NdotL = clamp(dot(normals, lightDir), 0.0, 1.0);
- float NdotH = clamp(dot(normals, halfAngle), 0.0, 1.0);
- float specularHighlight = pow(NdotH, 250);
- vec3 S = (lightColour * specularHighlight);
- vec3 D = (lightColour * NdotL);
- float dist = length(lightPosIn - position);
- float attenuation = 1.0 / (1.0 + ((2.0 / radius) * dist) + ((1.0 / (radius * radius)) * (dist * dist)));
- diffuse += D * attenuation;
- specular += S * attenuation;
- ambientColour += lightColour * attenuation;
- }
- vec3 ambience = 0.01 * ambientColour;
- Gouraud = ambience + diffuse + specular;
- gl_Position = (projectionMatrix * (viewMatrix * modelMatrix)) * vec4(inPosition, 1.0);
- }
- ///////////////////////////////////////////////////////
- ////////////////////FRAGMENT SHADER////////////////////
- ///////////////////////////////////////////////////////
- #version 330
- precision mediump float;
- in vec3 Gouraud;
- in vec2 texCoord;
- layout (location = 0) out vec4 FragColour;
- uniform sampler2D textureMap;
- void main()
- {
- vec3 albedo = texture(textureMap, texCoord).rgb;
- vec3 final = albedo * Gouraud;
- final = pow(final, vec3(1.0 / 2.2));
- FragColour = vec4(final, 1.0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement