dungeon_crawler

diff prototype/sdr/deferred_omni.p.glsl @ 34:85734f319626

passing shininess and specular in mrt
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 28 Aug 2012 03:34:56 +0300
parents 0357994effe2
children 4472ef41a209
line diff
     1.1 --- a/prototype/sdr/deferred_omni.p.glsl	Tue Aug 28 03:18:47 2012 +0300
     1.2 +++ b/prototype/sdr/deferred_omni.p.glsl	Tue Aug 28 03:34:56 2012 +0300
     1.3 @@ -4,28 +4,42 @@
     1.4  uniform vec3 light_color;
     1.5  uniform float light_radius;
     1.6  
     1.7 -varying vec3 ltpos;
     1.8 +varying vec3 vpos, ltpos;
     1.9  
    1.10  void main()
    1.11  {
    1.12  	vec2 tc = gl_FragCoord.xy * tex_scale / fb_size;
    1.13  
    1.14 -	vec3 pos = texture2D(mrt0, tc).xyz;
    1.15 +	// MRT0 - rgb: position, a: shininess
    1.16 +	vec4 texel0 = texture2D(mrt0, tc);
    1.17 +	vec3 pos = texel0.xyz;
    1.18 +	float shin = texel0.w;
    1.19 +
    1.20 +	// MRT1 - rgb: normal
    1.21  	vec3 norm = texture2D(mrt1, tc).xyz;
    1.22  
    1.23 +	// MRT2 - rgb: diffuse color, a: specular intensity
    1.24  	vec4 texel3 = texture2D(mrt2, tc);
    1.25  	vec3 dcol = texel3.xyz;
    1.26 -	float shin = texel3.w;
    1.27 +	vec3 scol = texel3.www;
    1.28  
    1.29  	vec3 ldir = ltpos - pos;
    1.30  	float light_dist = length(ldir);
    1.31  	ldir = normalize(ldir);
    1.32  
    1.33 -	float ndotl = dot(norm, ldir);
    1.34 -	vec3 color = dcol * ndotl;
    1.35 +	// diffuse
    1.36 +	float ndotl = max(dot(norm, ldir), 0.0);
    1.37 +	vec3 color_diffuse = dcol * ndotl;
    1.38 +
    1.39 +	// specular
    1.40 +	vec3 vdir = -normalize(vpos);
    1.41 +	vec3 halfvec = normalize(vdir + ldir);
    1.42 +	float ndoth = max(dot(norm, halfvec), 0.0);
    1.43 +	vec3 color_specular = scol * pow(ndoth, shin);
    1.44  
    1.45  	float atten = 1.0 - light_dist / light_radius;
    1.46  	atten = clamp(atten, 0.0, 1.0);
    1.47  
    1.48 -	gl_FragColor = vec4(color * light_color * atten, 1.0);
    1.49 +	vec3 color = (color_diffuse + color_specular) * light_color * atten;
    1.50 +	gl_FragColor = vec4(color, 1.0);
    1.51  }