dungeon_crawler

changeset 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 d0e93b4d9ec9
files prototype/data/deftile.mtl prototype/sdr/deferred_omni.p.glsl prototype/sdr/deferred_omni.v.glsl prototype/sdr/mrt.p.glsl
diffstat 4 files changed, 24 insertions(+), 9 deletions(-) [+]
line diff
     1.1 --- a/prototype/data/deftile.mtl	Tue Aug 28 03:18:47 2012 +0300
     1.2 +++ b/prototype/data/deftile.mtl	Tue Aug 28 03:34:56 2012 +0300
     1.3 @@ -3,7 +3,7 @@
     1.4  newmtl Material-light
     1.5  Ns 96.078431
     1.6  Ka 0.000000 0.000000 0.000000
     1.7 -Kd 1.000000 0.599313 0.348773
     1.8 +Kd 1.000000 0.732136 0.437466
     1.9  Ks 0.000000 0.000000 0.000000
    1.10  Ni 1.000000
    1.11  d 1.000000
     2.1 --- a/prototype/sdr/deferred_omni.p.glsl	Tue Aug 28 03:18:47 2012 +0300
     2.2 +++ b/prototype/sdr/deferred_omni.p.glsl	Tue Aug 28 03:34:56 2012 +0300
     2.3 @@ -4,28 +4,42 @@
     2.4  uniform vec3 light_color;
     2.5  uniform float light_radius;
     2.6  
     2.7 -varying vec3 ltpos;
     2.8 +varying vec3 vpos, ltpos;
     2.9  
    2.10  void main()
    2.11  {
    2.12  	vec2 tc = gl_FragCoord.xy * tex_scale / fb_size;
    2.13  
    2.14 -	vec3 pos = texture2D(mrt0, tc).xyz;
    2.15 +	// MRT0 - rgb: position, a: shininess
    2.16 +	vec4 texel0 = texture2D(mrt0, tc);
    2.17 +	vec3 pos = texel0.xyz;
    2.18 +	float shin = texel0.w;
    2.19 +
    2.20 +	// MRT1 - rgb: normal
    2.21  	vec3 norm = texture2D(mrt1, tc).xyz;
    2.22  
    2.23 +	// MRT2 - rgb: diffuse color, a: specular intensity
    2.24  	vec4 texel3 = texture2D(mrt2, tc);
    2.25  	vec3 dcol = texel3.xyz;
    2.26 -	float shin = texel3.w;
    2.27 +	vec3 scol = texel3.www;
    2.28  
    2.29  	vec3 ldir = ltpos - pos;
    2.30  	float light_dist = length(ldir);
    2.31  	ldir = normalize(ldir);
    2.32  
    2.33 -	float ndotl = dot(norm, ldir);
    2.34 -	vec3 color = dcol * ndotl;
    2.35 +	// diffuse
    2.36 +	float ndotl = max(dot(norm, ldir), 0.0);
    2.37 +	vec3 color_diffuse = dcol * ndotl;
    2.38 +
    2.39 +	// specular
    2.40 +	vec3 vdir = -normalize(vpos);
    2.41 +	vec3 halfvec = normalize(vdir + ldir);
    2.42 +	float ndoth = max(dot(norm, halfvec), 0.0);
    2.43 +	vec3 color_specular = scol * pow(ndoth, shin);
    2.44  
    2.45  	float atten = 1.0 - light_dist / light_radius;
    2.46  	atten = clamp(atten, 0.0, 1.0);
    2.47  
    2.48 -	gl_FragColor = vec4(color * light_color * atten, 1.0);
    2.49 +	vec3 color = (color_diffuse + color_specular) * light_color * atten;
    2.50 +	gl_FragColor = vec4(color, 1.0);
    2.51  }
     3.1 --- a/prototype/sdr/deferred_omni.v.glsl	Tue Aug 28 03:18:47 2012 +0300
     3.2 +++ b/prototype/sdr/deferred_omni.v.glsl	Tue Aug 28 03:34:56 2012 +0300
     3.3 @@ -1,8 +1,9 @@
     3.4 -varying vec3 ltpos;
     3.5 +varying vec3 vpos, ltpos;
     3.6  
     3.7  void main()
     3.8  {
     3.9  	gl_Position = ftransform();
    3.10  
    3.11 +	vpos = (gl_ModelViewMatrix * gl_Vertex).xyz;
    3.12  	ltpos = (gl_ModelViewMatrix * vec4(0.0, 0.0, 0.0, 1.0)).xyz;
    3.13  }
     4.1 --- a/prototype/sdr/mrt.p.glsl	Tue Aug 28 03:18:47 2012 +0300
     4.2 +++ b/prototype/sdr/mrt.p.glsl	Tue Aug 28 03:34:56 2012 +0300
     4.3 @@ -18,7 +18,7 @@
     4.4  	vec3 spec = gl_FrontMaterial.specular.xyz;
     4.5  	float sstr = (spec.x + spec.y + spec.z) / 3.0;
     4.6  
     4.7 -	gl_FragData[0] = vec4(pos, 0.0);
     4.8 +	gl_FragData[0] = vec4(pos, gl_FrontMaterial.shininess);
     4.9  	gl_FragData[1] = vec4(norm, 0.0);
    4.10  	gl_FragData[2] = vec4(diffuse, sstr);
    4.11  	//gl_FragData[3] = vec4(0.0, 0.0, 0.0, 0.0);