summaryrefslogtreecommitdiffstats
path: root/src/render
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@theqtcompany.com>2015-12-09 16:21:04 +0100
committerLaszlo Agocs <laszlo.agocs@theqtcompany.com>2015-12-10 11:54:28 +0000
commit5e94c15ddc89779c6da7ae919985688173a4d20d (patch)
treee9efeba287fab6c234d6e6ab1b3274478e7092d8 /src/render
parent2dec7715ed977e5cafdd35543538e104e1ccadf9 (diff)
Do lighting calculation in world space
As opposed to (mostly) camera space. Oops. While somewhat hidden with point lights, the problem became apparent with directional lights. Now that we have proper directional lights, change the default light, that is used when no light components are specified at all, from point to directional since this is cheaper and provides less surprises with arbitrary scenes. Also remove the duplicate phongalpha vertex shader in the process. Change-Id: I295660a1400b16b69e1516672e31794312ee48d1 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/render')
-rw-r--r--src/render/backend/renderview.cpp8
-rw-r--r--src/render/defaults/qphongalphamaterial.cpp4
-rw-r--r--src/render/render.qrc2
-rw-r--r--src/render/shaders/es2/diffusemap.frag6
-rw-r--r--src/render/shaders/es2/diffusemap.vert12
-rw-r--r--src/render/shaders/es2/diffusespecularmap.frag6
-rw-r--r--src/render/shaders/es2/gooch.frag6
-rw-r--r--src/render/shaders/es2/gooch.vert12
-rw-r--r--src/render/shaders/es2/normaldiffusemap.frag4
-rw-r--r--src/render/shaders/es2/normaldiffusemap.vert14
-rw-r--r--src/render/shaders/es2/normaldiffusemapalpha.frag4
-rw-r--r--src/render/shaders/es2/normaldiffusespecularmap.frag4
-rw-r--r--src/render/shaders/es2/pervertexcolor.frag6
-rw-r--r--src/render/shaders/es2/pervertexcolor.vert12
-rw-r--r--src/render/shaders/es2/phong.frag6
-rw-r--r--src/render/shaders/es2/phong.vert12
-rw-r--r--src/render/shaders/es2/phongalpha.frag6
-rw-r--r--src/render/shaders/es2/phongalpha.vert17
-rw-r--r--src/render/shaders/gl3/diffusemap.frag6
-rw-r--r--src/render/shaders/gl3/diffusemap.vert12
-rw-r--r--src/render/shaders/gl3/diffusespecularmap.frag6
-rw-r--r--src/render/shaders/gl3/gooch.frag6
-rw-r--r--src/render/shaders/gl3/gooch.vert12
-rw-r--r--src/render/shaders/gl3/normaldiffusemap.frag4
-rw-r--r--src/render/shaders/gl3/normaldiffusemap.vert15
-rw-r--r--src/render/shaders/gl3/normaldiffusemapalpha.frag4
-rw-r--r--src/render/shaders/gl3/normaldiffusespecularmap.frag4
-rw-r--r--src/render/shaders/gl3/pervertexcolor.frag6
-rw-r--r--src/render/shaders/gl3/pervertexcolor.vert12
-rw-r--r--src/render/shaders/gl3/phong.frag6
-rw-r--r--src/render/shaders/gl3/phong.vert12
-rw-r--r--src/render/shaders/gl3/phongalpha.frag6
-rw-r--r--src/render/shaders/gl3/phongalpha.vert19
33 files changed, 116 insertions, 155 deletions
diff --git a/src/render/backend/renderview.cpp b/src/render/backend/renderview.cpp
index 6c1f4b4e9..23599a223 100644
--- a/src/render/backend/renderview.cpp
+++ b/src/render/backend/renderview.cpp
@@ -773,12 +773,12 @@ void RenderView::setShaderAndUniforms(RenderCommand *command, RenderPass *rPass,
if (lightIdx == MAX_LIGHTS)
break;
Entity *lightEntity = lightSource.entity;
- const QVector3D pos = *m_data->m_viewMatrix * lightEntity->worldBoundingVolume()->center();
+ const QVector3D worldPos = lightEntity->worldBoundingVolume()->center();
Q_FOREACH (Light *light, lightSource.lights) {
if (lightIdx == MAX_LIGHTS)
break;
QString structName = QString(QStringLiteral("%1[%2]")).arg(LIGHT_ARRAY_NAME).arg(lightIdx);
- setUniformValue(command->m_uniforms, structName + QLatin1Char('.') + LIGHT_POSITION_NAME, pos);
+ setUniformValue(command->m_uniforms, structName + QLatin1Char('.') + LIGHT_POSITION_NAME, worldPos);
setDefaultUniformBlockShaderDataValue(command->m_uniforms, shader, light, structName);
++lightIdx;
}
@@ -788,8 +788,8 @@ void RenderView::setShaderAndUniforms(RenderCommand *command, RenderPass *rPass,
setUniformValue(command->m_uniforms, LIGHT_COUNT_NAME, qMax(1, lightIdx));
if (activeLightSources.isEmpty()) {
- setUniformValue(command->m_uniforms, QStringLiteral("lights[0].type"), int(QLight::PointLight));
- setUniformValue(command->m_uniforms, QStringLiteral("lights[0].position"), QVector3D(10.0f, 10.0f, 0.0f));
+ setUniformValue(command->m_uniforms, QStringLiteral("lights[0].type"), int(QLight::DirectionalLight));
+ setUniformValue(command->m_uniforms, QStringLiteral("lights[0].direction"), QVector3D(0.0f, -1.0f, -1.0f));
setUniformValue(command->m_uniforms, QStringLiteral("lights[0].color"), QVector3D(1.0f, 1.0f, 1.0f));
setUniformValue(command->m_uniforms, QStringLiteral("lights[0].intensity"), QVector3D(0.5f, 0.5f, 0.5f));
}
diff --git a/src/render/defaults/qphongalphamaterial.cpp b/src/render/defaults/qphongalphamaterial.cpp
index c9045461f..e54e9c694 100644
--- a/src/render/defaults/qphongalphamaterial.cpp
+++ b/src/render/defaults/qphongalphamaterial.cpp
@@ -94,9 +94,9 @@ void QPhongAlphaMaterialPrivate::init()
connect(m_alphaParameter, &Qt3DRender::QParameter::valueChanged,
this, &QPhongAlphaMaterialPrivate::handleAlphaChanged);
- m_phongAlphaGL3Shader->setVertexShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/gl3/phongalpha.vert"))));
+ m_phongAlphaGL3Shader->setVertexShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/gl3/phong.vert"))));
m_phongAlphaGL3Shader->setFragmentShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/gl3/phongalpha.frag"))));
- m_phongAlphaGL2ES2Shader->setVertexShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/es2/phongalpha.vert"))));
+ m_phongAlphaGL2ES2Shader->setVertexShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/es2/phong.vert"))));
m_phongAlphaGL2ES2Shader->setFragmentShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/es2/phongalpha.frag"))));
m_phongAlphaGL3Technique->graphicsApiFilter()->setApi(QGraphicsApiFilter::OpenGL);
diff --git a/src/render/render.qrc b/src/render/render.qrc
index 0cf54286b..e7b1c1d9a 100644
--- a/src/render/render.qrc
+++ b/src/render/render.qrc
@@ -34,9 +34,7 @@
<file>shaders/es2/gooch.frag</file>
<file>shaders/es2/gooch.vert</file>
<file>shaders/gl3/phongalpha.frag</file>
- <file>shaders/gl3/phongalpha.vert</file>
<file>shaders/es2/phongalpha.frag</file>
- <file>shaders/es2/phongalpha.vert</file>
<file>shaders/gl3/unlittexture.vert</file>
<file>shaders/gl3/unlittexture.frag</file>
<file>shaders/es2/unlittexture.frag</file>
diff --git a/src/render/shaders/es2/diffusemap.frag b/src/render/shaders/es2/diffusemap.frag
index f7fb0fe52..7d06d8e2c 100644
--- a/src/render/shaders/es2/diffusemap.frag
+++ b/src/render/shaders/es2/diffusemap.frag
@@ -8,8 +8,8 @@ uniform FP vec3 eyePosition;
uniform sampler2D diffuseTexture;
-varying FP vec3 position;
-varying FP vec3 normal;
+varying FP vec3 worldPosition;
+varying FP vec3 worldNormal;
varying FP vec2 texCoord;
#pragma include light.inc.frag
@@ -19,7 +19,7 @@ void main()
FP vec3 diffuseTextureColor = texture2D( diffuseTexture, texCoord ).rgb;
FP vec3 diffuseColor, specularColor;
- adsModel(position, normal, eyePosition, shininess, diffuseColor, specularColor);
+ adsModel(worldPosition, worldNormal, eyePosition, shininess, diffuseColor, specularColor);
gl_FragColor = vec4( diffuseTextureColor * ( ka + diffuseColor ) + ks * specularColor, 1.0 );
}
diff --git a/src/render/shaders/es2/diffusemap.vert b/src/render/shaders/es2/diffusemap.vert
index 90c751557..13798279e 100644
--- a/src/render/shaders/es2/diffusemap.vert
+++ b/src/render/shaders/es2/diffusemap.vert
@@ -2,12 +2,12 @@ attribute vec3 vertexPosition;
attribute vec3 vertexNormal;
attribute vec2 vertexTexCoord;
-varying vec3 position;
-varying vec3 normal;
+varying vec3 worldPosition;
+varying vec3 worldNormal;
varying vec2 texCoord;
-uniform mat4 modelView;
-uniform mat3 modelViewNormal;
+uniform mat4 modelMatrix;
+uniform mat3 modelNormalMatrix;
uniform mat4 mvp;
uniform float texCoordScale;
@@ -15,8 +15,8 @@ uniform float texCoordScale;
void main()
{
texCoord = vertexTexCoord * texCoordScale;
- normal = normalize( modelViewNormal * vertexNormal );
- position = vec3( modelView * vec4( vertexPosition, 1.0 ) );
+ worldNormal = normalize( modelNormalMatrix * vertexNormal );
+ worldPosition = vec3( modelMatrix * vec4( vertexPosition, 1.0 ) );
gl_Position = mvp * vec4( vertexPosition, 1.0 );
}
diff --git a/src/render/shaders/es2/diffusespecularmap.frag b/src/render/shaders/es2/diffusespecularmap.frag
index cc7785fd8..4d776772c 100644
--- a/src/render/shaders/es2/diffusespecularmap.frag
+++ b/src/render/shaders/es2/diffusespecularmap.frag
@@ -9,8 +9,8 @@ uniform FP vec3 eyePosition;
uniform sampler2D diffuseTexture;
uniform sampler2D specularTexture;
-varying FP vec3 position;
-varying FP vec3 normal;
+varying FP vec3 worldPosition;
+varying FP vec3 worldNormal;
varying FP vec2 texCoord;
#pragma include light.inc.frag
@@ -21,7 +21,7 @@ void main()
FP vec3 specularTextureColor = texture2D( specularTexture, texCoord ).rgb;
FP vec3 diffuseColor, specularColor;
- adsModel(position, normal, eyePosition, shininess, diffuseColor, specularColor);
+ adsModel(worldPosition, worldNormal, eyePosition, shininess, diffuseColor, specularColor);
gl_FragColor = vec4( diffuseTextureColor * ( ka + diffuseColor ) + specularTextureColor * specularColor, 1.0 );
}
diff --git a/src/render/shaders/es2/gooch.frag b/src/render/shaders/es2/gooch.frag
index b71cc3073..622aaf0b4 100644
--- a/src/render/shaders/es2/gooch.frag
+++ b/src/render/shaders/es2/gooch.frag
@@ -11,8 +11,8 @@ uniform FP float shininess; // Specular shininess factor
uniform FP vec3 eyePosition;
-varying FP vec3 position;
-varying FP vec3 normal;
+varying FP vec3 worldPosition;
+varying FP vec3 worldNormal;
#pragma include light.inc.frag
@@ -52,5 +52,5 @@ FP vec3 goochModel( const in FP vec3 pos, const in FP vec3 n )
void main()
{
- gl_FragColor = vec4( goochModel( position, normalize( normal ) ), 1.0 );
+ gl_FragColor = vec4( goochModel( worldPosition, normalize( worldNormal ) ), 1.0 );
}
diff --git a/src/render/shaders/es2/gooch.vert b/src/render/shaders/es2/gooch.vert
index 03a416213..dd162a66b 100644
--- a/src/render/shaders/es2/gooch.vert
+++ b/src/render/shaders/es2/gooch.vert
@@ -1,17 +1,17 @@
attribute vec3 vertexPosition;
attribute vec3 vertexNormal;
-varying vec3 position;
-varying vec3 normal;
+varying vec3 worldPosition;
+varying vec3 worldNormal;
-uniform mat4 modelView;
-uniform mat3 modelViewNormal;
+uniform mat4 modelMatrix;
+uniform mat3 modelNormalMatrix;
uniform mat4 mvp;
void main()
{
- normal = normalize( modelViewNormal * vertexNormal );
- position = vec3( modelView * vec4( vertexPosition, 1.0 ) );
+ worldNormal = normalize( modelNormalMatrix * vertexNormal );
+ worldPosition = vec3( modelMatrix * vec4( vertexPosition, 1.0 ) );
gl_Position = mvp * vec4( vertexPosition, 1.0 );
}
diff --git a/src/render/shaders/es2/normaldiffusemap.frag b/src/render/shaders/es2/normaldiffusemap.frag
index 71e936e15..1cf3e6838 100644
--- a/src/render/shaders/es2/normaldiffusemap.frag
+++ b/src/render/shaders/es2/normaldiffusemap.frag
@@ -1,6 +1,6 @@
#define FP highp
-varying FP vec3 position;
+varying FP vec3 worldPosition;
varying FP vec2 texCoord;
varying FP mat3 tangentMatrix;
@@ -24,7 +24,7 @@ void main()
// Calculate the lighting model, keeping the specular component separate
FP vec3 diffuseColor, specularColor;
- adsModelNormalMapped(position, normal, eyePosition, shininess, tangentMatrix, diffuseColor, specularColor);
+ adsModelNormalMapped(worldPosition, normal, eyePosition, shininess, tangentMatrix, diffuseColor, specularColor);
// Combine spec with ambient+diffuse for final fragment color
gl_FragColor = vec4( ka + diffuseTextureColor.rgb * diffuseColor + ks * specularColor, 1.0 );
diff --git a/src/render/shaders/es2/normaldiffusemap.vert b/src/render/shaders/es2/normaldiffusemap.vert
index fda16284d..ecc689f69 100644
--- a/src/render/shaders/es2/normaldiffusemap.vert
+++ b/src/render/shaders/es2/normaldiffusemap.vert
@@ -3,12 +3,12 @@ attribute vec3 vertexNormal;
attribute vec2 vertexTexCoord;
attribute vec4 vertexTangent;
-varying vec3 position;
+varying vec3 worldPosition;
varying vec2 texCoord;
varying mat3 tangentMatrix;
-uniform mat4 modelView;
-uniform mat3 modelViewNormal;
+uniform mat4 modelMatrix;
+uniform mat3 modelNormalMatrix;
uniform mat4 projectionMatrix;
uniform mat4 mvp;
@@ -19,10 +19,10 @@ void main()
// Pass through texture coordinates
texCoord = vertexTexCoord * texCoordScale;
- // Transform position, normal, and tangent to eye coords
- vec3 normal = normalize( modelViewNormal * vertexNormal );
- vec3 tangent = normalize( modelViewNormal * vertexTangent.xyz );
- position = vec3( modelView * vec4( vertexPosition, 1.0 ) );
+ // Transform position, normal, and tangent to world coords
+ vec3 normal = normalize( modelNormalMatrix * vertexNormal );
+ vec3 tangent = normalize( modelNormalMatrix * vertexTangent.xyz );
+ worldPosition = vec3( modelMatrix * vec4( vertexPosition, 1.0 ) );
// Calculate binormal vector
vec3 binormal = normalize( cross( normal, tangent ) );
diff --git a/src/render/shaders/es2/normaldiffusemapalpha.frag b/src/render/shaders/es2/normaldiffusemapalpha.frag
index 75306b3bd..debe45d78 100644
--- a/src/render/shaders/es2/normaldiffusemapalpha.frag
+++ b/src/render/shaders/es2/normaldiffusemapalpha.frag
@@ -1,6 +1,6 @@
#define FP highp
-varying FP vec3 position;
+varying FP vec3 worldPosition;
varying FP vec2 texCoord;
varying FP mat3 tangentMatrix;
@@ -24,7 +24,7 @@ void main()
// Calculate the lighting model, keeping the specular component separate
FP vec3 diffuseColor, specularColor;
- adsModelNormalMapped(position, normal, eyePosition, shininess, tangentMatrix, diffuseColor, specularColor);
+ adsModelNormalMapped(worldPosition, normal, eyePosition, shininess, tangentMatrix, diffuseColor, specularColor);
// Combine spec with ambient+diffuse for final fragment color
// Use the alpha from the diffuse texture (for alpha to coverage)
diff --git a/src/render/shaders/es2/normaldiffusespecularmap.frag b/src/render/shaders/es2/normaldiffusespecularmap.frag
index 48eaaae7d..8219ce4db 100644
--- a/src/render/shaders/es2/normaldiffusespecularmap.frag
+++ b/src/render/shaders/es2/normaldiffusespecularmap.frag
@@ -1,6 +1,6 @@
#define FP highp
-varying FP vec3 position;
+varying FP vec3 worldPosition;
varying FP vec2 texCoord;
varying FP mat3 tangentMatrix;
@@ -25,7 +25,7 @@ void main()
// Calculate the lighting model, keeping the specular component separate
FP vec3 diffuseColor, specularColor;
- adsModelNormalMapped(position, normal, eyePosition, shininess, tangentMatrix, diffuseColor, specularColor);
+ adsModelNormalMapped(worldPosition, normal, eyePosition, shininess, tangentMatrix, diffuseColor, specularColor);
// Combine spec with ambient+diffuse for final fragment color
gl_FragColor = vec4( ka + diffuseTextureColor.rgb * diffuseColor + specularTextureColor.rgb * specularColor, 1.0 );
diff --git a/src/render/shaders/es2/pervertexcolor.frag b/src/render/shaders/es2/pervertexcolor.frag
index 70bdd3ccb..ab429d942 100644
--- a/src/render/shaders/es2/pervertexcolor.frag
+++ b/src/render/shaders/es2/pervertexcolor.frag
@@ -1,7 +1,7 @@
#define FP highp
-varying FP vec3 position;
-varying FP vec3 normal;
+varying FP vec3 worldPosition;
+varying FP vec3 worldNormal;
varying FP vec3 color;
#pragma include light.inc.frag
@@ -9,6 +9,6 @@ varying FP vec3 color;
void main()
{
FP vec3 diffuseColor;
- adModel(position, normal, diffuseColor);
+ adModel(worldPosition, worldNormal, diffuseColor);
gl_FragColor = vec4( color + color * diffuseColor, 1.0 );
}
diff --git a/src/render/shaders/es2/pervertexcolor.vert b/src/render/shaders/es2/pervertexcolor.vert
index e7303052b..7fc3e649f 100644
--- a/src/render/shaders/es2/pervertexcolor.vert
+++ b/src/render/shaders/es2/pervertexcolor.vert
@@ -2,18 +2,18 @@ attribute vec3 vertexPosition;
attribute vec3 vertexNormal;
attribute vec3 vertexColor;
-varying vec3 position;
-varying vec3 normal;
+varying vec3 worldPosition;
+varying vec3 worldNormal;
varying vec3 color;
-uniform mat4 modelView;
-uniform mat3 modelViewNormal;
+uniform mat4 modelMatrix;
+uniform mat3 modelNormalMatrix;
uniform mat4 mvp;
void main()
{
- normal = normalize( modelViewNormal * vertexNormal );
- position = vec3( modelView * vec4( vertexPosition, 1.0 ) );
+ worldNormal = normalize( modelNormalMatrix * vertexNormal );
+ worldPosition = vec3( modelMatrix * vec4( vertexPosition, 1.0 ) );
color = vertexColor;
gl_Position = mvp * vec4( vertexPosition, 1.0 );
diff --git a/src/render/shaders/es2/phong.frag b/src/render/shaders/es2/phong.frag
index 0ea5abf0d..c00f89db0 100644
--- a/src/render/shaders/es2/phong.frag
+++ b/src/render/shaders/es2/phong.frag
@@ -7,14 +7,14 @@ uniform FP float shininess; // Specular shininess factor
uniform FP vec3 eyePosition;
-varying FP vec3 position;
-varying FP vec3 normal;
+varying FP vec3 worldPosition;
+varying FP vec3 worldNormal;
#pragma include light.inc.frag
void main()
{
FP vec3 diffuseColor, specularColor;
- adsModel(position, normal, eyePosition, shininess, diffuseColor, specularColor);
+ adsModel(worldPosition, worldNormal, eyePosition, shininess, diffuseColor, specularColor);
gl_FragColor = vec4( ka + kd * diffuseColor + ks * specularColor, 1.0 );
}
diff --git a/src/render/shaders/es2/phong.vert b/src/render/shaders/es2/phong.vert
index 255af8f11..2b4c51b14 100644
--- a/src/render/shaders/es2/phong.vert
+++ b/src/render/shaders/es2/phong.vert
@@ -1,17 +1,17 @@
attribute vec3 vertexPosition;
attribute vec3 vertexNormal;
-varying vec3 position;
-varying vec3 normal;
+varying vec3 worldPosition;
+varying vec3 worldNormal;
-uniform mat4 modelView;
-uniform mat3 modelViewNormal;
+uniform mat4 modelMatrix;
+uniform mat3 modelNormalMatrix;
uniform mat4 modelViewProjection;
void main()
{
- normal = normalize( modelViewNormal * vertexNormal );
- position = vec3( modelView * vec4( vertexPosition, 1.0 ) );
+ worldNormal = normalize( modelNormalMatrix * vertexNormal );
+ worldPosition = vec3( modelMatrix * vec4( vertexPosition, 1.0 ) );
gl_Position = modelViewProjection * vec4( vertexPosition, 1.0 );
}
diff --git a/src/render/shaders/es2/phongalpha.frag b/src/render/shaders/es2/phongalpha.frag
index 5f558a5a4..c5ec43049 100644
--- a/src/render/shaders/es2/phongalpha.frag
+++ b/src/render/shaders/es2/phongalpha.frag
@@ -9,14 +9,14 @@ uniform FP float alpha;
uniform FP vec3 eyePosition;
-varying FP vec3 position;
-varying FP vec3 normal;
+varying FP vec3 worldPosition;
+varying FP vec3 worldNormal;
#pragma include light.inc.frag
void main()
{
FP vec3 diffuseColor, specularColor;
- adsModel(position, normal, eyePosition, shininess, diffuseColor, specularColor);
+ adsModel(worldPosition, worldNormal, eyePosition, shininess, diffuseColor, specularColor);
gl_FragColor = vec4( ka + kd * diffuseColor + ks * specularColor, alpha );
}
diff --git a/src/render/shaders/es2/phongalpha.vert b/src/render/shaders/es2/phongalpha.vert
deleted file mode 100644
index 03a416213..000000000
--- a/src/render/shaders/es2/phongalpha.vert
+++ /dev/null
@@ -1,17 +0,0 @@
-attribute vec3 vertexPosition;
-attribute vec3 vertexNormal;
-
-varying vec3 position;
-varying vec3 normal;
-
-uniform mat4 modelView;
-uniform mat3 modelViewNormal;
-uniform mat4 mvp;
-
-void main()
-{
- normal = normalize( modelViewNormal * vertexNormal );
- position = vec3( modelView * vec4( vertexPosition, 1.0 ) );
-
- gl_Position = mvp * vec4( vertexPosition, 1.0 );
-}
diff --git a/src/render/shaders/gl3/diffusemap.frag b/src/render/shaders/gl3/diffusemap.frag
index 5e6266fd3..7810fdb68 100644
--- a/src/render/shaders/gl3/diffusemap.frag
+++ b/src/render/shaders/gl3/diffusemap.frag
@@ -8,8 +8,8 @@ uniform vec3 eyePosition;
uniform sampler2D diffuseTexture;
-in vec3 position;
-in vec3 normal;
+in vec3 worldPosition;
+in vec3 worldNormal;
in vec2 texCoord;
out vec4 fragColor;
@@ -21,7 +21,7 @@ void main()
vec3 diffuseTextureColor = texture( diffuseTexture, texCoord ).rgb;
vec3 diffuseColor, specularColor;
- adsModel(position, normal, eyePosition, shininess, diffuseColor, specularColor);
+ adsModel(worldPosition, worldNormal, eyePosition, shininess, diffuseColor, specularColor);
fragColor = vec4( diffuseTextureColor * ( ka + diffuseColor ) + ks * specularColor, 1.0 );
}
diff --git a/src/render/shaders/gl3/diffusemap.vert b/src/render/shaders/gl3/diffusemap.vert
index 2b27413a5..439be6e99 100644
--- a/src/render/shaders/gl3/diffusemap.vert
+++ b/src/render/shaders/gl3/diffusemap.vert
@@ -4,12 +4,12 @@ in vec3 vertexPosition;
in vec3 vertexNormal;
in vec2 vertexTexCoord;
-out vec3 position;
-out vec3 normal;
+out vec3 worldPosition;
+out vec3 worldNormal;
out vec2 texCoord;
-uniform mat4 modelView;
-uniform mat3 modelViewNormal;
+uniform mat4 modelMatrix;
+uniform mat3 modelNormalMatrix;
uniform mat4 mvp;
uniform float texCoordScale;
@@ -17,8 +17,8 @@ uniform float texCoordScale;
void main()
{
texCoord = vertexTexCoord * texCoordScale;
- normal = normalize( modelViewNormal * vertexNormal );
- position = vec3( modelView * vec4( vertexPosition, 1.0 ) );
+ worldNormal = normalize( modelNormalMatrix * vertexNormal );
+ worldPosition = vec3( modelMatrix * vec4( vertexPosition, 1.0 ) );
gl_Position = mvp * vec4( vertexPosition, 1.0 );
}
diff --git a/src/render/shaders/gl3/diffusespecularmap.frag b/src/render/shaders/gl3/diffusespecularmap.frag
index 98ef53040..fb809393a 100644
--- a/src/render/shaders/gl3/diffusespecularmap.frag
+++ b/src/render/shaders/gl3/diffusespecularmap.frag
@@ -9,8 +9,8 @@ uniform vec3 eyePosition;
uniform sampler2D diffuseTexture;
uniform sampler2D specularTexture;
-in vec3 position;
-in vec3 normal;
+in vec3 worldPosition;
+in vec3 worldNormal;
in vec2 texCoord;
out vec4 fragColor;
@@ -23,7 +23,7 @@ void main()
vec3 specularTextureColor = texture( specularTexture, texCoord ).rgb;
vec3 diffuseColor, specularColor;
- adsModel(position, normal, eyePosition, shininess, diffuseColor, specularColor);
+ adsModel(worldPosition, worldNormal, eyePosition, shininess, diffuseColor, specularColor);
fragColor = vec4( diffuseTextureColor * ( ka + diffuseColor ) + specularTextureColor * specularColor, 1.0 );
}
diff --git a/src/render/shaders/gl3/gooch.frag b/src/render/shaders/gl3/gooch.frag
index 14c4c714a..1beab1c01 100644
--- a/src/render/shaders/gl3/gooch.frag
+++ b/src/render/shaders/gl3/gooch.frag
@@ -11,8 +11,8 @@ uniform float shininess; // Specular shininess factor
uniform vec3 eyePosition;
-in vec3 position;
-in vec3 normal;
+in vec3 worldPosition;
+in vec3 worldNormal;
out vec4 fragColor;
@@ -60,5 +60,5 @@ vec3 goochModel( const in vec3 pos, const in vec3 n )
void main()
{
- fragColor = vec4( goochModel( position, normalize( normal ) ), 1.0 );
+ fragColor = vec4( goochModel( worldPosition, normalize( worldNormal ) ), 1.0 );
}
diff --git a/src/render/shaders/gl3/gooch.vert b/src/render/shaders/gl3/gooch.vert
index c0f907f29..5230fb70e 100644
--- a/src/render/shaders/gl3/gooch.vert
+++ b/src/render/shaders/gl3/gooch.vert
@@ -3,17 +3,17 @@
in vec3 vertexPosition;
in vec3 vertexNormal;
-out vec3 position;
-out vec3 normal;
+out vec3 worldPosition;
+out vec3 worldNormal;
-uniform mat4 modelView;
-uniform mat3 modelViewNormal;
+uniform mat4 modelMatrix;
+uniform mat3 modelNormalMatrix;
uniform mat4 mvp;
void main()
{
- normal = normalize( modelViewNormal * vertexNormal );
- position = vec3( modelView * vec4( vertexPosition, 1.0 ) );
+ worldNormal = normalize( modelNormalMatrix * vertexNormal );
+ worldPosition = vec3( modelMatrix * vec4( vertexPosition, 1.0 ) );
gl_Position = mvp * vec4( vertexPosition, 1.0 );
}
diff --git a/src/render/shaders/gl3/normaldiffusemap.frag b/src/render/shaders/gl3/normaldiffusemap.frag
index 4b61813c5..a99a7ed73 100644
--- a/src/render/shaders/gl3/normaldiffusemap.frag
+++ b/src/render/shaders/gl3/normaldiffusemap.frag
@@ -1,6 +1,6 @@
#version 150 core
-in vec3 position;
+in vec3 worldPosition;
in vec2 texCoord;
in mat3 tangentMatrix;
@@ -26,7 +26,7 @@ void main()
// Calculate the lighting model, keeping the specular component separate
vec3 diffuseColor, specularColor;
- adsModelNormalMapped(position, normal, eyePosition, shininess, tangentMatrix, diffuseColor, specularColor);
+ adsModelNormalMapped(worldPosition, normal, eyePosition, shininess, tangentMatrix, diffuseColor, specularColor);
// Combine spec with ambient+diffuse for final fragment color
fragColor = vec4( ka + diffuseTextureColor.rgb * diffuseColor + ks * specularColor, 1.0 );
diff --git a/src/render/shaders/gl3/normaldiffusemap.vert b/src/render/shaders/gl3/normaldiffusemap.vert
index 8b3a0716f..306a562fb 100644
--- a/src/render/shaders/gl3/normaldiffusemap.vert
+++ b/src/render/shaders/gl3/normaldiffusemap.vert
@@ -5,13 +5,12 @@ in vec3 vertexNormal;
in vec2 vertexTexCoord;
in vec4 vertexTangent;
-out vec3 position;
+out vec3 worldPosition;
out vec2 texCoord;
out mat3 tangentMatrix;
-uniform mat4 modelView;
-uniform mat3 modelViewNormal;
-uniform mat4 projectionMatrix;
+uniform mat4 modelMatrix;
+uniform mat3 modelNormalMatrix;
uniform mat4 mvp;
uniform float texCoordScale;
@@ -21,10 +20,10 @@ void main()
// Pass through texture coordinates
texCoord = vertexTexCoord * texCoordScale;
- // Transform position, normal, and tangent to eye coords
- vec3 normal = normalize( modelViewNormal * vertexNormal );
- vec3 tangent = normalize( modelViewNormal * vertexTangent.xyz );
- position = vec3( modelView * vec4( vertexPosition, 1.0 ) );
+ // Transform position, normal, and tangent to world coords
+ vec3 normal = normalize( modelNormalMatrix * vertexNormal );
+ vec3 tangent = normalize( modelNormalMatrix * vertexTangent.xyz );
+ worldPosition = vec3( modelMatrix * vec4( vertexPosition, 1.0 ) );
// Calculate binormal vector
vec3 binormal = normalize( cross( normal, tangent ) );
diff --git a/src/render/shaders/gl3/normaldiffusemapalpha.frag b/src/render/shaders/gl3/normaldiffusemapalpha.frag
index 28e597b16..ce5cf0e90 100644
--- a/src/render/shaders/gl3/normaldiffusemapalpha.frag
+++ b/src/render/shaders/gl3/normaldiffusemapalpha.frag
@@ -1,6 +1,6 @@
#version 150 core
-in vec3 position;
+in vec3 worldPosition;
in vec2 texCoord;
in mat3 tangentMatrix;
@@ -26,7 +26,7 @@ void main()
// Calculate the lighting model, keeping the specular component separate
vec3 diffuseColor, specularColor;
- adsModelNormalMapped(position, normal, eyePosition, shininess, tangentMatrix, diffuseColor, specularColor);
+ adsModelNormalMapped(worldPosition, normal, eyePosition, shininess, tangentMatrix, diffuseColor, specularColor);
// Combine spec with ambient+diffuse for final fragment color
// Use the alpha from the diffuse texture (for alpha to coverage)
diff --git a/src/render/shaders/gl3/normaldiffusespecularmap.frag b/src/render/shaders/gl3/normaldiffusespecularmap.frag
index d6a5f44ae..b62932ffd 100644
--- a/src/render/shaders/gl3/normaldiffusespecularmap.frag
+++ b/src/render/shaders/gl3/normaldiffusespecularmap.frag
@@ -1,6 +1,6 @@
#version 150 core
-in vec3 position;
+in vec3 worldPosition;
in vec2 texCoord;
in mat3 tangentMatrix;
@@ -27,7 +27,7 @@ void main()
// Calculate the lighting model, keeping the specular component separate
vec3 diffuseColor, specularColor;
- adsModelNormalMapped(position, normal, eyePosition, shininess, tangentMatrix, diffuseColor, specularColor);
+ adsModelNormalMapped(worldPosition, normal, eyePosition, shininess, tangentMatrix, diffuseColor, specularColor);
// Combine spec with ambient+diffuse for final fragment color
fragColor = vec4( ka + diffuseTextureColor.rgb * diffuseColor + specularTextureColor.rgb * specularColor, 1.0 );
diff --git a/src/render/shaders/gl3/pervertexcolor.frag b/src/render/shaders/gl3/pervertexcolor.frag
index 14efdd8af..b5ed5a33d 100644
--- a/src/render/shaders/gl3/pervertexcolor.frag
+++ b/src/render/shaders/gl3/pervertexcolor.frag
@@ -1,7 +1,7 @@
#version 150 core
-in vec3 position;
-in vec3 normal;
+in vec3 worldPosition;
+in vec3 worldNormal;
in vec3 color;
out vec4 fragColor;
@@ -11,6 +11,6 @@ out vec4 fragColor;
void main()
{
vec3 diffuseColor;
- adModel(position, normal, diffuseColor);
+ adModel(worldPosition, worldNormal, diffuseColor);
fragColor = vec4( color + color * diffuseColor, 1.0 );
}
diff --git a/src/render/shaders/gl3/pervertexcolor.vert b/src/render/shaders/gl3/pervertexcolor.vert
index b6b1a5da7..87713a520 100644
--- a/src/render/shaders/gl3/pervertexcolor.vert
+++ b/src/render/shaders/gl3/pervertexcolor.vert
@@ -4,18 +4,18 @@ in vec3 vertexPosition;
in vec3 vertexNormal;
in vec3 vertexColor;
-out vec3 position;
-out vec3 normal;
+out vec3 worldPosition;
+out vec3 worldNormal;
out vec3 color;
-uniform mat4 modelView;
-uniform mat3 modelViewNormal;
+uniform mat4 modelMatrix;
+uniform mat3 modelNormalMatrix;
uniform mat4 mvp;
void main()
{
- normal = normalize( modelViewNormal * vertexNormal );
- position = vec3( modelView * vec4( vertexPosition, 1.0 ) );
+ worldNormal = normalize( modelNormalMatrix * vertexNormal );
+ worldPosition = vec3( modelMatrix * vec4( vertexPosition, 1.0 ) );
color = vertexColor;
gl_Position = mvp * vec4( vertexPosition, 1.0 );
diff --git a/src/render/shaders/gl3/phong.frag b/src/render/shaders/gl3/phong.frag
index 26a06fb91..a4d7e0969 100644
--- a/src/render/shaders/gl3/phong.frag
+++ b/src/render/shaders/gl3/phong.frag
@@ -7,8 +7,8 @@ uniform float shininess; // Specular shininess factor
uniform vec3 eyePosition;
-in vec3 position;
-in vec3 normal;
+in vec3 worldPosition;
+in vec3 worldNormal;
out vec4 fragColor;
@@ -17,6 +17,6 @@ out vec4 fragColor;
void main()
{
vec3 diffuseColor, specularColor;
- adsModel(position, normal, eyePosition, shininess, diffuseColor, specularColor);
+ adsModel(worldPosition, worldNormal, eyePosition, shininess, diffuseColor, specularColor);
fragColor = vec4( ka + kd * diffuseColor + ks * specularColor, 1.0 );
}
diff --git a/src/render/shaders/gl3/phong.vert b/src/render/shaders/gl3/phong.vert
index f0a134702..cdb3c70e9 100644
--- a/src/render/shaders/gl3/phong.vert
+++ b/src/render/shaders/gl3/phong.vert
@@ -3,17 +3,17 @@
in vec3 vertexPosition;
in vec3 vertexNormal;
-out vec3 position;
-out vec3 normal;
+out vec3 worldPosition;
+out vec3 worldNormal;
-uniform mat4 modelView;
-uniform mat3 modelViewNormal;
+uniform mat4 modelMatrix;
+uniform mat3 modelNormalMatrix;
uniform mat4 modelViewProjection;
void main()
{
- normal = normalize( modelViewNormal * vertexNormal );
- position = vec3( modelView * vec4( vertexPosition, 1.0 ) );
+ worldNormal = normalize( modelNormalMatrix * vertexNormal );
+ worldPosition = vec3( modelMatrix * vec4( vertexPosition, 1.0 ) );
gl_Position = modelViewProjection * vec4( vertexPosition, 1.0 );
}
diff --git a/src/render/shaders/gl3/phongalpha.frag b/src/render/shaders/gl3/phongalpha.frag
index 1da32c701..cb019e9aa 100644
--- a/src/render/shaders/gl3/phongalpha.frag
+++ b/src/render/shaders/gl3/phongalpha.frag
@@ -9,8 +9,8 @@ uniform float alpha;
uniform vec3 eyePosition;
-in vec3 position;
-in vec3 normal;
+in vec3 worldPosition;
+in vec3 worldNormal;
out vec4 fragColor;
@@ -19,6 +19,6 @@ out vec4 fragColor;
void main()
{
vec3 diffuseColor, specularColor;
- adsModel(position, normal, eyePosition, shininess, diffuseColor, specularColor);
+ adsModel(worldPosition, worldNormal, eyePosition, shininess, diffuseColor, specularColor);
fragColor = vec4( ka + kd * diffuseColor + ks * specularColor, alpha );
}
diff --git a/src/render/shaders/gl3/phongalpha.vert b/src/render/shaders/gl3/phongalpha.vert
deleted file mode 100644
index c0f907f29..000000000
--- a/src/render/shaders/gl3/phongalpha.vert
+++ /dev/null
@@ -1,19 +0,0 @@
-#version 150 core
-
-in vec3 vertexPosition;
-in vec3 vertexNormal;
-
-out vec3 position;
-out vec3 normal;
-
-uniform mat4 modelView;
-uniform mat3 modelViewNormal;
-uniform mat4 mvp;
-
-void main()
-{
- normal = normalize( modelViewNormal * vertexNormal );
- position = vec3( modelView * vec4( vertexPosition, 1.0 ) );
-
- gl_Position = mvp * vec4( vertexPosition, 1.0 );
-}