move shaders to .glsl files and stringify to .h file.
add crude screenshot facility (using F1 key), it can also be used for debugging start with shadows using shadowmap, not working yet add experimental 'ignore' body index in raycast, using b3HitInfo.m_m_hitResult2
This commit is contained in:
10
btgui/OpenGLWindow/Shaders/createShadowMapInstancingPS.glsl
Normal file
10
btgui/OpenGLWindow/Shaders/createShadowMapInstancingPS.glsl
Normal file
@@ -0,0 +1,10 @@
|
||||
#version 330
|
||||
precision highp float;
|
||||
|
||||
|
||||
layout(location = 0) out float fragmentdepth;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
fragmentdepth = gl_FragCoord.z;
|
||||
}
|
||||
14
btgui/OpenGLWindow/Shaders/createShadowMapInstancingPS.h
Normal file
14
btgui/OpenGLWindow/Shaders/createShadowMapInstancingPS.h
Normal file
@@ -0,0 +1,14 @@
|
||||
//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"
|
||||
"\n"
|
||||
"\n"
|
||||
"layout(location = 0) out float fragmentdepth;\n"
|
||||
"\n"
|
||||
"void main(void)\n"
|
||||
"{\n"
|
||||
" fragmentdepth = gl_FragCoord.z;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
;
|
||||
60
btgui/OpenGLWindow/Shaders/createShadowMapInstancingVS.h
Normal file
60
btgui/OpenGLWindow/Shaders/createShadowMapInstancingVS.h
Normal file
@@ -0,0 +1,60 @@
|
||||
//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"
|
||||
"\n"
|
||||
"\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"
|
||||
"\n"
|
||||
"\n"
|
||||
"uniform mat4 ModelViewMatrix;\n"
|
||||
"uniform mat4 ProjectionMatrix;\n"
|
||||
"\n"
|
||||
"\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"
|
||||
"\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"
|
||||
"\n"
|
||||
"\n"
|
||||
"void main(void)\n"
|
||||
"{\n"
|
||||
" vec4 q = instance_quaternion;\n"
|
||||
" vec4 localcoord = quatRotate3( position.xyz*instance_scale,q);\n"
|
||||
" vec4 vertexPos = ProjectionMatrix * ModelViewMatrix * vec4( (instance_position+localcoord).xyz,1);\n"
|
||||
" gl_Position = vertexPos;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"\n"
|
||||
;
|
||||
56
btgui/OpenGLWindow/Shaders/createshadowMapInstancingVS.glsl
Normal file
56
btgui/OpenGLWindow/Shaders/createshadowMapInstancingVS.glsl
Normal file
@@ -0,0 +1,56 @@
|
||||
#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;
|
||||
|
||||
|
||||
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 = ProjectionMatrix * ModelViewMatrix * vec4( (instance_position+localcoord).xyz,1);
|
||||
gl_Position = vertexPos;
|
||||
}
|
||||
|
||||
36
btgui/OpenGLWindow/Shaders/instancingPS.glsl
Normal file
36
btgui/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);
|
||||
}
|
||||
40
btgui/OpenGLWindow/Shaders/instancingPS.h
Normal file
40
btgui/OpenGLWindow/Shaders/instancingPS.h
Normal file
@@ -0,0 +1,40 @@
|
||||
//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"
|
||||
"\n"
|
||||
"in Fragment\n"
|
||||
"{\n"
|
||||
" vec4 color;\n"
|
||||
"} fragment;\n"
|
||||
"\n"
|
||||
"in Vert\n"
|
||||
"{\n"
|
||||
" vec2 texcoord;\n"
|
||||
"} vert;\n"
|
||||
"\n"
|
||||
"uniform sampler2D Diffuse;\n"
|
||||
"in vec3 lightDir,normal,ambient;\n"
|
||||
"out vec4 color;\n"
|
||||
"\n"
|
||||
"void main_textured(void)\n"
|
||||
"{\n"
|
||||
" color = vec4(0.1,0.2,0.3,0.3);\n"
|
||||
"}\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"
|
||||
"\n"
|
||||
;
|
||||
82
btgui/OpenGLWindow/Shaders/instancingVS.glsl
Normal file
82
btgui/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;
|
||||
}
|
||||
|
||||
86
btgui/OpenGLWindow/Shaders/instancingVS.h
Normal file
86
btgui/OpenGLWindow/Shaders/instancingVS.h
Normal file
@@ -0,0 +1,86 @@
|
||||
//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"
|
||||
"\n"
|
||||
"\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"
|
||||
"\n"
|
||||
"\n"
|
||||
"uniform mat4 ModelViewMatrix;\n"
|
||||
"uniform mat4 ProjectionMatrix;\n"
|
||||
"\n"
|
||||
"out Fragment\n"
|
||||
"{\n"
|
||||
" vec4 color;\n"
|
||||
"} fragment;\n"
|
||||
"\n"
|
||||
"out Vert\n"
|
||||
"{\n"
|
||||
" vec2 texcoord;\n"
|
||||
"} vert;\n"
|
||||
"\n"
|
||||
"\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"
|
||||
"\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"
|
||||
"\n"
|
||||
"out vec3 lightDir,normal,ambient;\n"
|
||||
"\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"
|
||||
"\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"
|
||||
"\n"
|
||||
" gl_Position = vertexPos;\n"
|
||||
" \n"
|
||||
" fragment.color = instance_color;\n"
|
||||
" vert.texcoord = uvcoords;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"\n"
|
||||
;
|
||||
37
btgui/OpenGLWindow/Shaders/pointSpritePS.glsl
Normal file
37
btgui/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 = 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);
|
||||
}
|
||||
41
btgui/OpenGLWindow/Shaders/pointSpritePS.h
Normal file
41
btgui/OpenGLWindow/Shaders/pointSpritePS.h
Normal file
@@ -0,0 +1,41 @@
|
||||
//this file is autogenerated using stringify.bat (premake --stringify) in the build folder of this project
|
||||
static const char* pointSpriteFragmentShader= \
|
||||
"\n"
|
||||
"#version 330\n"
|
||||
"precision highp float;\n"
|
||||
"\n"
|
||||
"in Fragment\n"
|
||||
"{\n"
|
||||
" vec4 color;\n"
|
||||
"} fragment;\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"in vec3 ambient;\n"
|
||||
"\n"
|
||||
"out vec4 color;\n"
|
||||
"\n"
|
||||
"void main_textured(void)\n"
|
||||
"{\n"
|
||||
" color = fragment.color;//texture2D(Diffuse,vert.texcoord);//fragment.color;\n"
|
||||
"}\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 = 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"
|
||||
"\n"
|
||||
;
|
||||
46
btgui/OpenGLWindow/Shaders/pointSpriteVS.glsl
Normal file
46
btgui/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;
|
||||
}
|
||||
50
btgui/OpenGLWindow/Shaders/pointSpriteVS.h
Normal file
50
btgui/OpenGLWindow/Shaders/pointSpriteVS.h
Normal file
@@ -0,0 +1,50 @@
|
||||
//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"
|
||||
"\n"
|
||||
"\n"
|
||||
"\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"
|
||||
"\n"
|
||||
"\n"
|
||||
"uniform float screenWidth = 700.f;\n"
|
||||
"uniform mat4 ModelViewMatrix;\n"
|
||||
"uniform mat4 ProjectionMatrix;\n"
|
||||
"\n"
|
||||
"out Fragment\n"
|
||||
"{\n"
|
||||
" vec4 color;\n"
|
||||
"} fragment;\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"//\n"
|
||||
"// vector rotation via quaternion\n"
|
||||
"//\n"
|
||||
"\n"
|
||||
"out vec3 ambient;\n"
|
||||
"\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"
|
||||
"\n"
|
||||
" gl_Position = vertexPos;\n"
|
||||
" \n"
|
||||
" fragment.color = instance_color;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
;
|
||||
40
btgui/OpenGLWindow/Shaders/useShadowMapInstancingPS.glsl
Normal file
40
btgui/OpenGLWindow/Shaders/useShadowMapInstancingPS.glsl
Normal file
@@ -0,0 +1,40 @@
|
||||
#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 = 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;
|
||||
|
||||
float bias = 0.005f;
|
||||
float visibility = texture(shadowMap, vec3(ShadowCoord.xy,(ShadowCoord.z-bias)/ShadowCoord.w));
|
||||
|
||||
color = vec4(ct * cf * visibility, at * af);
|
||||
}
|
||||
44
btgui/OpenGLWindow/Shaders/useShadowMapInstancingPS.h
Normal file
44
btgui/OpenGLWindow/Shaders/useShadowMapInstancingPS.h
Normal file
@@ -0,0 +1,44 @@
|
||||
//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"
|
||||
"\n"
|
||||
"in Fragment\n"
|
||||
"{\n"
|
||||
" vec4 color;\n"
|
||||
"} fragment;\n"
|
||||
"\n"
|
||||
"in Vert\n"
|
||||
"{\n"
|
||||
" vec2 texcoord;\n"
|
||||
"} vert;\n"
|
||||
"\n"
|
||||
"uniform sampler2D Diffuse;\n"
|
||||
"uniform sampler2DShadow shadowMap;\n"
|
||||
"\n"
|
||||
"in vec3 lightDir,normal,ambient;\n"
|
||||
"in vec4 ShadowCoord;\n"
|
||||
"\n"
|
||||
"out vec4 color;\n"
|
||||
"\n"
|
||||
"\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"
|
||||
" float bias = 0.005f;\n"
|
||||
" float visibility = texture(shadowMap, vec3(ShadowCoord.xy,(ShadowCoord.z-bias)/ShadowCoord.w));\n"
|
||||
" \n"
|
||||
" color = vec4(ct * cf * visibility, at * af); \n"
|
||||
"}\n"
|
||||
"\n"
|
||||
;
|
||||
86
btgui/OpenGLWindow/Shaders/useShadowMapInstancingVS.glsl
Normal file
86
btgui/OpenGLWindow/Shaders/useShadowMapInstancingVS.glsl
Normal file
@@ -0,0 +1,86 @@
|
||||
#version 330 core
|
||||
//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;
|
||||
|
||||
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 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 * vec4((instance_position+localcoord).xyz,1);
|
||||
|
||||
gl_Position = vertexPos;
|
||||
ShadowCoord = DepthBiasModelViewProjectionMatrix * vec4((instance_position+localcoord).xyz,1);
|
||||
|
||||
fragment.color = instance_color;
|
||||
vert.texcoord = uvcoords;
|
||||
}
|
||||
|
||||
90
btgui/OpenGLWindow/Shaders/useShadowMapInstancingVS.h
Normal file
90
btgui/OpenGLWindow/Shaders/useShadowMapInstancingVS.h
Normal file
@@ -0,0 +1,90 @@
|
||||
//this file is autogenerated using stringify.bat (premake --stringify) in the build folder of this project
|
||||
static const char* useShadowMapInstancingVertexShader= \
|
||||
"#version 330 core\n"
|
||||
"//precision highp float;\n"
|
||||
"\n"
|
||||
"\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"
|
||||
"\n"
|
||||
"\n"
|
||||
"uniform mat4 ModelViewMatrix;\n"
|
||||
"uniform mat4 ProjectionMatrix;\n"
|
||||
"uniform mat4 DepthBiasModelViewProjectionMatrix;\n"
|
||||
"\n"
|
||||
"out vec4 ShadowCoord;\n"
|
||||
"\n"
|
||||
"out Fragment\n"
|
||||
"{\n"
|
||||
" vec4 color;\n"
|
||||
"} fragment;\n"
|
||||
"\n"
|
||||
"out Vert\n"
|
||||
"{\n"
|
||||
" vec2 texcoord;\n"
|
||||
"} vert;\n"
|
||||
"\n"
|
||||
"\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"
|
||||
"\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"
|
||||
"\n"
|
||||
"out vec3 lightDir,normal,ambient;\n"
|
||||
"\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"
|
||||
"\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 * vec4((instance_position+localcoord).xyz,1);\n"
|
||||
"\n"
|
||||
" gl_Position = vertexPos;\n"
|
||||
" ShadowCoord = DepthBiasModelViewProjectionMatrix * vec4((instance_position+localcoord).xyz,1);\n"
|
||||
"\n"
|
||||
" fragment.color = instance_color;\n"
|
||||
" vert.texcoord = uvcoords;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"\n"
|
||||
;
|
||||
Reference in New Issue
Block a user