dungeon_crawler

changeset 20:48cfd351a9be

mrt going on nicely
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 21 Aug 2012 04:57:33 +0300
parents 8a0ae6b4aa9b
children 0588f8a1a351
files prototype/sdr/deferred.p.glsl prototype/sdr/mrt.p.glsl prototype/sdr/mrt.v.glsl prototype/src/renderer.cc
diffstat 4 files changed, 46 insertions(+), 19 deletions(-) [+]
line diff
     1.1 --- a/prototype/sdr/deferred.p.glsl	Tue Aug 21 04:29:49 2012 +0300
     1.2 +++ b/prototype/sdr/deferred.p.glsl	Tue Aug 21 04:57:33 2012 +0300
     1.3 @@ -4,17 +4,16 @@
     1.4  void main()
     1.5  {
     1.6  	vec2 tc = gl_TexCoord[0].st;
     1.7 -	//vec4 texel0 = texture2D(mrt0, gl_TexCoord[0].st * s);
     1.8  
     1.9  	vec4 texel;
    1.10  	if(tc.x < 0.25) {
    1.11  		texel = texture2D(mrt0, tc * vec2(4.0, 1.0) * tex_scale);
    1.12  	} else if(tc.x < 0.5) {
    1.13 -		texel = texture2D(mrt0, (tc - vec2(0.25, 0.0)) * vec2(4.0, 1.0) * tex_scale);
    1.14 +		texel = texture2D(mrt1, (tc - vec2(0.25, 0.0)) * vec2(4.0, 1.0) * tex_scale);
    1.15  	} else if(tc.x < 0.75) {
    1.16 -		texel = texture2D(mrt0, (tc - vec2(0.5, 0.0)) * vec2(4.0, 1.0) * tex_scale);
    1.17 +		texel = texture2D(mrt2, (tc - vec2(0.5, 0.0)) * vec2(4.0, 1.0) * tex_scale);
    1.18  	} else {
    1.19 -		texel = texture2D(mrt0, (tc - vec2(0.75, 0.0)) * vec2(4.0, 1.0) * tex_scale);
    1.20 +		texel = texture2D(mrt3, (tc - vec2(0.75, 0.0)) * vec2(4.0, 1.0) * tex_scale);
    1.21  	}
    1.22  
    1.23  	gl_FragColor = texel;
     2.1 --- a/prototype/sdr/mrt.p.glsl	Tue Aug 21 04:29:49 2012 +0300
     2.2 +++ b/prototype/sdr/mrt.p.glsl	Tue Aug 21 04:57:33 2012 +0300
     2.3 @@ -1,10 +1,25 @@
     2.4 -uniform sampler2D tex_dif;
     2.5 +/* MRT assignments
     2.6 + * 0 - RGB: position
     2.7 + * 1 - RGB: normal
     2.8 + * 3 - RGB: diffuse color, A: shininess str.
     2.9 + * 4 - unused
    2.10 + */
    2.11 +
    2.12 +uniform sampler2D tex_dif, tex_norm;
    2.13 +
    2.14 +varying vec3 pos, norm;
    2.15  
    2.16  void main()
    2.17  {
    2.18 +	vec3 n = normalize(norm);
    2.19 +
    2.20  	vec4 texel = texture2D(tex_dif, gl_TexCoord[0].st);
    2.21 -	gl_FragData[0] = texel * vec4(1.0, 0.0, 0.0, 1.0);
    2.22 -	gl_FragData[1] = texel * vec4(0.0, 1.0, 0.0, 1.0);
    2.23 -	gl_FragData[2] = texel * vec4(0.0, 0.0, 1.0, 1.0);
    2.24 -	gl_FragData[3] = texel * vec4(1.0, 0.0, 0.0, 1.0);
    2.25 +	vec3 diffuse = (gl_FrontMaterial.diffuse * texel).xyz;
    2.26 +	vec3 spec = gl_FrontMaterial.specular.xyz;
    2.27 +	float sstr = (spec.x + spec.y + spec.z) / 3.0;
    2.28 +
    2.29 +	gl_FragData[0] = vec4(pos, 0.0);
    2.30 +	gl_FragData[1] = vec4(norm, 0.0);
    2.31 +	gl_FragData[2] = vec4(diffuse, sstr);
    2.32 +	gl_FragData[3] = vec4(0.0, 0.0, 0.0, 0.0);
    2.33  }
     3.1 --- a/prototype/sdr/mrt.v.glsl	Tue Aug 21 04:29:49 2012 +0300
     3.2 +++ b/prototype/sdr/mrt.v.glsl	Tue Aug 21 04:57:33 2012 +0300
     3.3 @@ -1,5 +1,11 @@
     3.4 +varying vec3 pos, norm;
     3.5 +
     3.6  void main()
     3.7  {
     3.8  	gl_Position = ftransform();
     3.9 +
    3.10 +	pos = (gl_ModelViewMatrix * gl_Vertex).xyz;
    3.11 +	norm = gl_NormalMatrix * gl_Normal;
    3.12 +
    3.13  	gl_TexCoord[0] = gl_MultiTexCoord0;
    3.14  }
     4.1 --- a/prototype/src/renderer.cc	Tue Aug 21 04:29:49 2012 +0300
     4.2 +++ b/prototype/src/renderer.cc	Tue Aug 21 04:57:33 2012 +0300
     4.3 @@ -74,19 +74,18 @@
     4.4  {
     4.5  	int loc;
     4.6  
     4.7 -	static GLenum draw_bufs[] = {
     4.8 -		GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT,
     4.9 -		GL_COLOR_ATTACHMENT2_EXT, GL_COLOR_ATTACHMENT3_EXT,
    4.10 -		GL_COLOR_ATTACHMENT4_EXT, GL_COLOR_ATTACHMENT5_EXT,
    4.11 -		GL_COLOR_ATTACHMENT6_EXT, GL_COLOR_ATTACHMENT7_EXT
    4.12 -	};
    4.13 -
    4.14  	// render into the MRT buffers
    4.15  	glBindFramebufferEXT(GL_FRAMEBUFFER, fbo);
    4.16 -	glDrawBuffersARB(MRT_COUNT, draw_bufs);
    4.17  
    4.18  	glUseProgram(mrt_prog);
    4.19 +	if((loc = glGetUniformLocation(mrt_prog, "tex_dif")) != -1) {
    4.20 +		glUniform1i(loc, 0);
    4.21 +	}
    4.22 +	if((loc = glGetUniformLocation(mrt_prog, "tex_norm")) != -1) {
    4.23 +		glUniform1i(loc, 1);
    4.24 +	}
    4.25  	draw_func();
    4.26 +
    4.27  	glUseProgram(0);
    4.28  	glBindFramebufferEXT(GL_FRAMEBUFFER, 0);
    4.29  
    4.30 @@ -160,11 +159,19 @@
    4.31  		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex_xsz, tex_ysz, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
    4.32  
    4.33  		// attach to fbo
    4.34 -		glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D,
    4.35 -				mrt_tex[i], 0);
    4.36 +		glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i,
    4.37 +				GL_TEXTURE_2D, mrt_tex[i], 0);
    4.38  		CHECKGLERR;
    4.39  	}
    4.40  
    4.41 +	static GLenum draw_bufs[] = {
    4.42 +		GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT,
    4.43 +		GL_COLOR_ATTACHMENT2_EXT, GL_COLOR_ATTACHMENT3_EXT,
    4.44 +		GL_COLOR_ATTACHMENT4_EXT, GL_COLOR_ATTACHMENT5_EXT,
    4.45 +		GL_COLOR_ATTACHMENT6_EXT, GL_COLOR_ATTACHMENT7_EXT
    4.46 +	};
    4.47 +	glDrawBuffersARB(MRT_COUNT, draw_bufs);
    4.48 +
    4.49  	glGenRenderbuffersEXT(1, &rbuf_depth);
    4.50  	glBindRenderbufferEXT(GL_RENDERBUFFER, rbuf_depth);
    4.51  	glRenderbufferStorageEXT(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, tex_xsz, tex_ysz);