dungeon_crawler

changeset 30:938a6a155c94

foo
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 27 Aug 2012 04:03:22 +0300
parents 2fc004802739
children ddb68dc4ba07
files prototype/configure prototype/sdr/deferred_omni.p.glsl prototype/sdr/deferred_omni.v.glsl prototype/src/main.cc prototype/src/renderer.cc
diffstat 5 files changed, 43 insertions(+), 16 deletions(-) [+]
line diff
     1.1 --- a/prototype/configure	Sun Aug 26 03:39:32 2012 +0300
     1.2 +++ b/prototype/configure	Mon Aug 27 04:03:22 2012 +0300
     1.3 @@ -34,14 +34,14 @@
     1.4  
     1.5  verstr=`$CXX --version`
     1.6  if echo "$verstr" | grep LLVM; then
     1.7 -	if echo | $CXX -c -x c++ -std=c++11 - >/dev/null 2>&1; then
     1.8 +	if echo | $CXX -c -x c++ -o /dev/null -std=c++11 - >/dev/null 2>&1; then
     1.9  		cxxflags11='-std=c++11 -stdlib=libc++'
    1.10  		ldflags11='-stdlib=libc++'
    1.11  	fi
    1.12  else
    1.13 -	if echo | $CXX -c -x c++ -std=c++11 - >/dev/null 2>&1; then
    1.14 +	if echo | $CXX -c -x c++ -o /dev/null -std=c++11 - >/dev/null 2>&1; then
    1.15  		cxxflags11='-std=c++11'
    1.16 -	elif echo | $CXX -c -x c++ -std=c++0x - >/dev/null 2>&1; then
    1.17 +	elif echo | $CXX -c -x c++ -o /dev/null -std=c++0x - >/dev/null 2>&1; then
    1.18  		cxxflags11='-std=c++0x'
    1.19  	fi
    1.20  fi
     2.1 --- a/prototype/sdr/deferred_omni.p.glsl	Sun Aug 26 03:39:32 2012 +0300
     2.2 +++ b/prototype/sdr/deferred_omni.p.glsl	Mon Aug 27 04:03:22 2012 +0300
     2.3 @@ -1,20 +1,30 @@
     2.4  uniform sampler2D mrt0, mrt1, mrt2, mrt3;
     2.5 -uniform vec2 tex_scale;
     2.6 +uniform vec2 tex_scale, fb_size;
     2.7 +
     2.8 +varying vec3 ltpos;
     2.9  
    2.10  void main()
    2.11  {
    2.12 -	vec2 tc = gl_TexCoord[0].st;
    2.13 +	vec2 tc = gl_FragCoord.xy * tex_scale / fb_size;
    2.14  
    2.15 -	vec4 texel;
    2.16 -	if(tc.x < 0.25) {
    2.17 -		texel = texture2D(mrt0, tc * vec2(4.0, 1.0) * tex_scale);
    2.18 -	} else if(tc.x < 0.5) {
    2.19 -		texel = texture2D(mrt1, (tc - vec2(0.25, 0.0)) * vec2(4.0, 1.0) * tex_scale);
    2.20 -	} else if(tc.x < 0.75) {
    2.21 -		texel = texture2D(mrt2, (tc - vec2(0.5, 0.0)) * vec2(4.0, 1.0) * tex_scale);
    2.22 -	} else {
    2.23 -		texel = texture2D(mrt3, (tc - vec2(0.75, 0.0)) * vec2(4.0, 1.0) * tex_scale);
    2.24 +	vec3 pos = texture2D(mrt0, tc).xyz;
    2.25 +	vec3 norm = texture2D(mrt1, tc).xyz;
    2.26 +
    2.27 +	vec4 texel3 = texture2D(mrt2, tc);
    2.28 +	vec3 dcol = texel3.xyz;
    2.29 +	float shin = texel3.w;
    2.30 +
    2.31 +	vec3 ldir = ltpos - pos;
    2.32 +	float dist = length(ldir);
    2.33 +	ldir = normalize(ldir);
    2.34 +
    2.35 +	float ndotl = dot(norm, ldir);
    2.36 +	vec3 color = dcol * ndotl;
    2.37 +
    2.38 +	float atten = 1.0;
    2.39 +	if(dist > 0.2) {
    2.40 +		atten = 0.0;
    2.41  	}
    2.42  
    2.43 -	gl_FragColor = texel;
    2.44 +	gl_FragColor = vec4(color, 1.0);
    2.45  }
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/prototype/sdr/deferred_omni.v.glsl	Mon Aug 27 04:03:22 2012 +0300
     3.3 @@ -0,0 +1,8 @@
     3.4 +varying vec3 ltpos;
     3.5 +
     3.6 +void main()
     3.7 +{
     3.8 +	gl_Position = ftransform();
     3.9 +
    3.10 +	ltpos = (gl_ModelViewMatrix * vec4(0.0, 0.0, 0.0, 1.0)).xyz;
    3.11 +}
     4.1 --- a/prototype/src/main.cc	Sun Aug 26 03:39:32 2012 +0300
     4.2 +++ b/prototype/src/main.cc	Mon Aug 27 04:03:22 2012 +0300
     4.3 @@ -235,6 +235,8 @@
     4.4  	glViewport(0, 0, x, y);
     4.5  	cfg.width = x;
     4.6  	cfg.height = y;
     4.7 +
     4.8 +	resize_renderer(x, y);
     4.9  }
    4.10  
    4.11  static bool stereo_shift_pressed;
     5.1 --- a/prototype/src/renderer.cc	Sun Aug 26 03:39:32 2012 +0300
     5.2 +++ b/prototype/src/renderer.cc	Mon Aug 27 04:03:22 2012 +0300
     5.3 @@ -73,7 +73,7 @@
     5.4  		set_uniform_int(deferred_debug, uname, i);
     5.5  	}
     5.6  
     5.7 -	if(!(deferred_omni = load_sdr("deferred.v.glsl", "deferred_omni.p.glsl"))) {
     5.8 +	if(!(deferred_omni = load_sdr("deferred_omni.v.glsl", "deferred_omni.p.glsl"))) {
     5.9  		return false;
    5.10  	}
    5.11  	for(int i=0; i<MRT_COUNT; i++) {
    5.12 @@ -119,6 +119,8 @@
    5.13  	float tex_scale_y = (float)fb_ysz / tex_ysz;
    5.14  
    5.15  	set_uniform_float2(deferred_omni, "tex_scale", tex_scale_x, tex_scale_y);
    5.16 +	set_uniform_float2(deferred_omni, "fb_size", fb_xsz, fb_ysz);
    5.17 +
    5.18  	set_uniform_float2(deferred_debug, "tex_scale", tex_scale_x, tex_scale_y);
    5.19  }
    5.20  
    5.21 @@ -137,7 +139,12 @@
    5.22  	// post-process lighting
    5.23  	glPushAttrib(GL_ENABLE_BIT);
    5.24  
    5.25 +	glEnable(GL_BLEND);
    5.26 +	glBlendFunc(GL_ONE, GL_ONE);
    5.27 +
    5.28  	glDisable(GL_LIGHTING);
    5.29 +	glDisable(GL_CULL_FACE);
    5.30 +	glDisable(GL_DEPTH_TEST);
    5.31  
    5.32  	glUseProgram(deferred_omni);
    5.33  	for(int i=0; i<MRT_COUNT; i++) {