# HG changeset patch # User John Tsiombikas # Date 1346114096 -10800 # Node ID 85734f319626e31e4e0c2c88fa4b2fedbc0f0566 # Parent 0357994effe2fa47090efbd6dff10d1dbdf7e574 passing shininess and specular in mrt diff -r 0357994effe2 -r 85734f319626 prototype/data/deftile.mtl --- a/prototype/data/deftile.mtl Tue Aug 28 03:18:47 2012 +0300 +++ b/prototype/data/deftile.mtl Tue Aug 28 03:34:56 2012 +0300 @@ -3,7 +3,7 @@ newmtl Material-light Ns 96.078431 Ka 0.000000 0.000000 0.000000 -Kd 1.000000 0.599313 0.348773 +Kd 1.000000 0.732136 0.437466 Ks 0.000000 0.000000 0.000000 Ni 1.000000 d 1.000000 diff -r 0357994effe2 -r 85734f319626 prototype/sdr/deferred_omni.p.glsl --- a/prototype/sdr/deferred_omni.p.glsl Tue Aug 28 03:18:47 2012 +0300 +++ b/prototype/sdr/deferred_omni.p.glsl Tue Aug 28 03:34:56 2012 +0300 @@ -4,28 +4,42 @@ uniform vec3 light_color; uniform float light_radius; -varying vec3 ltpos; +varying vec3 vpos, ltpos; void main() { vec2 tc = gl_FragCoord.xy * tex_scale / fb_size; - vec3 pos = texture2D(mrt0, tc).xyz; + // MRT0 - rgb: position, a: shininess + vec4 texel0 = texture2D(mrt0, tc); + vec3 pos = texel0.xyz; + float shin = texel0.w; + + // MRT1 - rgb: normal vec3 norm = texture2D(mrt1, tc).xyz; + // MRT2 - rgb: diffuse color, a: specular intensity vec4 texel3 = texture2D(mrt2, tc); vec3 dcol = texel3.xyz; - float shin = texel3.w; + vec3 scol = texel3.www; vec3 ldir = ltpos - pos; float light_dist = length(ldir); ldir = normalize(ldir); - float ndotl = dot(norm, ldir); - vec3 color = dcol * ndotl; + // diffuse + float ndotl = max(dot(norm, ldir), 0.0); + vec3 color_diffuse = dcol * ndotl; + + // specular + vec3 vdir = -normalize(vpos); + vec3 halfvec = normalize(vdir + ldir); + float ndoth = max(dot(norm, halfvec), 0.0); + vec3 color_specular = scol * pow(ndoth, shin); float atten = 1.0 - light_dist / light_radius; atten = clamp(atten, 0.0, 1.0); - gl_FragColor = vec4(color * light_color * atten, 1.0); + vec3 color = (color_diffuse + color_specular) * light_color * atten; + gl_FragColor = vec4(color, 1.0); } diff -r 0357994effe2 -r 85734f319626 prototype/sdr/deferred_omni.v.glsl --- a/prototype/sdr/deferred_omni.v.glsl Tue Aug 28 03:18:47 2012 +0300 +++ b/prototype/sdr/deferred_omni.v.glsl Tue Aug 28 03:34:56 2012 +0300 @@ -1,8 +1,9 @@ -varying vec3 ltpos; +varying vec3 vpos, ltpos; void main() { gl_Position = ftransform(); + vpos = (gl_ModelViewMatrix * gl_Vertex).xyz; ltpos = (gl_ModelViewMatrix * vec4(0.0, 0.0, 0.0, 1.0)).xyz; } diff -r 0357994effe2 -r 85734f319626 prototype/sdr/mrt.p.glsl --- a/prototype/sdr/mrt.p.glsl Tue Aug 28 03:18:47 2012 +0300 +++ b/prototype/sdr/mrt.p.glsl Tue Aug 28 03:34:56 2012 +0300 @@ -18,7 +18,7 @@ vec3 spec = gl_FrontMaterial.specular.xyz; float sstr = (spec.x + spec.y + spec.z) / 3.0; - gl_FragData[0] = vec4(pos, 0.0); + gl_FragData[0] = vec4(pos, gl_FrontMaterial.shininess); gl_FragData[1] = vec4(norm, 0.0); gl_FragData[2] = vec4(diffuse, sstr); //gl_FragData[3] = vec4(0.0, 0.0, 0.0, 0.0);