aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortaw27 <taw27@bf6ca9ba-c028-0410-8290-897cf20841d1>2008-06-06 11:18:42 +0000
committertaw27 <taw27@bf6ca9ba-c028-0410-8290-897cf20841d1>2008-06-06 11:18:42 +0000
commit0772a4fa2344d228f78541e320627c487a5ee4d3 (patch)
tree0ee265542e3458ab12849ca1b6e24bc6701adf8c
parentdadacff0823b881b687e48312aafa5351d4818e0 (diff)
Shader fixes (pulled across from Synth3D)
git-svn-id: svn://cook.msm.cam.ac.uk:745/diff-tomo/dtr@282 bf6ca9ba-c028-0410-8290-897cf20841d1
-rw-r--r--data/light-pp.frag41
-rw-r--r--data/light-pp.vert23
-rw-r--r--src/glbits.c18
3 files changed, 47 insertions, 35 deletions
diff --git a/data/light-pp.frag b/data/light-pp.frag
index ca96990..c40b302 100644
--- a/data/light-pp.frag
+++ b/data/light-pp.frag
@@ -9,35 +9,44 @@
*
*/
-varying vec4 col_ambi;
-varying vec4 col_diff;
-varying vec4 col_spec;
-varying vec4 col_emit;
+varying vec3 col_ambi;
+varying vec3 col_diff;
+varying vec3 col_spec;
+varying vec3 col_emit;
varying float shininess;
varying vec3 normal;
-varying vec3 halfvc;
+varying vec3 lightvc;
+varying vec3 lighthvc;
void main() {
- vec4 ambi;
- vec4 diff;
- vec4 spec;
+ vec3 ambi;
+ vec3 emit;
+ vec3 diff;
+ vec3 spec;
+
+ vec3 norm = normalize(normal);
/* Ambient contribution */
- ambi = col_ambi * gl_LightModel.ambient;
- ambi += col_ambi * gl_LightSource[0].ambient;
+ ambi = col_ambi * gl_LightModel.ambient.rgb;
+
+ /* Emission */
+ emit = col_emit;
/* Diffuse contribution */
- diff = col_diff * clamp(dot( vec3(normalize(gl_LightSource[0].position)), normal ), 0.0, 1.0);
+ diff = col_diff * gl_LightSource[0].diffuse.rgb * max(dot(normalize(lightvc).xyz, norm), 0.0);
/* Specular contribution */
- spec = col_spec * clamp(pow(dot( vec3(normal), halfvc ), shininess), 0.0, 1.0);
+ if ( col_spec.r > 0.0 ) {
+ float ndothv = max(dot(norm, normalize(lighthvc)), 0.0);
+ spec = col_spec * gl_LightSource[0].specular.rgb * pow(ndothv, shininess);
+ }
- gl_FragColor = vec4(min(col_emit.r + ambi.r + diff.r + spec.r, 1.0),
- min(col_emit.g + ambi.g + diff.g + spec.g, 1.0),
- min(col_emit.b + ambi.b + diff.b + spec.b, 1.0),
- min(col_emit.a + ambi.a + diff.a + spec.a, 1.0));
+ gl_FragColor = vec4(min(emit.r + ambi.r + diff.r + spec.r, 1.0),
+ min(emit.g + ambi.g + diff.g + spec.g, 1.0),
+ min(emit.b + ambi.b + diff.b + spec.b, 1.0),
+ 1.0);
}
diff --git a/data/light-pp.vert b/data/light-pp.vert
index d01f135..8333aae 100644
--- a/data/light-pp.vert
+++ b/data/light-pp.vert
@@ -9,25 +9,26 @@
*
*/
-varying vec4 col_ambi;
-varying vec4 col_diff;
-varying vec4 col_spec;
-varying vec4 col_emit;
+varying vec3 col_ambi;
+varying vec3 col_diff;
+varying vec3 col_spec;
+varying vec3 col_emit;
varying float shininess;
varying vec3 normal;
-varying vec3 halfvc;
+varying vec3 lightvc;
+varying vec3 lighthvc;
void main() {
normal = normalize(gl_NormalMatrix * gl_Normal);
- halfvc = vec3(gl_LightSource[0].halfVector);
-
- col_ambi = gl_FrontMaterial.ambient;
- col_diff = gl_FrontMaterial.diffuse;
- col_spec = gl_FrontMaterial.specular;
- col_emit = gl_FrontMaterial.emission;
+ lightvc = normalize(vec3(gl_LightSource[0].position));
+ lighthvc = normalize(gl_LightSource[0].halfVector.xyz);
+ col_ambi = gl_Color.rgb;
+ col_diff = gl_Color.rgb;
+ col_spec = gl_FrontMaterial.specular.rgb;
+ col_emit = gl_FrontMaterial.emission.rgb;
shininess = gl_FrontMaterial.shininess;
gl_Position = ftransform();
diff --git a/src/glbits.c b/src/glbits.c
index aff3a36..b489ea6 100644
--- a/src/glbits.c
+++ b/src/glbits.c
@@ -651,10 +651,9 @@ gint glbits_expose(GtkWidget *widget, GdkEventExpose *event, DisplayWindow *dw)
float m[4][4];
GLfloat black[] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat blue[] = { 0.0, 0.0, 0.5, 1.0 };
- GLfloat blue_spec[] = { 0.0, 0.0, 1.0, 1.0 };
- GLfloat gold[] = { 0.5, 0.5, 0.0, 1.0 };
- GLfloat gold_spec[] = { 0.9, 0.9, 0.0, 1.0 };
- GLfloat light0_position[] = { 0.1, 0.1, 1.0, 0.0 };
+ GLfloat white[] = { 1.0, 1.0, 1.0, 1.0 };
+ GLfloat gold[] = { 0.7, 0.7, 0.0, 1.0 };
+ GLfloat light0_position[] = { 0.0, 1.0, 1.0, 0.0 };
GLfloat light0_diffuse[] = { 0.8, 0.8, 0.8, 1.0 };
GLfloat light0_specular[] = { 0.8, 0.8, 0.8, 1.0 };
GLfloat grey[] = { 0.6, 0.6, 0.6, 1.0 };
@@ -734,6 +733,7 @@ gint glbits_expose(GtkWidget *widget, GdkEventExpose *event, DisplayWindow *dw)
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, black);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, black);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, black);
+ glColor3f(0.0, 0.0, 0.0);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 0.0);
if ( dw->gl_use_buffers ) {
@@ -758,8 +758,9 @@ gint glbits_expose(GtkWidget *widget, GdkEventExpose *event, DisplayWindow *dw)
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, blue);
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, black);
- glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, blue_spec);
- glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 50.0);
+ glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, white);
+ glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 100.0);
+ glColor3f(0.0, 0.0, 1.0);
if ( dw->gl_use_buffers ) {
glBindBufferARB(GL_ARRAY_BUFFER, dw->gl_marker_vertex_buffer);
@@ -783,8 +784,9 @@ gint glbits_expose(GtkWidget *widget, GdkEventExpose *event, DisplayWindow *dw)
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, black);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, gold);
- glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, gold_spec);
- glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 70.0);
+ glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, white);
+ glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 100.0);
+ glColor3f(0.7, 0.7, 0.0);
glUseProgramObjectARB(dw->gl_program_lightpp);
if ( dw->gl_use_buffers ) {