* shader are now dynamically loaded
This commit is contained in:
parent
aff49c268b
commit
2568c13b15
12 changed files with 44 additions and 59 deletions
43
data/shader/gameobjects.frag
Normal file
43
data/shader/gameobjects.frag
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#version 120
|
||||
|
||||
varying vec3 vertex;
|
||||
varying vec3 normal;
|
||||
|
||||
uniform vec3 materialColor;
|
||||
uniform vec3 lightColor;
|
||||
uniform vec3 lightPosition;
|
||||
|
||||
varying vec3 lightDirection;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 Eye = normalize(-vertex);
|
||||
vec3 Reflected = normalize(reflect( -lightPosition, normal));
|
||||
|
||||
vec3 IAmbient = vec3(0.2f);
|
||||
|
||||
// TODO: add noise texture
|
||||
vec3 IDiffuse = vec3(materialColor) * lightColor * max(dot(normal, lightDirection), 0.0);
|
||||
|
||||
// TODO make instensity/exponent as parameter
|
||||
//vec3 ISpecular = lightColor * 5.0 * pow(max(dot(Reflected, Eye), 0.0), 2.0);
|
||||
vec3 ISpecular = lightColor * pow(max(dot(Reflected, Eye), 0.0), 2.0);
|
||||
|
||||
if (dot(lightDirection, normal) <= 0.0) {
|
||||
ISpecular = vec3(0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
// p: point of the fragment on the surface
|
||||
//vec3 v_eye = normalize(pos_eye - pos_space); // point from p to eye
|
||||
//vec3 v_sun = normalize(sun_light_dir); // points from p to the sun
|
||||
|
||||
//float specular = spec_int * pow(
|
||||
// clamp(dot((v_eye + v_sun)/2.0, normal), 0.0, 1.0),
|
||||
// 2.0*specular_exponent);
|
||||
|
||||
//ISpecular = vec3(1.0, 0.0, 0.0) * specular;
|
||||
|
||||
//gl_FragColor = vec4(ISpecular, 1.0);
|
||||
gl_FragColor = vec4((IAmbient + IDiffuse) + ISpecular, 1.0);
|
||||
//gl_FragColor = vec4(0.5+0.5*normal, 1.0);
|
||||
}
|
||||
23
data/shader/gameobjects.vert
Normal file
23
data/shader/gameobjects.vert
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#version 120
|
||||
|
||||
attribute vec3 in_vertex;
|
||||
attribute vec3 in_normal;
|
||||
|
||||
varying vec3 vertex;
|
||||
varying vec3 normal;
|
||||
varying vec3 lightDirection;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform vec3 lightPosition;
|
||||
|
||||
void main()
|
||||
{
|
||||
// TODO: this becomes invalid when projection matrices are used
|
||||
vec3 p = (model*vec4(in_vertex, 1.0)).xyz;
|
||||
lightDirection = normalize(lightPosition - p);
|
||||
|
||||
vertex = p.xyz;
|
||||
normal = normalize((model*vec4(in_normal.xyz, 0.0)).xyz);
|
||||
|
||||
gl_Position = vec4(p, 1.0);
|
||||
}
|
||||
16
data/shader/particle.frag
Normal file
16
data/shader/particle.frag
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#version 120
|
||||
varying vec2 vertex;
|
||||
varying vec2 velocity;
|
||||
uniform float maxAge;
|
||||
uniform float time;
|
||||
void main()
|
||||
{
|
||||
//gl_FragColor = vec4(0.5+0.5*vertex.x, 0.5+0.5*vertex.y, 0.0, 1.0);
|
||||
if (length(vertex) > 1.0) {
|
||||
discard;
|
||||
}
|
||||
float decay = time / maxAge;
|
||||
decay = 5.0*decay*decay;
|
||||
// (length(10.0*velocity));
|
||||
gl_FragColor = vec4(1.0/max(1.0, decay), 1.0/max(1.0, 6.0*decay), 0.0, 1.0);
|
||||
}
|
||||
18
data/shader/particle.vert
Normal file
18
data/shader/particle.vert
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#version 120
|
||||
attribute vec2 in_vertex;
|
||||
attribute vec2 in_position;
|
||||
attribute vec2 in_velocity;
|
||||
varying vec2 velocity;
|
||||
varying vec2 vertex;
|
||||
uniform float time;
|
||||
uniform float size;
|
||||
void main()
|
||||
{
|
||||
vec2 p = size*in_vertex;
|
||||
p += log(1.0+time) * in_velocity;
|
||||
p += in_position;
|
||||
gl_Position = vec4(p, 0.0, 1.0);
|
||||
|
||||
vertex = in_vertex;
|
||||
velocity = in_velocity;
|
||||
}
|
||||
6
data/shader/simple.frag
Normal file
6
data/shader/simple.frag
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#version 120
|
||||
varying vec3 vertex;
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = vec4(0.5+0.5*vertex.xyz, 1.0);
|
||||
}
|
||||
7
data/shader/simple.vert
Normal file
7
data/shader/simple.vert
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#version 120
|
||||
varying vec3 vertex;
|
||||
void main()
|
||||
{
|
||||
gl_Position = gl_Vertex;
|
||||
vertex = gl_Position.xyz;
|
||||
}
|
||||
9
data/shader/sphere.frag
Normal file
9
data/shader/sphere.frag
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#version 120
|
||||
varying vec3 vertex;
|
||||
uniform vec3 color;
|
||||
void main()
|
||||
{
|
||||
//gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
|
||||
//gl_FragColor = vec4(0.5+0.5*vertex.xyz, 1.0);
|
||||
gl_FragColor = vec4(color, 1.0);
|
||||
}
|
||||
12
data/shader/sphere.vert
Normal file
12
data/shader/sphere.vert
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#version 120
|
||||
varying vec3 vertex;
|
||||
uniform mat4 model;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
//vec3 p = position + scale*gl_Vertex.xyz;
|
||||
vec3 p = (model*gl_Vertex).xyz;
|
||||
gl_Position = vec4(p, 1.0);
|
||||
vertex = p.xyz;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue