dungeon_crawler

view prototype/sdr/deferred_omni.p.glsl @ 61:4472ef41a209

forgot an extra mrt uniform in deferred_omni.p.glsl
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 25 Sep 2012 06:37:56 +0300
parents 85734f319626
children
line source
1 uniform sampler2D mrt0, mrt1, mrt2;
2 uniform vec2 tex_scale, fb_size;
4 uniform vec3 light_color;
5 uniform float light_radius;
7 varying vec3 vpos, ltpos;
9 void main()
10 {
11 vec2 tc = gl_FragCoord.xy * tex_scale / fb_size;
13 // MRT0 - rgb: position, a: shininess
14 vec4 texel0 = texture2D(mrt0, tc);
15 vec3 pos = texel0.xyz;
16 float shin = texel0.w;
18 // MRT1 - rgb: normal
19 vec3 norm = texture2D(mrt1, tc).xyz;
21 // MRT2 - rgb: diffuse color, a: specular intensity
22 vec4 texel3 = texture2D(mrt2, tc);
23 vec3 dcol = texel3.xyz;
24 vec3 scol = texel3.www;
26 vec3 ldir = ltpos - pos;
27 float light_dist = length(ldir);
28 ldir = normalize(ldir);
30 // diffuse
31 float ndotl = max(dot(norm, ldir), 0.0);
32 vec3 color_diffuse = dcol * ndotl;
34 // specular
35 vec3 vdir = -normalize(vpos);
36 vec3 halfvec = normalize(vdir + ldir);
37 float ndoth = max(dot(norm, halfvec), 0.0);
38 vec3 color_specular = scol * pow(ndoth, shin);
40 float atten = 1.0 - light_dist / light_radius;
41 atten = clamp(atten, 0.0, 1.0);
43 vec3 color = (color_diffuse + color_specular) * light_color * atten;
44 gl_FragColor = vec4(color, 1.0);
45 }