add initial examples, replacing the 'Demos/Demos3'. Will make it work cross-platform, OpenGL3/OpenGL2 and add more examples to it.
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
#version 330
|
||||
precision highp float;
|
||||
|
||||
|
||||
layout(location = 0) out float fragmentdepth;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
fragmentdepth = gl_FragCoord.z;
|
||||
}
|
||||
10
examples/OpenGLWindow/Shaders/createShadowMapInstancingPS.h
Normal file
10
examples/OpenGLWindow/Shaders/createShadowMapInstancingPS.h
Normal file
@@ -0,0 +1,10 @@
|
||||
//this file is autogenerated using stringify.bat (premake --stringify) in the build folder of this project
|
||||
static const char* createShadowMapInstancingFragmentShader= \
|
||||
"#version 330\n"
|
||||
"precision highp float;\n"
|
||||
"layout(location = 0) out float fragmentdepth;\n"
|
||||
"void main(void)\n"
|
||||
"{\n"
|
||||
" fragmentdepth = gl_FragCoord.z;\n"
|
||||
"}\n"
|
||||
;
|
||||
@@ -0,0 +1,55 @@
|
||||
#version 330
|
||||
precision highp float;
|
||||
|
||||
|
||||
layout (location = 0) in vec4 position;
|
||||
layout (location = 1) in vec4 instance_position;
|
||||
layout (location = 2) in vec4 instance_quaternion;
|
||||
layout (location = 3) in vec2 uvcoords;
|
||||
layout (location = 4) in vec3 vertexnormal;
|
||||
layout (location = 5) in vec4 instance_color;
|
||||
layout (location = 6) in vec3 instance_scale;
|
||||
|
||||
|
||||
uniform mat4 depthMVP;
|
||||
|
||||
|
||||
vec4 quatMul ( in vec4 q1, in vec4 q2 )
|
||||
{
|
||||
vec3 im = q1.w * q2.xyz + q1.xyz * q2.w + cross ( q1.xyz, q2.xyz );
|
||||
vec4 dt = q1 * q2;
|
||||
float re = dot ( dt, vec4 ( -1.0, -1.0, -1.0, 1.0 ) );
|
||||
return vec4 ( im, re );
|
||||
}
|
||||
|
||||
vec4 quatFromAxisAngle(vec4 axis, in float angle)
|
||||
{
|
||||
float cah = cos(angle*0.5);
|
||||
float sah = sin(angle*0.5);
|
||||
float d = inversesqrt(dot(axis,axis));
|
||||
vec4 q = vec4(axis.x*sah*d,axis.y*sah*d,axis.z*sah*d,cah);
|
||||
return q;
|
||||
}
|
||||
//
|
||||
// vector rotation via quaternion
|
||||
//
|
||||
vec4 quatRotate3 ( in vec3 p, in vec4 q )
|
||||
{
|
||||
vec4 temp = quatMul ( q, vec4 ( p, 0.0 ) );
|
||||
return quatMul ( temp, vec4 ( -q.x, -q.y, -q.z, q.w ) );
|
||||
}
|
||||
vec4 quatRotate ( in vec4 p, in vec4 q )
|
||||
{
|
||||
vec4 temp = quatMul ( q, p );
|
||||
return quatMul ( temp, vec4 ( -q.x, -q.y, -q.z, q.w ) );
|
||||
}
|
||||
|
||||
|
||||
void main(void)
|
||||
{
|
||||
vec4 q = instance_quaternion;
|
||||
vec4 localcoord = quatRotate3( position.xyz*instance_scale,q);
|
||||
vec4 vertexPos = depthMVP * vec4( (instance_position+localcoord).xyz,1);
|
||||
gl_Position = vertexPos;
|
||||
}
|
||||
|
||||
48
examples/OpenGLWindow/Shaders/createShadowMapInstancingVS.h
Normal file
48
examples/OpenGLWindow/Shaders/createShadowMapInstancingVS.h
Normal file
@@ -0,0 +1,48 @@
|
||||
//this file is autogenerated using stringify.bat (premake --stringify) in the build folder of this project
|
||||
static const char* createShadowMapInstancingVertexShader= \
|
||||
"#version 330\n"
|
||||
"precision highp float;\n"
|
||||
"layout (location = 0) in vec4 position;\n"
|
||||
"layout (location = 1) in vec4 instance_position;\n"
|
||||
"layout (location = 2) in vec4 instance_quaternion;\n"
|
||||
"layout (location = 3) in vec2 uvcoords;\n"
|
||||
"layout (location = 4) in vec3 vertexnormal;\n"
|
||||
"layout (location = 5) in vec4 instance_color;\n"
|
||||
"layout (location = 6) in vec3 instance_scale;\n"
|
||||
"uniform mat4 depthMVP;\n"
|
||||
"vec4 quatMul ( in vec4 q1, in vec4 q2 )\n"
|
||||
"{\n"
|
||||
" vec3 im = q1.w * q2.xyz + q1.xyz * q2.w + cross ( q1.xyz, q2.xyz );\n"
|
||||
" vec4 dt = q1 * q2;\n"
|
||||
" float re = dot ( dt, vec4 ( -1.0, -1.0, -1.0, 1.0 ) );\n"
|
||||
" return vec4 ( im, re );\n"
|
||||
"}\n"
|
||||
"vec4 quatFromAxisAngle(vec4 axis, in float angle)\n"
|
||||
"{\n"
|
||||
" float cah = cos(angle*0.5);\n"
|
||||
" float sah = sin(angle*0.5);\n"
|
||||
" float d = inversesqrt(dot(axis,axis));\n"
|
||||
" vec4 q = vec4(axis.x*sah*d,axis.y*sah*d,axis.z*sah*d,cah);\n"
|
||||
" return q;\n"
|
||||
"}\n"
|
||||
"//\n"
|
||||
"// vector rotation via quaternion\n"
|
||||
"//\n"
|
||||
"vec4 quatRotate3 ( in vec3 p, in vec4 q )\n"
|
||||
"{\n"
|
||||
" vec4 temp = quatMul ( q, vec4 ( p, 0.0 ) );\n"
|
||||
" return quatMul ( temp, vec4 ( -q.x, -q.y, -q.z, q.w ) );\n"
|
||||
"}\n"
|
||||
"vec4 quatRotate ( in vec4 p, in vec4 q )\n"
|
||||
"{\n"
|
||||
" vec4 temp = quatMul ( q, p );\n"
|
||||
" return quatMul ( temp, vec4 ( -q.x, -q.y, -q.z, q.w ) );\n"
|
||||
"}\n"
|
||||
"void main(void)\n"
|
||||
"{\n"
|
||||
" vec4 q = instance_quaternion;\n"
|
||||
" vec4 localcoord = quatRotate3( position.xyz*instance_scale,q);\n"
|
||||
" vec4 vertexPos = depthMVP * vec4( (instance_position+localcoord).xyz,1);\n"
|
||||
" gl_Position = vertexPos;\n"
|
||||
"}\n"
|
||||
;
|
||||
36
examples/OpenGLWindow/Shaders/instancingPS.glsl
Normal file
36
examples/OpenGLWindow/Shaders/instancingPS.glsl
Normal file
@@ -0,0 +1,36 @@
|
||||
#version 330
|
||||
precision highp float;
|
||||
|
||||
in Fragment
|
||||
{
|
||||
vec4 color;
|
||||
} fragment;
|
||||
|
||||
in Vert
|
||||
{
|
||||
vec2 texcoord;
|
||||
} vert;
|
||||
|
||||
uniform sampler2D Diffuse;
|
||||
in vec3 lightDir,normal,ambient;
|
||||
out vec4 color;
|
||||
|
||||
void main_textured(void)
|
||||
{
|
||||
color = vec4(0.1,0.2,0.3,0.3);
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
vec4 texel = fragment.color*texture(Diffuse,vert.texcoord);//fragment.color;
|
||||
vec3 ct,cf;
|
||||
float intensity,at,af;
|
||||
intensity = max(dot(lightDir,normalize(normal)),0);
|
||||
cf = intensity*vec3(1.0,1.0,1.0)+ambient;
|
||||
af = 1.0;
|
||||
|
||||
ct = texel.rgb;
|
||||
at = texel.a;
|
||||
|
||||
color = vec4(ct * cf, at * af);
|
||||
}
|
||||
34
examples/OpenGLWindow/Shaders/instancingPS.h
Normal file
34
examples/OpenGLWindow/Shaders/instancingPS.h
Normal file
@@ -0,0 +1,34 @@
|
||||
//this file is autogenerated using stringify.bat (premake --stringify) in the build folder of this project
|
||||
static const char* instancingFragmentShader= \
|
||||
"#version 330\n"
|
||||
"precision highp float;\n"
|
||||
"in Fragment\n"
|
||||
"{\n"
|
||||
" vec4 color;\n"
|
||||
"} fragment;\n"
|
||||
"in Vert\n"
|
||||
"{\n"
|
||||
" vec2 texcoord;\n"
|
||||
"} vert;\n"
|
||||
"uniform sampler2D Diffuse;\n"
|
||||
"in vec3 lightDir,normal,ambient;\n"
|
||||
"out vec4 color;\n"
|
||||
"void main_textured(void)\n"
|
||||
"{\n"
|
||||
" color = vec4(0.1,0.2,0.3,0.3);\n"
|
||||
"}\n"
|
||||
"void main(void)\n"
|
||||
"{\n"
|
||||
" vec4 texel = fragment.color*texture(Diffuse,vert.texcoord);//fragment.color;\n"
|
||||
" vec3 ct,cf;\n"
|
||||
" float intensity,at,af;\n"
|
||||
" intensity = max(dot(lightDir,normalize(normal)),0);\n"
|
||||
" cf = intensity*vec3(1.0,1.0,1.0)+ambient;\n"
|
||||
" af = 1.0;\n"
|
||||
" \n"
|
||||
" ct = texel.rgb;\n"
|
||||
" at = texel.a;\n"
|
||||
" \n"
|
||||
" color = vec4(ct * cf, at * af); \n"
|
||||
"}\n"
|
||||
;
|
||||
82
examples/OpenGLWindow/Shaders/instancingVS.glsl
Normal file
82
examples/OpenGLWindow/Shaders/instancingVS.glsl
Normal file
@@ -0,0 +1,82 @@
|
||||
#version 330
|
||||
precision highp float;
|
||||
|
||||
|
||||
layout (location = 0) in vec4 position;
|
||||
layout (location = 1) in vec4 instance_position;
|
||||
layout (location = 2) in vec4 instance_quaternion;
|
||||
layout (location = 3) in vec2 uvcoords;
|
||||
layout (location = 4) in vec3 vertexnormal;
|
||||
layout (location = 5) in vec4 instance_color;
|
||||
layout (location = 6) in vec3 instance_scale;
|
||||
|
||||
|
||||
uniform mat4 ModelViewMatrix;
|
||||
uniform mat4 ProjectionMatrix;
|
||||
|
||||
out Fragment
|
||||
{
|
||||
vec4 color;
|
||||
} fragment;
|
||||
|
||||
out Vert
|
||||
{
|
||||
vec2 texcoord;
|
||||
} vert;
|
||||
|
||||
|
||||
vec4 quatMul ( in vec4 q1, in vec4 q2 )
|
||||
{
|
||||
vec3 im = q1.w * q2.xyz + q1.xyz * q2.w + cross ( q1.xyz, q2.xyz );
|
||||
vec4 dt = q1 * q2;
|
||||
float re = dot ( dt, vec4 ( -1.0, -1.0, -1.0, 1.0 ) );
|
||||
return vec4 ( im, re );
|
||||
}
|
||||
|
||||
vec4 quatFromAxisAngle(vec4 axis, in float angle)
|
||||
{
|
||||
float cah = cos(angle*0.5);
|
||||
float sah = sin(angle*0.5);
|
||||
float d = inversesqrt(dot(axis,axis));
|
||||
vec4 q = vec4(axis.x*sah*d,axis.y*sah*d,axis.z*sah*d,cah);
|
||||
return q;
|
||||
}
|
||||
//
|
||||
// vector rotation via quaternion
|
||||
//
|
||||
vec4 quatRotate3 ( in vec3 p, in vec4 q )
|
||||
{
|
||||
vec4 temp = quatMul ( q, vec4 ( p, 0.0 ) );
|
||||
return quatMul ( temp, vec4 ( -q.x, -q.y, -q.z, q.w ) );
|
||||
}
|
||||
vec4 quatRotate ( in vec4 p, in vec4 q )
|
||||
{
|
||||
vec4 temp = quatMul ( q, p );
|
||||
return quatMul ( temp, vec4 ( -q.x, -q.y, -q.z, q.w ) );
|
||||
}
|
||||
|
||||
out vec3 lightDir,normal,ambient;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
vec4 q = instance_quaternion;
|
||||
ambient = vec3(0.3,.3,0.3);
|
||||
|
||||
|
||||
vec4 local_normal = (quatRotate3( vertexnormal,q));
|
||||
vec3 light_pos = vec3(-0.3,0.1,0.1);
|
||||
normal = local_normal.xyz;//normalize(ModelViewMatrix * local_normal).xyz;
|
||||
|
||||
lightDir = normalize(light_pos);//gl_LightSource[0].position.xyz));
|
||||
// lightDir = normalize(vec3(gl_LightSource[0].position));
|
||||
|
||||
vec4 axis = vec4(1,1,1,0);
|
||||
vec4 localcoord = quatRotate3( position.xyz*instance_scale,q);
|
||||
vec4 vertexPos = ProjectionMatrix * ModelViewMatrix *(instance_position+localcoord);
|
||||
|
||||
gl_Position = vertexPos;
|
||||
|
||||
fragment.color = instance_color;
|
||||
vert.texcoord = uvcoords;
|
||||
}
|
||||
|
||||
71
examples/OpenGLWindow/Shaders/instancingVS.h
Normal file
71
examples/OpenGLWindow/Shaders/instancingVS.h
Normal file
@@ -0,0 +1,71 @@
|
||||
//this file is autogenerated using stringify.bat (premake --stringify) in the build folder of this project
|
||||
static const char* instancingVertexShader= \
|
||||
"#version 330\n"
|
||||
"precision highp float;\n"
|
||||
"layout (location = 0) in vec4 position;\n"
|
||||
"layout (location = 1) in vec4 instance_position;\n"
|
||||
"layout (location = 2) in vec4 instance_quaternion;\n"
|
||||
"layout (location = 3) in vec2 uvcoords;\n"
|
||||
"layout (location = 4) in vec3 vertexnormal;\n"
|
||||
"layout (location = 5) in vec4 instance_color;\n"
|
||||
"layout (location = 6) in vec3 instance_scale;\n"
|
||||
"uniform mat4 ModelViewMatrix;\n"
|
||||
"uniform mat4 ProjectionMatrix;\n"
|
||||
"out Fragment\n"
|
||||
"{\n"
|
||||
" vec4 color;\n"
|
||||
"} fragment;\n"
|
||||
"out Vert\n"
|
||||
"{\n"
|
||||
" vec2 texcoord;\n"
|
||||
"} vert;\n"
|
||||
"vec4 quatMul ( in vec4 q1, in vec4 q2 )\n"
|
||||
"{\n"
|
||||
" vec3 im = q1.w * q2.xyz + q1.xyz * q2.w + cross ( q1.xyz, q2.xyz );\n"
|
||||
" vec4 dt = q1 * q2;\n"
|
||||
" float re = dot ( dt, vec4 ( -1.0, -1.0, -1.0, 1.0 ) );\n"
|
||||
" return vec4 ( im, re );\n"
|
||||
"}\n"
|
||||
"vec4 quatFromAxisAngle(vec4 axis, in float angle)\n"
|
||||
"{\n"
|
||||
" float cah = cos(angle*0.5);\n"
|
||||
" float sah = sin(angle*0.5);\n"
|
||||
" float d = inversesqrt(dot(axis,axis));\n"
|
||||
" vec4 q = vec4(axis.x*sah*d,axis.y*sah*d,axis.z*sah*d,cah);\n"
|
||||
" return q;\n"
|
||||
"}\n"
|
||||
"//\n"
|
||||
"// vector rotation via quaternion\n"
|
||||
"//\n"
|
||||
"vec4 quatRotate3 ( in vec3 p, in vec4 q )\n"
|
||||
"{\n"
|
||||
" vec4 temp = quatMul ( q, vec4 ( p, 0.0 ) );\n"
|
||||
" return quatMul ( temp, vec4 ( -q.x, -q.y, -q.z, q.w ) );\n"
|
||||
"}\n"
|
||||
"vec4 quatRotate ( in vec4 p, in vec4 q )\n"
|
||||
"{\n"
|
||||
" vec4 temp = quatMul ( q, p );\n"
|
||||
" return quatMul ( temp, vec4 ( -q.x, -q.y, -q.z, q.w ) );\n"
|
||||
"}\n"
|
||||
"out vec3 lightDir,normal,ambient;\n"
|
||||
"void main(void)\n"
|
||||
"{\n"
|
||||
" vec4 q = instance_quaternion;\n"
|
||||
" ambient = vec3(0.3,.3,0.3);\n"
|
||||
" \n"
|
||||
" \n"
|
||||
" vec4 local_normal = (quatRotate3( vertexnormal,q));\n"
|
||||
" vec3 light_pos = vec3(-0.3,0.1,0.1);\n"
|
||||
" normal = local_normal.xyz;//normalize(ModelViewMatrix * local_normal).xyz;\n"
|
||||
" lightDir = normalize(light_pos);//gl_LightSource[0].position.xyz));\n"
|
||||
"// lightDir = normalize(vec3(gl_LightSource[0].position));\n"
|
||||
" \n"
|
||||
" vec4 axis = vec4(1,1,1,0);\n"
|
||||
" vec4 localcoord = quatRotate3( position.xyz*instance_scale,q);\n"
|
||||
" vec4 vertexPos = ProjectionMatrix * ModelViewMatrix *(instance_position+localcoord);\n"
|
||||
" gl_Position = vertexPos;\n"
|
||||
" \n"
|
||||
" fragment.color = instance_color;\n"
|
||||
" vert.texcoord = uvcoords;\n"
|
||||
"}\n"
|
||||
;
|
||||
10
examples/OpenGLWindow/Shaders/linesPS.glsl
Normal file
10
examples/OpenGLWindow/Shaders/linesPS.glsl
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
#version 150
|
||||
|
||||
in vec4 colourV;
|
||||
out vec4 fragColour;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
fragColour = colourV;
|
||||
}
|
||||
10
examples/OpenGLWindow/Shaders/linesPS.h
Normal file
10
examples/OpenGLWindow/Shaders/linesPS.h
Normal file
@@ -0,0 +1,10 @@
|
||||
//this file is autogenerated using stringify.bat (premake --stringify) in the build folder of this project
|
||||
static const char* linesFragmentShader= \
|
||||
"#version 150\n"
|
||||
"in vec4 colourV;\n"
|
||||
"out vec4 fragColour;\n"
|
||||
"void main(void)\n"
|
||||
"{\n"
|
||||
" fragColour = colourV;\n"
|
||||
"}\n"
|
||||
;
|
||||
17
examples/OpenGLWindow/Shaders/linesVS.glsl
Normal file
17
examples/OpenGLWindow/Shaders/linesVS.glsl
Normal file
@@ -0,0 +1,17 @@
|
||||
#version 150
|
||||
|
||||
uniform mat4 ModelViewMatrix;
|
||||
uniform mat4 ProjectionMatrix;
|
||||
uniform vec4 colour;
|
||||
|
||||
in vec4 position;
|
||||
|
||||
|
||||
out vec4 colourV;
|
||||
|
||||
void main (void)
|
||||
{
|
||||
colourV = colour;
|
||||
gl_Position = ProjectionMatrix * ModelViewMatrix * position;
|
||||
|
||||
}
|
||||
15
examples/OpenGLWindow/Shaders/linesVS.h
Normal file
15
examples/OpenGLWindow/Shaders/linesVS.h
Normal file
@@ -0,0 +1,15 @@
|
||||
//this file is autogenerated using stringify.bat (premake --stringify) in the build folder of this project
|
||||
static const char* linesVertexShader= \
|
||||
"#version 150 \n"
|
||||
"uniform mat4 ModelViewMatrix;\n"
|
||||
"uniform mat4 ProjectionMatrix;\n"
|
||||
"uniform vec4 colour;\n"
|
||||
"in vec4 position;\n"
|
||||
"out vec4 colourV;\n"
|
||||
"void main (void)\n"
|
||||
"{\n"
|
||||
" colourV = colour;\n"
|
||||
" gl_Position = ProjectionMatrix * ModelViewMatrix * position;\n"
|
||||
" \n"
|
||||
"}\n"
|
||||
;
|
||||
37
examples/OpenGLWindow/Shaders/pointSpritePS.glsl
Normal file
37
examples/OpenGLWindow/Shaders/pointSpritePS.glsl
Normal file
@@ -0,0 +1,37 @@
|
||||
|
||||
#version 330
|
||||
precision highp float;
|
||||
|
||||
in Fragment
|
||||
{
|
||||
vec4 color;
|
||||
} fragment;
|
||||
|
||||
|
||||
in vec3 ambient;
|
||||
|
||||
out vec4 color;
|
||||
|
||||
void main_textured(void)
|
||||
{
|
||||
color = fragment.color;//texture2D(Diffuse,vert.texcoord);//fragment.color;
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
vec3 N;
|
||||
N.xy = gl_PointCoord.st*vec2(2.0, -2.0) + vec2(-1.0, 1.0);
|
||||
float mag = dot(N.xy, N.xy);
|
||||
if (mag > 1.0) discard;
|
||||
vec4 texel = fragment.color;//vec4(1,0,0,1);//fragment.color*texture(Diffuse,vert.texcoord);//fragment.color;
|
||||
vec3 ct;
|
||||
float at,af;
|
||||
af = 1.0;
|
||||
|
||||
ct = texel.rgb;
|
||||
at = texel.a;
|
||||
|
||||
vec3 lightDir= vec3(1,0,0);
|
||||
float diffuse = max(0.0, dot(lightDir, N));
|
||||
color = vec4(ct * diffuse, at * af);
|
||||
}
|
||||
33
examples/OpenGLWindow/Shaders/pointSpritePS.h
Normal file
33
examples/OpenGLWindow/Shaders/pointSpritePS.h
Normal file
@@ -0,0 +1,33 @@
|
||||
//this file is autogenerated using stringify.bat (premake --stringify) in the build folder of this project
|
||||
static const char* pointSpriteFragmentShader= \
|
||||
"#version 330\n"
|
||||
"precision highp float;\n"
|
||||
"in Fragment\n"
|
||||
"{\n"
|
||||
" vec4 color;\n"
|
||||
"} fragment;\n"
|
||||
"in vec3 ambient;\n"
|
||||
"out vec4 color;\n"
|
||||
"void main_textured(void)\n"
|
||||
"{\n"
|
||||
" color = fragment.color;//texture2D(Diffuse,vert.texcoord);//fragment.color;\n"
|
||||
"}\n"
|
||||
"void main(void)\n"
|
||||
"{\n"
|
||||
" vec3 N;\n"
|
||||
" N.xy = gl_PointCoord.st*vec2(2.0, -2.0) + vec2(-1.0, 1.0);\n"
|
||||
" float mag = dot(N.xy, N.xy);\n"
|
||||
" if (mag > 1.0) discard; \n"
|
||||
" vec4 texel = fragment.color;//vec4(1,0,0,1);//fragment.color*texture(Diffuse,vert.texcoord);//fragment.color;\n"
|
||||
" vec3 ct;\n"
|
||||
" float at,af;\n"
|
||||
" af = 1.0;\n"
|
||||
" \n"
|
||||
" ct = texel.rgb;\n"
|
||||
" at = texel.a;\n"
|
||||
" \n"
|
||||
" vec3 lightDir= vec3(1,0,0);\n"
|
||||
" float diffuse = max(0.0, dot(lightDir, N));\n"
|
||||
" color = vec4(ct * diffuse, at * af); \n"
|
||||
"}\n"
|
||||
;
|
||||
46
examples/OpenGLWindow/Shaders/pointSpriteVS.glsl
Normal file
46
examples/OpenGLWindow/Shaders/pointSpriteVS.glsl
Normal file
@@ -0,0 +1,46 @@
|
||||
#version 330
|
||||
precision highp float;
|
||||
|
||||
|
||||
|
||||
layout (location = 0) in vec4 position;
|
||||
layout (location = 1) in vec4 instance_position;
|
||||
layout (location = 3) in vec2 uvcoords;
|
||||
layout (location = 4) in vec3 vertexnormal;
|
||||
layout (location = 5) in vec4 instance_color;
|
||||
layout (location = 6) in vec3 instance_scale;
|
||||
|
||||
|
||||
uniform float screenWidth = 700.f;
|
||||
uniform mat4 ModelViewMatrix;
|
||||
uniform mat4 ProjectionMatrix;
|
||||
|
||||
out Fragment
|
||||
{
|
||||
vec4 color;
|
||||
} fragment;
|
||||
|
||||
|
||||
|
||||
//
|
||||
// vector rotation via quaternion
|
||||
//
|
||||
|
||||
out vec3 ambient;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
ambient = vec3(0.3,.3,0.3);
|
||||
|
||||
|
||||
vec4 axis = vec4(1,1,1,0);
|
||||
vec4 vertexPos = ProjectionMatrix * ModelViewMatrix *(instance_position);
|
||||
vec3 posEye = vec3(ModelViewMatrix * vec4(instance_position.xyz, 1.0));
|
||||
float dist = length(posEye);
|
||||
float pointRadius = 1.f;
|
||||
gl_PointSize = instance_scale.x * pointRadius * (screenWidth / dist);
|
||||
|
||||
gl_Position = vertexPos;
|
||||
|
||||
fragment.color = instance_color;
|
||||
}
|
||||
37
examples/OpenGLWindow/Shaders/pointSpriteVS.h
Normal file
37
examples/OpenGLWindow/Shaders/pointSpriteVS.h
Normal file
@@ -0,0 +1,37 @@
|
||||
//this file is autogenerated using stringify.bat (premake --stringify) in the build folder of this project
|
||||
static const char* pointSpriteVertexShader= \
|
||||
"#version 330\n"
|
||||
"precision highp float;\n"
|
||||
"layout (location = 0) in vec4 position;\n"
|
||||
"layout (location = 1) in vec4 instance_position;\n"
|
||||
"layout (location = 3) in vec2 uvcoords;\n"
|
||||
"layout (location = 4) in vec3 vertexnormal;\n"
|
||||
"layout (location = 5) in vec4 instance_color;\n"
|
||||
"layout (location = 6) in vec3 instance_scale;\n"
|
||||
"uniform float screenWidth = 700.f;\n"
|
||||
"uniform mat4 ModelViewMatrix;\n"
|
||||
"uniform mat4 ProjectionMatrix;\n"
|
||||
"out Fragment\n"
|
||||
"{\n"
|
||||
" vec4 color;\n"
|
||||
"} fragment;\n"
|
||||
"//\n"
|
||||
"// vector rotation via quaternion\n"
|
||||
"//\n"
|
||||
"out vec3 ambient;\n"
|
||||
"void main(void)\n"
|
||||
"{\n"
|
||||
" ambient = vec3(0.3,.3,0.3);\n"
|
||||
" \n"
|
||||
" \n"
|
||||
" vec4 axis = vec4(1,1,1,0);\n"
|
||||
" vec4 vertexPos = ProjectionMatrix * ModelViewMatrix *(instance_position);\n"
|
||||
" vec3 posEye = vec3(ModelViewMatrix * vec4(instance_position.xyz, 1.0));\n"
|
||||
" float dist = length(posEye);\n"
|
||||
" float pointRadius = 1.f;\n"
|
||||
" gl_PointSize = instance_scale.x * pointRadius * (screenWidth / dist);\n"
|
||||
" gl_Position = vertexPos;\n"
|
||||
" \n"
|
||||
" fragment.color = instance_color;\n"
|
||||
"}\n"
|
||||
;
|
||||
56
examples/OpenGLWindow/Shaders/useShadowMapInstancingPS.glsl
Normal file
56
examples/OpenGLWindow/Shaders/useShadowMapInstancingPS.glsl
Normal file
@@ -0,0 +1,56 @@
|
||||
#version 330 core
|
||||
//precision highp float;
|
||||
|
||||
in Fragment
|
||||
{
|
||||
vec4 color;
|
||||
} fragment;
|
||||
|
||||
in Vert
|
||||
{
|
||||
vec2 texcoord;
|
||||
} vert;
|
||||
|
||||
uniform sampler2D Diffuse;
|
||||
uniform sampler2DShadow shadowMap;
|
||||
|
||||
in vec3 lightDir,normal,ambient;
|
||||
in vec4 ShadowCoord;
|
||||
|
||||
out vec4 color;
|
||||
|
||||
|
||||
|
||||
void main(void)
|
||||
{
|
||||
vec4 texel = fragment.color*texture(Diffuse,vert.texcoord);//fragment.color;
|
||||
vec3 ct,cf;
|
||||
float intensity,at,af;
|
||||
|
||||
intensity = clamp( dot( normalize(normal),lightDir ), 0,1 );
|
||||
|
||||
cf = ambient;
|
||||
af = 1.0;
|
||||
|
||||
ct = texel.rgb;
|
||||
at = texel.a;
|
||||
|
||||
//float bias = 0.005f;
|
||||
|
||||
float bias = 0.0001*tan(acos(intensity));
|
||||
bias = clamp(bias, 0,0.01);
|
||||
|
||||
|
||||
float visibility = texture(shadowMap, vec3(ShadowCoord.xy,(ShadowCoord.z-bias)/ShadowCoord.w));
|
||||
|
||||
intensity*=2;
|
||||
if (intensity>1)
|
||||
intensity=1.f;
|
||||
|
||||
visibility *= intensity;
|
||||
|
||||
if (visibility<0.6)
|
||||
visibility=0.6f;
|
||||
|
||||
color = vec4(ct * visibility, fragment.color.w);
|
||||
}
|
||||
49
examples/OpenGLWindow/Shaders/useShadowMapInstancingPS.h
Normal file
49
examples/OpenGLWindow/Shaders/useShadowMapInstancingPS.h
Normal file
@@ -0,0 +1,49 @@
|
||||
//this file is autogenerated using stringify.bat (premake --stringify) in the build folder of this project
|
||||
static const char* useShadowMapInstancingFragmentShader= \
|
||||
"#version 330 core\n"
|
||||
"//precision highp float;\n"
|
||||
"in Fragment\n"
|
||||
"{\n"
|
||||
" vec4 color;\n"
|
||||
"} fragment;\n"
|
||||
"in Vert\n"
|
||||
"{\n"
|
||||
" vec2 texcoord;\n"
|
||||
"} vert;\n"
|
||||
"uniform sampler2D Diffuse;\n"
|
||||
"uniform sampler2DShadow shadowMap;\n"
|
||||
"in vec3 lightDir,normal,ambient;\n"
|
||||
"in vec4 ShadowCoord;\n"
|
||||
"out vec4 color;\n"
|
||||
"void main(void)\n"
|
||||
"{\n"
|
||||
" vec4 texel = fragment.color*texture(Diffuse,vert.texcoord);//fragment.color;\n"
|
||||
" vec3 ct,cf;\n"
|
||||
" float intensity,at,af;\n"
|
||||
" \n"
|
||||
" intensity = clamp( dot( normalize(normal),lightDir ), 0,1 );\n"
|
||||
" \n"
|
||||
" cf = ambient;\n"
|
||||
" af = 1.0;\n"
|
||||
" \n"
|
||||
" ct = texel.rgb;\n"
|
||||
" at = texel.a;\n"
|
||||
" \n"
|
||||
" //float bias = 0.005f;\n"
|
||||
" \n"
|
||||
" float bias = 0.0001*tan(acos(intensity));\n"
|
||||
" bias = clamp(bias, 0,0.01);\n"
|
||||
" float visibility = texture(shadowMap, vec3(ShadowCoord.xy,(ShadowCoord.z-bias)/ShadowCoord.w));\n"
|
||||
" \n"
|
||||
" intensity*=2;\n"
|
||||
" if (intensity>1)\n"
|
||||
" intensity=1.f;\n"
|
||||
" \n"
|
||||
" visibility *= intensity;\n"
|
||||
" \n"
|
||||
" if (visibility<0.6)\n"
|
||||
" visibility=0.6f;\n"
|
||||
" \n"
|
||||
" color = vec4(ct * visibility, fragment.color.w);\n"
|
||||
"}\n"
|
||||
;
|
||||
86
examples/OpenGLWindow/Shaders/useShadowMapInstancingVS.glsl
Normal file
86
examples/OpenGLWindow/Shaders/useShadowMapInstancingVS.glsl
Normal file
@@ -0,0 +1,86 @@
|
||||
#version 330
|
||||
precision highp float;
|
||||
|
||||
|
||||
layout (location = 0) in vec4 position;
|
||||
layout (location = 1) in vec4 instance_position;
|
||||
layout (location = 2) in vec4 instance_quaternion;
|
||||
layout (location = 3) in vec2 uvcoords;
|
||||
layout (location = 4) in vec3 vertexnormal;
|
||||
layout (location = 5) in vec4 instance_color;
|
||||
layout (location = 6) in vec3 instance_scale;
|
||||
|
||||
|
||||
uniform mat4 ModelViewMatrix;
|
||||
uniform mat4 ProjectionMatrix;
|
||||
uniform mat4 DepthBiasModelViewProjectionMatrix;
|
||||
uniform mat4 MVP;
|
||||
uniform vec3 lightDirIn;
|
||||
|
||||
out vec4 ShadowCoord;
|
||||
|
||||
out Fragment
|
||||
{
|
||||
vec4 color;
|
||||
} fragment;
|
||||
|
||||
out Vert
|
||||
{
|
||||
vec2 texcoord;
|
||||
} vert;
|
||||
|
||||
|
||||
vec4 quatMul ( in vec4 q1, in vec4 q2 )
|
||||
{
|
||||
vec3 im = q1.w * q2.xyz + q1.xyz * q2.w + cross ( q1.xyz, q2.xyz );
|
||||
vec4 dt = q1 * q2;
|
||||
float re = dot ( dt, vec4 ( -1.0, -1.0, -1.0, 1.0 ) );
|
||||
return vec4 ( im, re );
|
||||
}
|
||||
|
||||
vec4 quatFromAxisAngle(vec4 axis, in float angle)
|
||||
{
|
||||
float cah = cos(angle*0.5);
|
||||
float sah = sin(angle*0.5);
|
||||
float d = inversesqrt(dot(axis,axis));
|
||||
vec4 q = vec4(axis.x*sah*d,axis.y*sah*d,axis.z*sah*d,cah);
|
||||
return q;
|
||||
}
|
||||
//
|
||||
// vector rotation via quaternion
|
||||
//
|
||||
vec4 quatRotate3 ( in vec3 p, in vec4 q )
|
||||
{
|
||||
vec4 temp = quatMul ( q, vec4 ( p, 0.0 ) );
|
||||
return quatMul ( temp, vec4 ( -q.x, -q.y, -q.z, q.w ) );
|
||||
}
|
||||
vec4 quatRotate ( in vec4 p, in vec4 q )
|
||||
{
|
||||
vec4 temp = quatMul ( q, p );
|
||||
return quatMul ( temp, vec4 ( -q.x, -q.y, -q.z, q.w ) );
|
||||
}
|
||||
|
||||
out vec3 lightDir,normal,ambient;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
vec4 q = instance_quaternion;
|
||||
ambient = vec3(0.3,.3,0.3);
|
||||
|
||||
vec4 worldNormal = (quatRotate3( vertexnormal,q));
|
||||
|
||||
normal = normalize(worldNormal).xyz;
|
||||
|
||||
lightDir = lightDirIn;
|
||||
|
||||
vec4 axis = vec4(1,1,1,0);
|
||||
vec4 localcoord = quatRotate3( position.xyz*instance_scale,q);
|
||||
vec4 vertexPos = MVP* vec4((instance_position+localcoord).xyz,1);
|
||||
|
||||
gl_Position = vertexPos;
|
||||
ShadowCoord = DepthBiasModelViewProjectionMatrix * vec4((instance_position+localcoord).xyz,1);
|
||||
|
||||
fragment.color = instance_color;
|
||||
vert.texcoord = uvcoords;
|
||||
}
|
||||
|
||||
73
examples/OpenGLWindow/Shaders/useShadowMapInstancingVS.h
Normal file
73
examples/OpenGLWindow/Shaders/useShadowMapInstancingVS.h
Normal file
@@ -0,0 +1,73 @@
|
||||
//this file is autogenerated using stringify.bat (premake --stringify) in the build folder of this project
|
||||
static const char* useShadowMapInstancingVertexShader= \
|
||||
"#version 330 \n"
|
||||
"precision highp float;\n"
|
||||
"layout (location = 0) in vec4 position;\n"
|
||||
"layout (location = 1) in vec4 instance_position;\n"
|
||||
"layout (location = 2) in vec4 instance_quaternion;\n"
|
||||
"layout (location = 3) in vec2 uvcoords;\n"
|
||||
"layout (location = 4) in vec3 vertexnormal;\n"
|
||||
"layout (location = 5) in vec4 instance_color;\n"
|
||||
"layout (location = 6) in vec3 instance_scale;\n"
|
||||
"uniform mat4 ModelViewMatrix;\n"
|
||||
"uniform mat4 ProjectionMatrix;\n"
|
||||
"uniform mat4 DepthBiasModelViewProjectionMatrix;\n"
|
||||
"uniform mat4 MVP;\n"
|
||||
"uniform vec3 lightDirIn;\n"
|
||||
"out vec4 ShadowCoord;\n"
|
||||
"out Fragment\n"
|
||||
"{\n"
|
||||
" vec4 color;\n"
|
||||
"} fragment;\n"
|
||||
"out Vert\n"
|
||||
"{\n"
|
||||
" vec2 texcoord;\n"
|
||||
"} vert;\n"
|
||||
"vec4 quatMul ( in vec4 q1, in vec4 q2 )\n"
|
||||
"{\n"
|
||||
" vec3 im = q1.w * q2.xyz + q1.xyz * q2.w + cross ( q1.xyz, q2.xyz );\n"
|
||||
" vec4 dt = q1 * q2;\n"
|
||||
" float re = dot ( dt, vec4 ( -1.0, -1.0, -1.0, 1.0 ) );\n"
|
||||
" return vec4 ( im, re );\n"
|
||||
"}\n"
|
||||
"vec4 quatFromAxisAngle(vec4 axis, in float angle)\n"
|
||||
"{\n"
|
||||
" float cah = cos(angle*0.5);\n"
|
||||
" float sah = sin(angle*0.5);\n"
|
||||
" float d = inversesqrt(dot(axis,axis));\n"
|
||||
" vec4 q = vec4(axis.x*sah*d,axis.y*sah*d,axis.z*sah*d,cah);\n"
|
||||
" return q;\n"
|
||||
"}\n"
|
||||
"//\n"
|
||||
"// vector rotation via quaternion\n"
|
||||
"//\n"
|
||||
"vec4 quatRotate3 ( in vec3 p, in vec4 q )\n"
|
||||
"{\n"
|
||||
" vec4 temp = quatMul ( q, vec4 ( p, 0.0 ) );\n"
|
||||
" return quatMul ( temp, vec4 ( -q.x, -q.y, -q.z, q.w ) );\n"
|
||||
"}\n"
|
||||
"vec4 quatRotate ( in vec4 p, in vec4 q )\n"
|
||||
"{\n"
|
||||
" vec4 temp = quatMul ( q, p );\n"
|
||||
" return quatMul ( temp, vec4 ( -q.x, -q.y, -q.z, q.w ) );\n"
|
||||
"}\n"
|
||||
"out vec3 lightDir,normal,ambient;\n"
|
||||
"void main(void)\n"
|
||||
"{\n"
|
||||
" vec4 q = instance_quaternion;\n"
|
||||
" ambient = vec3(0.3,.3,0.3);\n"
|
||||
" \n"
|
||||
" vec4 worldNormal = (quatRotate3( vertexnormal,q));\n"
|
||||
" \n"
|
||||
" normal = normalize(worldNormal).xyz;\n"
|
||||
" lightDir = lightDirIn;\n"
|
||||
" \n"
|
||||
" vec4 axis = vec4(1,1,1,0);\n"
|
||||
" vec4 localcoord = quatRotate3( position.xyz*instance_scale,q);\n"
|
||||
" vec4 vertexPos = MVP* vec4((instance_position+localcoord).xyz,1);\n"
|
||||
" gl_Position = vertexPos;\n"
|
||||
" ShadowCoord = DepthBiasModelViewProjectionMatrix * vec4((instance_position+localcoord).xyz,1);\n"
|
||||
" fragment.color = instance_color;\n"
|
||||
" vert.texcoord = uvcoords;\n"
|
||||
"}\n"
|
||||
;
|
||||
Reference in New Issue
Block a user