dungeon_crawler

changeset 77:d89b403f630b

added gamma correction (without dialing the lighting down yet) fixed the incorrect PointLight sphere radius
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 26 Oct 2012 03:03:52 +0300
parents f379c00eb07f
children 12a1dcfe91fa
files prototype/sdr/post.p.glsl prototype/src/light.cc prototype/src/light.h
diffstat 3 files changed, 14 insertions(+), 6 deletions(-) [+]
line diff
     1.1 --- a/prototype/sdr/post.p.glsl	Tue Oct 23 14:57:08 2012 +0300
     1.2 +++ b/prototype/sdr/post.p.glsl	Fri Oct 26 03:03:52 2012 +0300
     1.3 @@ -4,8 +4,10 @@
     1.4  void main()
     1.5  {
     1.6  	// lookup the render output color for this pixel
     1.7 -	vec4 color = texture2D(fbtex, gl_TexCoord[0].st);
     1.8 -	vec3 tc = (color.xyz * 15.0 + 0.5) / 16.0;
     1.9 +	vec4 fbcolor = texture2D(fbtex, gl_TexCoord[0].st);
    1.10 +	vec3 tc = (fbcolor.xyz * 15.0 + 0.5) / 16.0;
    1.11  	// use that color as an index into the palette
    1.12 -	gl_FragColor = vec4(texture3D(paltex, tc).xyz, color.a);
    1.13 +	vec3 color = texture3D(paltex, tc).xyz;
    1.14 +	// gamma-correction
    1.15 +	gl_FragColor = vec4(pow(color, 1.0 / 2.2), fbcolor.a);
    1.16  }
     2.1 --- a/prototype/src/light.cc	Tue Oct 23 14:57:08 2012 +0300
     2.2 +++ b/prototype/src/light.cc	Fri Oct 26 03:03:52 2012 +0300
     2.3 @@ -5,6 +5,7 @@
     2.4  #include "timer.h"
     2.5  
     2.6  unsigned int PointLight::sph_vbo = 0;
     2.7 +int PointLight::subdiv = 8;
     2.8  
     2.9  Light::Light(const Color &col)
    2.10  	: color(col)
    2.11 @@ -137,7 +138,11 @@
    2.12  	glMatrixMode(GL_MODELVIEW);
    2.13  	glPushMatrix();
    2.14  	glTranslatef(pos.x, pos.y, pos.z);
    2.15 -	glScalef(radius, radius, radius);
    2.16 +
    2.17 +	// scale by the hypotenuse of the triangle with adjacent side: radius
    2.18 +	// and angle M_PI / subdiv
    2.19 +	float s = radius / cos(M_PI / subdiv);
    2.20 +	glScalef(s, s, s);
    2.21  
    2.22  	Light::draw();
    2.23  
    2.24 @@ -168,8 +173,8 @@
    2.25  
    2.26  	printf("building sphere mesh for point light drawing\n");
    2.27  
    2.28 -	const static int udiv = 8;
    2.29 -	const static int vdiv = 4;
    2.30 +	const static int udiv = subdiv;
    2.31 +	const static int vdiv = udiv / 2;
    2.32  
    2.33  	int nquads = udiv * vdiv;
    2.34  	num_faces = nquads * 2;
     3.1 --- a/prototype/src/light.h	Tue Oct 23 14:57:08 2012 +0300
     3.2 +++ b/prototype/src/light.h	Fri Oct 26 03:03:52 2012 +0300
     3.3 @@ -37,6 +37,7 @@
     3.4  	float radius;
     3.5  
     3.6  	static unsigned int sph_vbo;
     3.7 +	static int subdiv;
     3.8  
     3.9  	bool create_mesh();
    3.10