rename shaders

This commit is contained in:
Paul Leroy
2024-03-19 21:56:01 +01:00
parent f7025e0f9c
commit 28b478ef87
7 changed files with 71 additions and 208 deletions
+49 -3
View File
@@ -1,6 +1,52 @@
uniform vec4 color;
#version 330
void main(void)
// uniforms
uniform vec4 lightPosition; // should be in the eye space
uniform vec4 lightAmbient; // light ambient color
uniform vec4 lightDiffuse; // light diffuse color
uniform vec4 lightSpecular; // light specular color
uniform vec4 materialAmbient; // material ambient color
uniform vec4 materialDiffuse; // material diffuse color
uniform vec4 materialSpecular; // material specular color
uniform float materialShininess; // material specular shininess
uniform bool drawLines; //
// in
in vec3 esVertex;
in vec3 esNormal;
in vec2 texCoord0;
// out
out vec4 fragColor;
void main()
{
gl_FragColor = color;
vec3 normal = normalize(esNormal);
vec3 light;
if(lightPosition.w == 0.0)
{
light = normalize(lightPosition.xyz);
}
else
{
light = normalize(lightPosition.xyz - esVertex);
}
vec3 view = normalize(-esVertex);
vec3 reflectVec = reflect(-light, normal); // 2 * N * (N dot L) - L
vec3 color = lightAmbient.rgb * materialAmbient.rgb; // begin with ambient
float dotNL = max(dot(normal, light), 0.0);
color += lightDiffuse.rgb * materialDiffuse.rgb * dotNL; // add diffuse
float dotVR = max(dot(view, reflectVec), 0.0);
color += pow(dotVR, materialShininess) * lightSpecular.rgb * materialSpecular.rgb; // add specular
fragColor = vec4(color, materialDiffuse.a); // set frag color
if (drawLines)
{
fragColor = vec4(materialAmbient.rgb * vec3(0.8, 0.8, 0.8), materialDiffuse.a);
}
else
{
fragColor = vec4(materialAmbient.rgb, materialDiffuse.a);
}
}
-26
View File
@@ -1,26 +0,0 @@
#version 330 core
layout (points) in;
layout (line_strip, max_vertices = 2) out;
in Vertex
{
vec3 semiAxisLengths;
} vertex[];
uniform float normalLength;
uniform mat4 modelViewProjectionMatrix;
void main(void)
{
vec3 P = gl_in[0].gl_Position.xyz;
vec3 N = vec3(0., 0., 1.);
gl_Position = modelViewProjectionMatrix * vec4(P, 1.0);
EmitVertex();
gl_Position = modelViewProjectionMatrix * vec4(P + N * 1., 1);
EmitVertex();
EndPrimitive();
}
-86
View File
@@ -1,86 +0,0 @@
#version 330 core
layout (points) in;
layout (line_strip, max_vertices = 200) out;
in Vertex
{
vec3 semiAxisLengths;
} vertex[];
uniform float normalLength;
uniform mat4 modelViewProjectionMatrix;
uniform float cosTheta[21];
uniform float sinTheta[21];
uniform float cosPhi[21];
uniform float sinPhi[21];
void main(void)
{
vec3 P = gl_in[0].gl_Position.xyz;
//vec3 semiAxisLengths = vertex[0].semiAxisLengths;
vec3 semiAxisLengths = vec3(0.1, 0.1, 0.1);
float x;
float y;
float z;
int count = 0;
for (int phi_i = 0; phi_i < 21; phi_i++)
{
if (phi_i == 0)
{
x = P.x;
y = P.y;
z = P.z + semiAxisLengths.z;
gl_Position = modelViewProjectionMatrix * vec4(x, y, z, 1.0);
EmitVertex();
count++;
if (count == 200)
{
EndPrimitive();
count = 0;
}
}
else if (phi_i == 20)
{
x = P.x;
y = P.y;
z = P.z - 1.;
gl_Position = modelViewProjectionMatrix * vec4(x, y, z, 1.0);
EmitVertex();
count++;
if (count == 200)
{
EndPrimitive();
count = 0;
}
}
else
{
for (int theta_i = 0; theta_i < 21; theta_i++)
{
//x = P.x + semiAxisLengths.x * sinTheta[theta_i] * cosPhi[phi_i];
//y = P.y + semiAxisLengths.y * sinTheta[theta_i] * sinPhi[phi_i];
//z = P.z + semiAxisLengths.z * cosTheta[theta_i];
x = P.x + semiAxisLengths.x * sinTheta[theta_i] * cosPhi[phi_i];
y = P.y + semiAxisLengths.y * sinTheta[theta_i] * sinPhi[phi_i];
z = P.z + semiAxisLengths.z * cosTheta[theta_i];
gl_Position = modelViewProjectionMatrix * vec4(x, y, z, 1.0);
EmitVertex();
count++;
if (count == 200)
{
EndPrimitive();
count = 0;
}
}
}
}
EndPrimitive();
}
+20 -11
View File
@@ -1,17 +1,26 @@
attribute vec3 vertexIn;
attribute vec3 semiAxisLengths;
/*out Vertex
{
vec3 semiAxisLengths;
} vertex;*/
#version 330
// uniforms
uniform mat4 modelViewMatrix;
uniform mat4 normalMatrix;
uniform mat4 modelViewProjectionMatrix;
uniform vec3 center;
uniform int instanceId;
void main(void)
// in
in vec3 vertexPosition;
in vec3 vertexNormal;
in vec2 vertexTexCoord;
// out
out vec3 esVertex;
out vec3 esNormal;
out vec2 texCoord0;
void main()
{
gl_PointSize = 5;
gl_Position = modelViewProjectionMatrix * vec4(vertexIn + center, 1.0);
//vertex.semiAxisLengths = semiAxisLengths;
esVertex = vec3(modelViewMatrix * vec4(vertexPosition, 1.0));
esNormal = vec3(normalMatrix * vec4(vertexNormal, 1.0));
texCoord0 = vertexTexCoord;
gl_Position = modelViewProjectionMatrix * vec4(vertexPosition, 1.0);
}
-52
View File
@@ -1,52 +0,0 @@
#version 330
// uniforms
uniform vec4 lightPosition; // should be in the eye space
uniform vec4 lightAmbient; // light ambient color
uniform vec4 lightDiffuse; // light diffuse color
uniform vec4 lightSpecular; // light specular color
uniform vec4 materialAmbient; // material ambient color
uniform vec4 materialDiffuse; // material diffuse color
uniform vec4 materialSpecular; // material specular color
uniform float materialShininess; // material specular shininess
uniform bool drawLines; //
// in
in vec3 esVertex;
in vec3 esNormal;
in vec2 texCoord0;
// out
out vec4 fragColor;
void main()
{
vec3 normal = normalize(esNormal);
vec3 light;
if(lightPosition.w == 0.0)
{
light = normalize(lightPosition.xyz);
}
else
{
light = normalize(lightPosition.xyz - esVertex);
}
vec3 view = normalize(-esVertex);
vec3 reflectVec = reflect(-light, normal); // 2 * N * (N dot L) - L
vec3 color = lightAmbient.rgb * materialAmbient.rgb; // begin with ambient
float dotNL = max(dot(normal, light), 0.0);
color += lightDiffuse.rgb * materialDiffuse.rgb * dotNL; // add diffuse
float dotVR = max(dot(view, reflectVec), 0.0);
color += pow(dotVR, materialShininess) * lightSpecular.rgb * materialSpecular.rgb; // add specular
fragColor = vec4(color, materialDiffuse.a); // set frag color
if (drawLines)
{
fragColor = vec4(materialAmbient.rgb * vec3(0.8, 0.8, 0.8), materialDiffuse.a);
}
else
{
fragColor = vec4(materialAmbient.rgb, materialDiffuse.a);
}
}
-26
View File
@@ -1,26 +0,0 @@
#version 330
// uniforms
uniform mat4 modelViewMatrix;
uniform mat4 normalMatrix;
uniform mat4 modelViewProjectionMatrix;
uniform vec3 center;
uniform int instanceId;
// in
in vec3 vertexPosition;
in vec3 vertexNormal;
in vec2 vertexTexCoord;
// out
out vec3 esVertex;
out vec3 esNormal;
out vec2 texCoord0;
void main()
{
esVertex = vec3(modelViewMatrix * vec4(vertexPosition, 1.0));
esNormal = vec3(normalMatrix * vec4(vertexNormal, 1.0));
texCoord0 = vertexTexCoord;
gl_Position = modelViewProjectionMatrix * vec4(vertexPosition, 1.0);
}
+2 -4
View File
@@ -39,8 +39,7 @@ bool GrainsAsEllipsoids::initProgram(QOpenGLContext* context)
m_program.reset(new QOpenGLShaderProgram(context));
// create vertex shader
// QString vertexShaderFile(m_shaderPath + "/DrawGrains.vs");
QString vertexShaderFile(m_shaderPath + "/ellipsoid.vs");
QString vertexShaderFile(m_shaderPath + "/DrawGrains.vs");
if (!m_program->addShaderFromSourceFile(QOpenGLShader::Vertex, vertexShaderFile))
{
error = m_program->log();
@@ -58,8 +57,7 @@ bool GrainsAsEllipsoids::initProgram(QOpenGLContext* context)
// }
// create fragment shader
// QString fragmentShaderFile(m_shaderPath + "/DrawGrains.fs");
QString fragmentShaderFile(m_shaderPath + "/ellipsoid.fs");
QString fragmentShaderFile(m_shaderPath + "/DrawGrains.fs");
if (!m_program->addShaderFromSourceFile(QOpenGLShader::Fragment, fragmentShaderFile))
{
error = m_program->log();