Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ------------
- VERTEX PROGRAM:
- ------------
- attribute vec4 a_position;
- attribute vec4 a_color;
- attribute vec2 a_texCoord0;
- uniform mat4 u_proj;
- uniform mat4 u_trans;
- uniform mat4 u_projTrans;
- varying vec4 v_color;
- varying vec2 v_texCoords;
- void main()
- {
- v_color = a_color;
- v_texCoords = a_texCoord0;
- gl_Position = u_projTrans * a_position;
- }
- ------------
- FRAGMENT PROGRAM:
- ------------
- #ifdef GL_ES
- precision mediump float;
- #endif
- varying vec4 v_color;
- varying vec2 v_texCoords;
- uniform sampler2D u_texture;
- uniform sampler2D u_normals;
- uniform vec3 light;
- uniform vec3 ambientColor;
- uniform float ambientIntensity;
- uniform vec2 resolution;
- uniform vec3 lightColor;
- uniform bool useNormals;
- uniform bool useShadow;
- uniform vec3 attenuation;
- void main() {
- vec4 color = texture2D(u_texture, v_texCoords.st);
- vec3 normal = normalize(texture2D(u_normals, v_texCoords.st).rgb * 2.0 - 1.0);
- vec3 light_pos = normalize(light);
- float lambert = useNormals ? max(dot(normal, light_pos), 0.0) : 1.0;
- //now let's get a nice little falloff
- float d = distance(gl_FragCoord.xy, light.xy * resolution);
- d *= light.z;
- float att = useShadow ? 1.0 / ( attenuation.x + (attenuation.y*d) + (attenuation.z*d*d) ) : 1.0;
- vec3 result = (ambientColor * ambientIntensity) + (lightColor.rgb * lambert) * att;
- result *= color.rgb;
- gl_FragColor = v_color * vec4(result, color.a);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement