Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Vertex Shader:
- #version 120
- attribute vec3 aVertexPos;
- attribute vec2 aVertexTex;
- attribute vec3 aVertexNorm;
- uniform mat4 uVMatrix;
- uniform mat4 uTMatrix;
- uniform mat4 uPMatrix;
- uniform vec3 uLightColor[5];
- uniform vec3 uLightPos[5];
- uniform vec3 uLightAtt[5];
- varying vec3 vSurfaceNorm;
- varying vec3 vLightVector[5];
- varying vec3 vLightColor[5];
- varying vec3 vLightAtt[5];
- varying vec2 vVertexTex;
- void main(){
- vec4 lWorldPos = uTMatrix * vec4(aVertexPos, 1.0);
- gl_Position = uPMatrix * uVMatrix * lWorldPos;
- for(int i = 0; i < 5; i++){
- vLightVector[i] = uLightPos[i] - lWorldPos.xyz;
- vLightColor[i] = uLightColor[i];
- vLightAtt[i] = uLightAtt[i];
- }
- vSurfaceNorm = (uTMatrix * vec4(aVertexNorm, 0.0)).xyz;
- vVertexTex = aVertexTex * 128.0;
- }
- //Fragment Shader:
- #version 120
- uniform sampler2D diffuseTexs[4];
- uniform sampler2D blendTex;
- varying vec3 vSurfaceNorm;
- varying vec3 vLightVector[5];
- varying vec3 vLightColor[5];
- varying vec3 vLightAtt[5];
- varying vec2 vVertexTex;
- void main(){
- vec4 texelDiffuse0 = texture2D(diffuseTexs[0], vVertexTex);
- vec4 texelDiffuse1 = texture2D(diffuseTexs[1], vVertexTex);
- vec4 texelDiffuse2 = texture2D(diffuseTexs[2], vVertexTex);
- vec4 texelDiffuse3 = texture2D(diffuseTexs[3], vVertexTex);
- vec3 lTotalDiffuse = vec3(0.0);
- for(int i = 0; i < 5; i++){
- float lDist = length(vLightVector[i]);
- float attFactor = 1.0 + (0.01 * lDist) + (0.002 * lDist * lDist);
- vec3 lUnitNormal = normalize(vSurfaceNorm);
- vec3 lUnitLightVector = normalize(vLightVector[i]);
- float lNDotl = dot(lUnitNormal, lUnitLightVector);
- float lBrightness = max(lNDotl, 0.0);
- lTotalDiffuse = lTotalDiffuse + (lBrightness * vLightColor[i]) / attFactor;
- }
- lTotalDiffuse = max(lTotalDiffuse, 0.3);
- gl_FragColor = vec4(lTotalDiffuse, 1.0) * texelDiffuse0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement