Commit 7ef66541 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[CHANGE] - basic (not yet working) phong lighting

parent 4cc63aae
......@@ -35,8 +35,9 @@ vec4 blinnPhongIllumination( vec3 ambient, vec3 diffuse, vec3 specular, float sh
}
/**
* Function to calculate lighting intensity based on "Real-Time Volume Graphics, p 119, chapter 5.4, Listing 5.1".
* It is basically the same as blinnPhongIllumination function above. But it is faster if you just need the intensity.
* @brief Function to calculate lighting intensitybased on "Real-Time Volume Graphics, p 119, chapter 5.4, Listing 5.1".
* It is basically the same as blinnPhongIllumination function above. But it is faster if you just need
* the intensity.
*
* @param ambient materials ambient intensity
* @param diffuse materials diffuse intensity
......@@ -50,9 +51,9 @@ vec4 blinnPhongIllumination( vec3 ambient, vec3 diffuse, vec3 specular, float sh
*
* @return the light intensity.
*/
float blinnPhongIlluminationIntensity( float ambient, float diffuse, float specular, float shininess,
float lightIntensity, float ambientIntensity,
vec3 normalDir, vec3 viewDir, vec3 lightDir )
float blinnPhongIlluminationIntensity(float ambient, float diffuse, float specular, float shininess,
float lightIntensity, float ambientIntensity,
vec3 normalDir, vec3 viewDir, vec3 lightDir )
{
vec3 H = normalize( lightDir + viewDir );
......
......@@ -24,6 +24,8 @@
#version 120
#include "shadingTools.fs"
/////////////////////////////////////////////////////////////////////////////
// Varyings
/////////////////////////////////////////////////////////////////////////////
......@@ -40,9 +42,6 @@ uniform sampler3D tex0;
// The isovalue to use.
uniform float u_isovalue;
// True if only the simple depth value should be used for coloring
uniform bool u_depthCueingOnly;
// The number of steps to use.
uniform int u_steps;
......@@ -158,6 +157,37 @@ void main()
color = gl_Color * 1.5 * d * d;
#endif
#ifdef PHONG
// find a proper normal for a headlight
float s = 0.005;
float valueXP = texture3D( tex0, curPoint + vec3( s, 0.0, 0.0 ) ).r;
float valueXM = texture3D( tex0, curPoint - vec3( s, 0.0, 0.0 ) ).r;
float valueYP = texture3D( tex0, curPoint + vec3( 0.0, s, 0.0 ) ).r;
float valueYM = texture3D( tex0, curPoint - vec3( 0.0, s, 0.0 ) ).r;
float valueZP = texture3D( tex0, curPoint + vec3( 0.0, 0.0, s ) ).r;
float valueZM = texture3D( tex0, curPoint - vec3( 0.0, 0.0, s ) ).r;
vec3 dir = vec3( 0.0 );//v_ray;
dir += vec3( valueXP, 0.0, 0.0 );
dir -= vec3( valueXM, 0.0, 0.0 );
dir += vec3( 0.0, valueYP, 0.0 );
dir -= vec3( 0.0, valueYM, 0.0 );
dir += vec3( 0.0, 0.0, valueZP );
dir -= vec3( 0.0, 0.0, valueZP );
// Phong:
float light = blinnPhongIlluminationIntensity(
0.3, // material ambient
1.0, // material diffuse
1.3, // material specular
10.0, // shinines
1.0, // light diffuse
0.75, // light ambient
normalize( -dir ), // normal
normalize( v_ray ), // view direction
normalize( v_lightSource ) // light source position
);
color = light * gl_Color;
#endif
#ifdef PHONGWITHDEPTH
#endif
......
......@@ -35,3 +35,6 @@ varying vec3 v_ray;
// the Surface normal at this point
varying vec3 v_normal;
// The light source in local coordinates
varying vec3 v_lightSource;
......@@ -24,6 +24,8 @@
#version 120
#include "transformationTools.fs"
/////////////////////////////////////////////////////////////////////////////
// Varyings
/////////////////////////////////////////////////////////////////////////////
......@@ -65,7 +67,12 @@ void main()
// Therefore use two points, as we transform a vector
vec4 camLookAt = vec4( 0.0, 0.0, -1.0, 1.0 );
vec4 camPos = vec4( 0.0, 0.0, 0.0, 1.0 );
v_ray = ( gl_ModelViewMatrixInverse * ( camLookAt - camPos ) ).xyz;
v_ray = worldToLocal( camLookAt, camPos ).xyz;
// also get the coordinates of the light
vec4 lpos = gl_LightSource[0].position;
// lpos = vec4( 0.0, 0.0, 1000.0, 1.0 );
v_lightSource = worldToLocal( lpos ).xyz;
// Simply project the vertex
gl_Position = ftransform();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment