| 1 |
// -*-C++-*- |
| 2 |
#version 120 |
| 3 |
|
| 4 |
#extension GL_EXT_draw_instanced : enable |
| 5 |
|
| 6 |
#define MODE_OFF 0 |
| 7 |
#define MODE_DIFFUSE 1 |
| 8 |
#define MODE_AMBIENT_AND_DIFFUSE 2 |
| 9 |
|
| 10 |
attribute vec3 instance_position; // (x,y,z) |
| 11 |
attribute vec4 instance_rotation_and_scale; // (heading, pitch, roll, scale) |
| 12 |
|
| 13 |
varying vec4 diffuse_term; |
| 14 |
varying vec3 normal; |
| 15 |
varying vec4 ecPosition; |
| 16 |
|
| 17 |
uniform int colorMode; |
| 18 |
|
| 19 |
void setupShadows(vec4 eyeSpacePos); |
| 20 |
void apply_instance_transforms(inout vec3 position, inout vec3 normal, in vec3 instance_position, in vec4 instance_rotation_and_scale); |
| 21 |
|
| 22 |
void main() |
| 23 |
{ |
| 24 |
vec3 position = gl_Vertex.xyz; |
| 25 |
apply_instance_transforms(position, normal, instance_position, instance_rotation_and_scale); |
| 26 |
|
| 27 |
gl_Position = gl_ModelViewProjectionMatrix * vec4(position, gl_Vertex.w); |
| 28 |
|
| 29 |
/************* The following is copied from default.vert *************/ |
| 30 |
ecPosition = gl_ModelViewMatrix * gl_Vertex; |
| 31 |
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; |
| 32 |
gl_TexCoord[2] = gl_TextureMatrix[2] * gl_MultiTexCoord2; |
| 33 |
|
| 34 |
vec4 ambient_color, diffuse_color; |
| 35 |
if (colorMode == MODE_DIFFUSE) { |
| 36 |
diffuse_color = gl_Color; |
| 37 |
ambient_color = gl_FrontMaterial.ambient; |
| 38 |
} else if (colorMode == MODE_AMBIENT_AND_DIFFUSE) { |
| 39 |
diffuse_color = gl_Color; |
| 40 |
ambient_color = gl_Color; |
| 41 |
} else { |
| 42 |
diffuse_color = gl_FrontMaterial.diffuse; |
| 43 |
ambient_color = gl_FrontMaterial.ambient; |
| 44 |
} |
| 45 |
diffuse_term = diffuse_color * gl_LightSource[0].diffuse; |
| 46 |
vec4 constant_term = gl_FrontMaterial.emission + ambient_color * |
| 47 |
(gl_LightModel.ambient + gl_LightSource[0].ambient); |
| 48 |
// Super hack: if diffuse material alpha is less than 1, assume a |
| 49 |
// transparency animation is at work |
| 50 |
if (gl_FrontMaterial.diffuse.a < 1.0) |
| 51 |
diffuse_term.a = gl_FrontMaterial.diffuse.a; |
| 52 |
else |
| 53 |
diffuse_term.a = gl_Color.a; |
| 54 |
// Another hack for supporting two-sided lighting without using |
| 55 |
// gl_FrontFacing in the fragment shader. |
| 56 |
gl_FrontColor.rgb = constant_term.rgb; gl_FrontColor.a = 1.0; |
| 57 |
gl_BackColor.rgb = constant_term.rgb; gl_BackColor.a = 0.0; |
| 58 |
|
| 59 |
setupShadows(ecPosition); |
| 60 |
} |