Commit 9b1b9e57 authored by Sylvain Thery's avatar Sylvain Thery
Browse files

Shader dans fichier separe mais compile dans le .o

Ajout executable Tools/shader_to_h
Modification de la compilation de utils pour generer
les fichiers a inclure  a la compilation
parent 7764757b
// ShaderVectorPerVertex::geometryShaderText
uniform float vectorScale;
uniform mat4 ModelViewProjectionMatrix;
VARYING_IN vec3 VectorAttrib[];
void main()
{
gl_Position = ModelViewProjectionMatrix * POSITION_IN(0);
EmitVertex();
gl_Position = ModelViewProjectionMatrix * (POSITION_IN(0) + vec4(VectorAttrib[0] * vectorScale, 0.0));
EmitVertex();
EndPrimitive();
}
// ShaderVectorPerVertex::vertexShaderText
ATTRIBUTE vec3 VertexPosition;
ATTRIBUTE vec3 VertexVector;
VARYING_VERT vec3 VectorAttrib;
INVARIANT_POS;
void main ()
{
VectorAttrib = VertexVector;
gl_Position = vec4(VertexPosition, 1.0);
}
// PointSprite::fragmentShaderText
uniform sampler2D SpriteTexture;
uniform float size;
uniform vec3 color;
VARYING_FRAG vec2 texCoord;
VARYING_FRAG vec2 positionFragIn;
VARYING_FRAG vec4 mvpFragIn;
void main(void)
{
float lum = texture2D(SpriteTexture, texCoord).s;
if (lum==0.0)
discard;
vec2 v = texCoord-vec2(0.5,0.5);
float z = size * sqrt(1.0-dot(v,v));
vec2 zfrag = positionFragIn + vec2(z,0.0);
gl_FragDepth = 0.5 + 0.5 * dot(zfrag, mvpFragIn.xy) / dot(zfrag, mvpFragIn.zw);
gl_FragColor = vec4(color,0.0)*lum;
}
\ No newline at end of file
// PointSprite::geometryShaderText
uniform float size;
uniform mat4 ModelViewMatrix;
uniform mat4 ProjectionMatrix;
VARYING_OUT vec2 texCoord;
VARYING_OUT vec2 positionFragIn;
VARYING_OUT vec4 mvpFragIn;
void main()
{
vec4 posCenter = ModelViewMatrix * POSITION_IN(0);
vec4 pos = posCenter + vec4(-size, size, 0.0, 0.0);
positionFragIn = posCenter.zw;
mvpFragIn.x = ProjectionMatrix[2][2];
mvpFragIn.y = ProjectionMatrix[3][2];
mvpFragIn.z = ProjectionMatrix[2][3];
mvpFragIn.w = ProjectionMatrix[3][3];
texCoord = vec2(0.0,1.0);
gl_Position = ProjectionMatrix * pos;
EmitVertex();
pos = posCenter + vec4(-size, -size, 0.0, 0.0);
texCoord = vec2(0.0,0.0);
gl_Position = ProjectionMatrix * pos;
EmitVertex();
pos = posCenter + vec4( size, size, 0.0, 0.0);
texCoord = vec2(1.0,1.0);
gl_Position = ProjectionMatrix * pos;
EmitVertex();
pos = posCenter + vec4( size,-size, 0.0, 0.0);
texCoord = vec2(1.0,0.0);
gl_Position = ProjectionMatrix * pos;
EmitVertex();
EndPrimitive();
}
// PointSprite::vertexShaderText
ATTRIBUTE vec3 VertexPosition;
void main ()
{
gl_Position = vec4(VertexPosition,1.0);
}
//Strings3D::fragmentShaderText1
VARYING_FRAG vec2 tex_coord;
uniform sampler2D FontTexture;
uniform vec3 color;
FRAG_OUT_DEF;
void main (void)
{
float lum = texture2D(FontTexture, tex_coord).s;;
}
//Strings3D::vertexShaderText
ATTRIBUTE vec4 VertexPosition;
uniform mat4 ModelViewMatrix;
uniform mat4 ProjectionMatrix
uniform vec3 strPos;
uniform float scale;
VARYING_VERT vec2 tex_coord;
INVARIANT_POS;
void main ()
{
vec4 pos = ModelViewMatrix * vec4(strPos,1.0) + vec4(VertexPosition[0]*scale,VertexPosition[1]*scale,0.0,0.0);
tex_coord = vec2(VertexPosition[2],VertexPosition[3]);
gl_Position = ProjectionMatrix * pos;
}
\ No newline at end of file
......@@ -32,27 +32,30 @@ namespace CGoGN
namespace Utils
{
std::string ShaderColorPerVertex::vertexShaderText =
"ATTRIBUTE vec3 VertexPosition;\n"
"ATTRIBUTE vec3 VertexColor;\n"
"uniform mat4 ModelViewProjectionMatrix;\n"
"VARYING_VERT vec3 color;\n"
"INVARIANT_POS;\n"
"void main ()\n"
"{\n"
" gl_Position = ModelViewProjectionMatrix * vec4 (VertexPosition, 1.0);\n"
" color = VertexColor;\n"
"}";
std::string ShaderColorPerVertex::fragmentShaderText =
"PRECISON;\n"
"VARYING_FRAG vec3 color;\n"
"FRAG_OUT_DEF;\n"
"void main()\n"
"{\n"
" gl_FragColor=vec4(color,0.0);\n"
"}";
#include "shaderColorPerVertex.vert"
#include "shaderColorPerVertex.frag"
//std::string ShaderColorPerVertex::vertexShaderText =
// "ATTRIBUTE vec3 VertexPosition;\n"
// "ATTRIBUTE vec3 VertexColor;\n"
// "uniform mat4 ModelViewProjectionMatrix;\n"
// "VARYING_VERT vec3 color;\n"
// "INVARIANT_POS;\n"
// "void main ()\n"
// "{\n"
// " gl_Position = ModelViewProjectionMatrix * vec4 (VertexPosition, 1.0);\n"
// " color = VertexColor;\n"
// "}";
//
//
//std::string ShaderColorPerVertex::fragmentShaderText =
// "PRECISON;\n"
// "VARYING_FRAG vec3 color;\n"
// "FRAG_OUT_DEF;\n"
// "void main()\n"
// "{\n"
// " gl_FragColor=vec4(color,0.0);\n"
// "}";
ShaderColorPerVertex::ShaderColorPerVertex()
......
......@@ -31,54 +31,57 @@ namespace CGoGN
namespace Utils
{
std::string ShaderFlat::vertexShaderText =
"ATTRIBUTE vec3 VertexPosition;\n"
"void main()\n"
"{\n"
" gl_Position = vec4(VertexPosition, 1.0);\n"
"}";
std::string ShaderFlat::geometryShaderText =
"uniform float explode;\n"
"uniform mat4 ModelViewProjectionMatrix;\n"
"uniform mat4 NormalMatrix;\n"
"uniform mat4 ModelViewMatrix;\n"
"uniform vec3 lightPosition;\n"
"uniform vec4 diffuse;\n"
"uniform vec4 ambient;\n"
"VARYING_OUT vec4 ColorFS;\n"
"void main(void)\n"
"{\n"
" vec3 v1 = POSITION_IN(1).xyz - POSITION_IN(0).xyz;\n"
" vec3 v2 = POSITION_IN(2).xyz - POSITION_IN(0).xyz;\n"
" vec3 N = cross(v1,v2);\n"
" N = normalize (vec3(NormalMatrix*vec4(N,0.0))); \n"
" vec3 center = POSITION_IN(0).xyz + POSITION_IN(1).xyz + POSITION_IN(2).xyz; \n"
" center /= 3.0;\n"
" vec4 newPos = ModelViewMatrix * vec4(center,0.0);\n"
" vec3 L = normalize (lightPosition - newPos.xyz);\n"
" float lambertTerm = dot(N,L);\n"
" ColorFS = ambient;\n"
" if(lambertTerm > 0.0)\n"
" ColorFS += diffuse * lambertTerm;\n"
" int i;\n"
" for(i=0; i< NBVERTS_IN; i++)\n"
" {\n"
" vec4 pos = explode * POSITION_IN(i) + (1.0-explode)* vec4(center,1.0);\n"
" gl_Position = ModelViewProjectionMatrix * pos;\n"
" EmitVertex();\n"
" }\n"
" EndPrimitive();\n"
"}";
std::string ShaderFlat::fragmentShaderText =
"VARYING_FRAG vec4 ColorFS; \n"
"void main()\n"
"{\n"
" gl_FragColor = ColorFS;\n"
"}";
#include "shaderFlat.vert"
#include "shaderFlat.frag"
#include "shaderFlat.geom"
//std::string ShaderFlat::vertexShaderText =
//"ATTRIBUTE vec3 VertexPosition;\n"
//"void main()\n"
//"{\n"
//" gl_Position = vec4(VertexPosition, 1.0);\n"
//"}";
//std::string ShaderFlat::geometryShaderText =
//"uniform float explode;\n"
//"uniform mat4 ModelViewProjectionMatrix;\n"
//"uniform mat4 NormalMatrix;\n"
//"uniform mat4 ModelViewMatrix;\n"
//"uniform vec3 lightPosition;\n"
//"uniform vec4 diffuse;\n"
//"uniform vec4 ambient;\n"
//"VARYING_OUT vec4 ColorFS;\n"
//"void main(void)\n"
//"{\n"
//" vec3 v1 = POSITION_IN(1).xyz - POSITION_IN(0).xyz;\n"
//" vec3 v2 = POSITION_IN(2).xyz - POSITION_IN(0).xyz;\n"
//" vec3 N = cross(v1,v2);\n"
//" N = normalize (vec3(NormalMatrix*vec4(N,0.0))); \n"
//" vec3 center = POSITION_IN(0).xyz + POSITION_IN(1).xyz + POSITION_IN(2).xyz; \n"
//" center /= 3.0;\n"
//" vec4 newPos = ModelViewMatrix * vec4(center,0.0);\n"
//" vec3 L = normalize (lightPosition - newPos.xyz);\n"
//" float lambertTerm = dot(N,L);\n"
//" ColorFS = ambient;\n"
//" if(lambertTerm > 0.0)\n"
//" ColorFS += diffuse * lambertTerm;\n"
//" int i;\n"
//" for(i=0; i< NBVERTS_IN; i++)\n"
//" {\n"
//" vec4 pos = explode * POSITION_IN(i) + (1.0-explode)* vec4(center,1.0);\n"
//" gl_Position = ModelViewProjectionMatrix * pos;\n"
//" EmitVertex();\n"
//" }\n"
//" EndPrimitive();\n"
//"}";
//std::string ShaderFlat::fragmentShaderText =
//"VARYING_FRAG vec4 ColorFS; \n"
//"void main()\n"
//"{\n"
//" gl_FragColor = ColorFS;\n"
//"}";
ShaderFlat::ShaderFlat()
......
......@@ -30,66 +30,67 @@ namespace CGoGN
namespace Utils
{
#include "shaderPhong.vert"
#include "shaderPhong.frag"
//std::string ShaderPhong::vertexShaderText =
//"ATTRIBUTE vec3 VertexPosition, VertexNormal;\n"
//"#ifdef WITH_COLOR\n"
//"ATTRIBUTE vec3 VertexColor;\n"
//"#endif\n"
//"uniform mat4 ModelViewProjectionMatrix;\n"
//"uniform mat4 ModelViewMatrix;\n"
//"uniform mat4 NormalMatrix;\n"
//"uniform vec3 lightPosition;\n"
//"VARYING_VERT vec3 EyeVector, Normal, LightDir;\n"
//"#ifdef WITH_COLOR\n"
//"VARYING_VERT vec3 Color;\n"
//"#endif\n"
//"INVARIANT_POS;\n"
//"void main ()\n"
//"{\n"
//" Normal = vec3 (NormalMatrix * vec4 (VertexNormal, 0.0));\n"
//" vec3 Position = vec3 (ModelViewMatrix * vec4 (VertexPosition, 1.0));\n"
//" LightDir = lightPosition - Position;\n"
//" EyeVector = -Position;\n"
//" #ifdef WITH_COLOR\n"
//" Color = VertexColor;\n"
//" #endif\n"
//" gl_Position = ModelViewProjectionMatrix * vec4 (VertexPosition, 1.0);\n"
//"}";
std::string ShaderPhong::vertexShaderText =
"ATTRIBUTE vec3 VertexPosition, VertexNormal;\n"
"#ifdef WITH_COLOR\n"
"ATTRIBUTE vec3 VertexColor;\n"
"#endif\n"
"uniform mat4 ModelViewProjectionMatrix;\n"
"uniform mat4 ModelViewMatrix;\n"
"uniform mat4 NormalMatrix;\n"
"uniform vec3 lightPosition;\n"
"VARYING_VERT vec3 EyeVector, Normal, LightDir;\n"
"#ifdef WITH_COLOR\n"
"VARYING_VERT vec3 Color;\n"
"#endif\n"
"INVARIANT_POS;\n"
"void main ()\n"
"{\n"
" Normal = vec3 (NormalMatrix * vec4 (VertexNormal, 0.0));\n"
" vec3 Position = vec3 (ModelViewMatrix * vec4 (VertexPosition, 1.0));\n"
" LightDir = lightPosition - Position;\n"
" EyeVector = -Position;\n"
" #ifdef WITH_COLOR\n"
" Color = VertexColor;\n"
" #endif\n"
" gl_Position = ModelViewProjectionMatrix * vec4 (VertexPosition, 1.0);\n"
"}";
std::string ShaderPhong::fragmentShaderText =
"PRECISON;\n"
"VARYING_FRAG vec3 EyeVector, Normal, LightDir;\n"
"#ifdef WITH_COLOR\n"
"VARYING_FRAG vec3 Color;\n"
"#endif\n"
"uniform vec4 materialDiffuse;\n"
"uniform vec4 materialSpecular;\n"
"uniform vec4 materialAmbient;\n"
"uniform float shininess;\n"
"FRAG_OUT_DEF;\n"
"void main()\n"
"{\n"
" vec3 N = normalize (Normal);\n"
" vec3 L = normalize (LightDir);\n"
" float lambertTerm = dot(N,L);\n"
" vec4 finalColor = materialAmbient;\n"
" if(lambertTerm > 0.0)\n"
" {\n"
" #ifndef WITH_COLOR\n"
" finalColor += materialDiffuse * lambertTerm;\n"
" #else\n"
" finalColor += vec4((Color*lambertTerm),0.0) ;\n"
" #endif\n"
" vec3 E = normalize(EyeVector);\n"
" vec3 R = reflect(-L, N);\n"
" float specular = pow( max(dot(R, E), 0.0), shininess );\n"
" finalColor += materialSpecular * specular;\n"
" }\n"
" gl_FragColor=finalColor;\n"
"}";
//std::string ShaderPhong::fragmentShaderText =
//"PRECISON;\n"
//"VARYING_FRAG vec3 EyeVector, Normal, LightDir;\n"
//"#ifdef WITH_COLOR\n"
//"VARYING_FRAG vec3 Color;\n"
//"#endif\n"
//"uniform vec4 materialDiffuse;\n"
//"uniform vec4 materialSpecular;\n"
//"uniform vec4 materialAmbient;\n"
//"uniform float shininess;\n"
//"FRAG_OUT_DEF;\n"
//"void main()\n"
//"{\n"
//" vec3 N = normalize (Normal);\n"
//" vec3 L = normalize (LightDir);\n"
//" float lambertTerm = dot(N,L);\n"
//
//" vec4 finalColor = materialAmbient;\n"
//" if(lambertTerm > 0.0)\n"
//" {\n"
//" #ifndef WITH_COLOR\n"
//" finalColor += materialDiffuse * lambertTerm;\n"
//" #else\n"
//" finalColor += vec4((Color*lambertTerm),0.0) ;\n"
//" #endif\n"
//" vec3 E = normalize(EyeVector);\n"
//" vec3 R = reflect(-L, N);\n"
//" float specular = pow( max(dot(R, E), 0.0), shininess );\n"
//" finalColor += materialSpecular * specular;\n"
//" }\n"
//" gl_FragColor=finalColor;\n"
//"}";
ShaderPhong::ShaderPhong():
......
......@@ -30,25 +30,27 @@ namespace CGoGN
namespace Utils
{
std::string ShaderSimpleColor::vertexShaderText =
"ATTRIBUTE vec3 VertexPosition, VertexNormal;\n"
"uniform mat4 ModelViewProjectionMatrix;\n"
// "INVARIANT_POS;\n"
"void main ()\n"
"{\n"
" gl_Position = ModelViewProjectionMatrix * vec4 (VertexPosition, 1.0);\n"
"}";
std::string ShaderSimpleColor::fragmentShaderText =
"PRECISON;\n"
"uniform vec4 color;\n"
"FRAG_OUT_DEF;\n"
"void main()\n"
"{\n"
" gl_FragColor=color;\n"
"}";
#include "shaderSimpleColor.vert"
#include "shaderSimpleColor.frag"
//std::string ShaderSimpleColor::vertexShaderText =
// "ATTRIBUTE vec3 VertexPosition, VertexNormal;\n"
// "uniform mat4 ModelViewProjectionMatrix;\n"
//// "INVARIANT_POS;\n"
// "void main ()\n"
// "{\n"
// " gl_Position = ModelViewProjectionMatrix * vec4 (VertexPosition, 1.0);\n"
// "}";
//
//
//std::string ShaderSimpleColor::fragmentShaderText =
// "PRECISON;\n"
// "uniform vec4 color;\n"
// "FRAG_OUT_DEF;\n"
// "void main()\n"
// "{\n"
// " gl_FragColor=color;\n"
// "}";
ShaderSimpleColor::ShaderSimpleColor()
......
......@@ -31,29 +31,31 @@ namespace CGoGN
namespace Utils
{
std::string ShaderSimpleTexture::vertexShaderText =
"ATTRIBUTE vec3 VertexPosition;\n"
"ATTRIBUTE vec2 VertexTexCoord;\n"
"uniform mat4 ModelViewProjectionMatrix;\n"
"VARYING_VERT vec2 texCoord;\n"
"INVARIANT_POS;\n"
"void main ()\n"
"{\n"
" gl_Position = ModelViewProjectionMatrix * vec4 (VertexPosition, 1.0);\n"
" texCoord = VertexTexCoord;\n"
"}";
std::string ShaderSimpleTexture::fragmentShaderText =
"PRECISON;\n"
"VARYING_FRAG vec2 texCoord;\n"
"uniform sampler2D textureUnit;\n"
"FRAG_OUT_DEF;\n"
"void main()\n"
"{\n"
" gl_FragColor=texture2D(textureUnit,texCoord);\n"
"}";
#include "shaderSimpleTexture.vert"
#include "shaderSimpleTexture.frag"
//std::string ShaderSimpleTexture::vertexShaderText =
// "ATTRIBUTE vec3 VertexPosition;\n"
// "ATTRIBUTE vec2 VertexTexCoord;\n"
// "uniform mat4 ModelViewProjectionMatrix;\n"
// "VARYING_VERT vec2 texCoord;\n"
// "INVARIANT_POS;\n"
// "void main ()\n"
// "{\n"
// " gl_Position = ModelViewProjectionMatrix * vec4 (VertexPosition, 1.0);\n"
// " texCoord = VertexTexCoord;\n"
// "}";
//
//
//std::string ShaderSimpleTexture::fragmentShaderText =
// "PRECISON;\n"
// "VARYING_FRAG vec2 texCoord;\n"
// "uniform sampler2D textureUnit;\n"
// "FRAG_OUT_DEF;\n"
// "void main()\n"
// "{\n"
// " gl_FragColor=texture2D(textureUnit,texCoord);\n"
// "}";
ShaderSimpleTexture::ShaderSimpleTexture()
......
......@@ -32,32 +32,35 @@ namespace CGoGN
namespace Utils
{
std::string ShaderTextureMask::vertexShaderText =
"ATTRIBUTE vec3 VertexPosition;\n"
"ATTRIBUTE vec2 VertexTexCoord;\n"
"uniform mat4 ModelViewProjectionMatrix;\n"
"VARYING_VERT vec2 texCoord;\n"
"INVARIANT_POS;\n"
"void main ()\n"
"{\n"
" gl_Position = ModelViewProjectionMatrix * vec4 (VertexPosition, 1.0);\n"
" texCoord = VertexTexCoord;\n"
"}";
std::string ShaderTextureMask::fragmentShaderText =
"PRECISON;\n"
"VARYING_FRAG vec2 texCoord;\n"
"uniform sampler2D textureUnit;\n"
"uniform sampler2D textureUnitMask;\n"
"FRAG_OUT_DEF;\n"
"void main()\n"
"{\n"
" float m = texture2D(textureUnitMask,texCoord).r;\n"
" if (m < 0.5)"
" discard;"
" gl_FragColor=texture2D(textureUnit,texCoord)*m;\n"
"}";
#include "shaderTextureMask.vert"
#include "shaderTextureMask.frag"
//std::string ShaderTextureMask::vertexShaderText =
// "ATTRIBUTE vec3 VertexPosition;\n"
// "ATTRIBUTE vec2 VertexTexCoord;\n"
// "uniform mat4 ModelViewProjectionMatrix;\n"
// "VARYING_VERT vec2 texCoord;\n"
// "INVARIANT_POS;\n"
// "void main ()\n"
// "{\n"
// " gl_Position = ModelViewProjectionMatrix * vec4 (VertexPosition, 1.0);\n"
// " texCoord = VertexTexCoord;\n"
// "}";
//
//
//std::string ShaderTextureMask::fragmentShaderText =
// "PRECISON;\n"
// "VARYING_FRAG vec2 texCoord;\n"
// "uniform sampler2D textureUnit;\n"
// "uniform sampler2D textureUnitMask;\n"
// "FRAG_OUT_DEF;\n"
// "void main()\n"
// "{\n"
// " float m = texture2D(textureUnitMask,texCoord).r;\n"
// " if (m < 0.5)"
// " discard;"
// " gl_FragColor=texture2D(textureUnit,texCoord)*m;\n"
// "}";
ShaderTextureMask::ShaderTextureMask()
......
......@@ -30,41 +30,44 @@ namespace CGoGN
namespace Utils
{
std::string ShaderVectorPerVertex::vertexShaderText =
"ATTRIBUTE vec3 VertexPosition;\n"
"ATTRIBUTE vec3 VertexVector;\n"
"VARYING_VERT vec3 VectorAttrib;\n"
"INVARIANT_POS;\n"
"void main ()\n"
"{\n"
" VectorAttrib = VertexVector;\n"
" gl_Position = vec4(VertexPosition, 1.0);\n"
"}";
std::string ShaderVectorPerVertex::geometryShaderText =
"uniform float vectorScale;\n"
"uniform mat4 ModelViewProjectionMatrix;\n"
"VARYING_IN vec3 VectorAttrib[];\n"
"void main()\n"
"{\n"
" gl_Position = ModelViewProjectionMatrix * POSITION_IN(0);\n"
" EmitVertex();\n"
" gl_Position = ModelViewProjectionMatrix * (POSITION_IN(0) + vec4(VectorAttrib[0] * vectorScale, 0.0));\n"
" EmitVertex();\n"
" EndPrimitive();\n"
"}";
std::string ShaderVectorPerVertex::fragmentShaderText =
"PRECISON;\n"
"uniform vec4 vectorColor;\n"
"FRAG_OUT_DEF;\n"
"void main()\n"
"{\n"
" gl_FragColor = vectorColor;\n"
"}";
#include "shaderVectorPerVertex.vert"
#include "shaderVectorPerVertex.geom"
#include "shaderVectorPerVertex.frag"
//std::string ShaderVectorPerVertex::vertexShaderText =
// "ATTRIBUTE vec3 VertexPosition;\n"
// "ATTRIBUTE vec3 VertexVector;\n"
// "VARYING_VERT vec3 VectorAttrib;\n"