intravenous

changeset 5:aab0d8ea21cd

normalmap and sortof subsurface shader
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 22 Apr 2012 06:26:08 +0300
parents c6a6a64df6de
children 2723dc026c4f 3fae5eb6a411
files sdr/vein.p.glsl src/game.cc src/main.cc src/vein.cc src/vein.h
diffstat 5 files changed, 33 insertions(+), 4 deletions(-) [+]
line diff
     1.1 --- a/sdr/vein.p.glsl	Sun Apr 22 05:20:03 2012 +0300
     1.2 +++ b/sdr/vein.p.glsl	Sun Apr 22 06:26:08 2012 +0300
     1.3 @@ -1,8 +1,13 @@
     1.4  uniform sampler2D tex_norm;
     1.5 +uniform vec3 fog_col;
     1.6  
     1.7  varying vec3 vpos, vnorm;
     1.8  varying vec3 ldir, vdir;
     1.9  
    1.10 +const float fog_dens = 0.075;
    1.11 +
    1.12 +float fog(float dist);
    1.13 +
    1.14  void main()
    1.15  {
    1.16  	vec3 tnorm = texture2D(tex_norm, gl_TexCoord[0].st).xyz * 2.0 - 1.0;
    1.17 @@ -14,5 +19,13 @@
    1.18  	vec3 diff = vec3(0.8, 0.25, 0.2) * (1.0 - max(dot(l, n), 0.0));
    1.19  	vec3 spec = 0.5 * vec3(0.9, 0.4, 0.3) * pow(max(dot(h, n), 0.0), 10.0);
    1.20  
    1.21 -	gl_FragColor = vec4(diff + spec, 1.0);
    1.22 +	vec3 color = mix(fog_col, diff + spec, fog(vpos.z));
    1.23 +
    1.24 +	gl_FragColor = vec4(color, 1.0);
    1.25  }
    1.26 +
    1.27 +#define LOG2E	1.442695
    1.28 +float fog(float dist)
    1.29 +{
    1.30 +	return clamp(exp2(-fog_dens * fog_dens * dist * dist * LOG2E), 0.0, 1.0);
    1.31 +}
     2.1 --- a/src/game.cc	Sun Apr 22 05:20:03 2012 +0300
     2.2 +++ b/src/game.cc	Sun Apr 22 06:26:08 2012 +0300
     2.3 @@ -6,6 +6,8 @@
     2.4  #include "camera.h"
     2.5  #include "cockpit.h"
     2.6  
     2.7 +static const Vector3 fog_color{0.64, 0.1, 0.1};
     2.8 +
     2.9  static Vein *vein;
    2.10  static Ship ship;
    2.11  
    2.12 @@ -35,6 +37,9 @@
    2.13  	if(!vein->init()) {
    2.14  		return false;
    2.15  	}
    2.16 +	vein->set_fog_color(fog_color);
    2.17 +
    2.18 +	glClearColor(fog_color.x, fog_color.y, fog_color.z, 1);
    2.19  
    2.20  	return true;
    2.21  }
     3.1 --- a/src/main.cc	Sun Apr 22 05:20:03 2012 +0300
     3.2 +++ b/src/main.cc	Sun Apr 22 06:26:08 2012 +0300
     3.3 @@ -51,7 +51,6 @@
     3.4  	// update any game logic
     3.5  	game_update(msec);
     3.6  
     3.7 -	glClearColor(0.05, 0.05, 0.05, 1.0);
     3.8  	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     3.9  
    3.10  	// render stuff
     4.1 --- a/src/vein.cc	Sun Apr 22 05:20:03 2012 +0300
     4.2 +++ b/src/vein.cc	Sun Apr 22 06:26:08 2012 +0300
     4.3 @@ -11,8 +11,8 @@
     4.4  
     4.5  Vein::Vein()
     4.6  {
     4.7 -	gen_dist = 16.0;
     4.8 -	subdiv = 32;
     4.9 +	gen_dist = 40.0;
    4.10 +	subdiv = 64;
    4.11  	ring_subdiv = 24;
    4.12  	rad = 2.0;
    4.13  
    4.14 @@ -80,6 +80,15 @@
    4.15  	return true;
    4.16  }
    4.17  
    4.18 +void Vein::set_fog_color(const Vector3 &col)
    4.19 +{
    4.20 +	fog_color = col;
    4.21 +
    4.22 +	if(sdr) {
    4.23 +		set_uniform_float3(sdr, "fog_col", col.x, col.y, col.z);
    4.24 +	}
    4.25 +}
    4.26 +
    4.27  void Vein::draw(const Vector3 &ppos) const
    4.28  {
    4.29  	float start_z = ppos.z - gen_dist / 2.0;
     5.1 --- a/src/vein.h	Sun Apr 22 05:20:03 2012 +0300
     5.2 +++ b/src/vein.h	Sun Apr 22 06:26:08 2012 +0300
     5.3 @@ -14,6 +14,7 @@
     5.4  	int attr_tang_loc;
     5.5  
     5.6  	unsigned int tex_norm;
     5.7 +	Vector3 fog_color;
     5.8  
     5.9  	Vector3 calc_center(const Vector3 &ppos) const;
    5.10  	Vector3 calc_dir(const Vector3 &ppos) const;
    5.11 @@ -26,6 +27,8 @@
    5.12  
    5.13  	bool init();
    5.14  
    5.15 +	void set_fog_color(const Vector3 &col);
    5.16 +
    5.17  	void draw(const Vector3 &player_pos) const;
    5.18  };
    5.19