Shader cleanup, deferred lighting in progress
--HG-- extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%4045
This commit is contained in:
@@ -390,6 +390,12 @@ double const PI = 3.141592653589793f;
|
|||||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
|
// Set source to buffers from pass 1
|
||||||
|
glActiveTexture(GL_TEXTURE6);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, compositeColorTexture);
|
||||||
|
glActiveTexture(GL_TEXTURE7);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, compositeDepthTexture);
|
||||||
|
|
||||||
// Enable additive blending
|
// Enable additive blending
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_ONE, GL_ONE);
|
glBlendFunc(GL_ONE, GL_ONE);
|
||||||
@@ -404,6 +410,10 @@ double const PI = 3.141592653589793f;
|
|||||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
|
// Set source to buffers from pass 2
|
||||||
|
glActiveTexture(GL_TEXTURE6);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, lightAccumulationBuffer);
|
||||||
|
|
||||||
// Enable backface culling
|
// Enable backface culling
|
||||||
glCullFace(GL_BACK);
|
glCullFace(GL_BACK);
|
||||||
glEnable(GL_CULL_FACE);
|
glEnable(GL_CULL_FACE);
|
||||||
@@ -416,6 +426,12 @@ double const PI = 3.141592653589793f;
|
|||||||
// Render the geometry
|
// Render the geometry
|
||||||
pScene->render(&m_camera, m_pContext, frustrumVolume, false, viewMatrix, cameraPosition, lightDirection, shadowmvpmatrix, shadowDepthTexture, m_cShadowBuffers, 3);
|
pScene->render(&m_camera, m_pContext, frustrumVolume, false, viewMatrix, cameraPosition, lightDirection, shadowmvpmatrix, shadowDepthTexture, m_cShadowBuffers, 3);
|
||||||
|
|
||||||
|
// Deactivate source buffer texture units
|
||||||
|
glActiveTexture(GL_TEXTURE6);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
glActiveTexture(GL_TEXTURE7);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// ----====---- Opaque Geometry, Forward Rendering ----====----
|
// ----====---- Opaque Geometry, Forward Rendering ----====----
|
||||||
|
|
||||||
@@ -588,11 +604,11 @@ double const PI = 3.141592653589793f;
|
|||||||
// This needs to be done prior to linking.
|
// This needs to be done prior to linking.
|
||||||
glBindAttribLocation(*programPointer, KRShader::KRENGINE_ATTRIB_VERTEX, "position");
|
glBindAttribLocation(*programPointer, KRShader::KRENGINE_ATTRIB_VERTEX, "position");
|
||||||
glBindAttribLocation(*programPointer, KRShader::KRENGINE_ATTRIB_TEXUVA, "inputTextureCoordinate");
|
glBindAttribLocation(*programPointer, KRShader::KRENGINE_ATTRIB_TEXUVA, "inputTextureCoordinate");
|
||||||
glBindAttribLocation(*programPointer, KRShader::KRENGINE_ATTRIB_TEXUVB, "shadowuv");
|
glBindAttribLocation(*programPointer, KRShader::KRENGINE_ATTRIB_TEXUVB, "vertex_lightmap_uv");
|
||||||
glBindAttribLocation(*programPointer, KRShader::KRENGINE_ATTRIB_VERTEX, "myVertex");
|
glBindAttribLocation(*programPointer, KRShader::KRENGINE_ATTRIB_VERTEX, "vertex_position");
|
||||||
glBindAttribLocation(*programPointer, KRShader::KRENGINE_ATTRIB_NORMAL, "myNormal");
|
glBindAttribLocation(*programPointer, KRShader::KRENGINE_ATTRIB_NORMAL, "vertex_normal");
|
||||||
glBindAttribLocation(*programPointer, KRShader::KRENGINE_ATTRIB_TANGENT, "myTangent");
|
glBindAttribLocation(*programPointer, KRShader::KRENGINE_ATTRIB_TANGENT, "vertex_tangent");
|
||||||
glBindAttribLocation(*programPointer, KRShader::KRENGINE_ATTRIB_TEXUVA, "myUV");
|
glBindAttribLocation(*programPointer, KRShader::KRENGINE_ATTRIB_TEXUVA, "vertex_uv");
|
||||||
|
|
||||||
// Link program.
|
// Link program.
|
||||||
if (![self linkProgram:*programPointer])
|
if (![self linkProgram:*programPointer])
|
||||||
@@ -635,7 +651,7 @@ double const PI = 3.141592653589793f;
|
|||||||
{
|
{
|
||||||
[self loadVertexShader:@"ShadowShader" fragmentShader:@"ShadowShader" forProgram:&m_shadowShaderProgram withOptions: NULL];
|
[self loadVertexShader:@"ShadowShader" fragmentShader:@"ShadowShader" forProgram:&m_shadowShaderProgram withOptions: NULL];
|
||||||
|
|
||||||
m_shadowUniforms[KRENGINE_UNIFORM_SHADOWMVP1] = glGetUniformLocation(m_shadowShaderProgram, "myShadowMVPMatrix1");
|
m_shadowUniforms[KRENGINE_UNIFORM_SHADOWMVP1] = glGetUniformLocation(m_shadowShaderProgram, "shadow_mvp1");
|
||||||
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|||||||
@@ -47,11 +47,31 @@ KRShader::KRShader(char *szKey, std::string options, const GLchar *szVertShaderS
|
|||||||
glShaderSource(vertexShader, 2, vertSource, NULL);
|
glShaderSource(vertexShader, 2, vertSource, NULL);
|
||||||
glCompileShader(vertexShader);
|
glCompileShader(vertexShader);
|
||||||
|
|
||||||
|
// Report any compile issues to stderr
|
||||||
|
GLint logLength;
|
||||||
|
glGetShaderiv(vertexShader, GL_INFO_LOG_LENGTH, &logLength);
|
||||||
|
if (logLength > 0) {
|
||||||
|
GLchar *log = (GLchar *)malloc(logLength);
|
||||||
|
glGetShaderInfoLog(vertexShader, logLength, &logLength, log);
|
||||||
|
fprintf(stderr, "KREngine - Failed to compile vertex shader: %s\nShader compile log:\n%s", szKey, log);
|
||||||
|
free(log);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Create and compile vertex shader.
|
// Create and compile vertex shader.
|
||||||
fragShader = glCreateShader(GL_FRAGMENT_SHADER);
|
fragShader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||||
glShaderSource(fragShader, 2, fragSource, NULL);
|
glShaderSource(fragShader, 2, fragSource, NULL);
|
||||||
glCompileShader(fragShader);
|
glCompileShader(fragShader);
|
||||||
|
|
||||||
|
// Report any compile issues to stderr
|
||||||
|
glGetShaderiv(fragShader, GL_INFO_LOG_LENGTH, &logLength);
|
||||||
|
if (logLength > 0) {
|
||||||
|
GLchar *log = (GLchar *)malloc(logLength);
|
||||||
|
glGetShaderInfoLog(vertexShader, logLength, &logLength, log);
|
||||||
|
fprintf(stderr, "KREngine - Failed to compile fragment shader: %s\nShader compile log:\n%s", szKey, log);
|
||||||
|
free(log);
|
||||||
|
}
|
||||||
|
|
||||||
// Attach vertex shader to program.
|
// Attach vertex shader to program.
|
||||||
glAttachShader(m_iProgram, vertexShader);
|
glAttachShader(m_iProgram, vertexShader);
|
||||||
|
|
||||||
@@ -62,15 +82,25 @@ KRShader::KRShader(char *szKey, std::string options, const GLchar *szVertShaderS
|
|||||||
// This needs to be done prior to linking.
|
// This needs to be done prior to linking.
|
||||||
glBindAttribLocation(m_iProgram, KRENGINE_ATTRIB_VERTEX, "position");
|
glBindAttribLocation(m_iProgram, KRENGINE_ATTRIB_VERTEX, "position");
|
||||||
glBindAttribLocation(m_iProgram, KRENGINE_ATTRIB_TEXUVA, "inputTextureCoordinate");
|
glBindAttribLocation(m_iProgram, KRENGINE_ATTRIB_TEXUVA, "inputTextureCoordinate");
|
||||||
glBindAttribLocation(m_iProgram, KRENGINE_ATTRIB_TEXUVB, "shadowuv");
|
glBindAttribLocation(m_iProgram, KRENGINE_ATTRIB_TEXUVB, "vertex_lightmap_uv");
|
||||||
glBindAttribLocation(m_iProgram, KRENGINE_ATTRIB_VERTEX, "myVertex");
|
glBindAttribLocation(m_iProgram, KRENGINE_ATTRIB_VERTEX, "vertex_position");
|
||||||
glBindAttribLocation(m_iProgram, KRENGINE_ATTRIB_NORMAL, "myNormal");
|
glBindAttribLocation(m_iProgram, KRENGINE_ATTRIB_NORMAL, "vertex_normal");
|
||||||
glBindAttribLocation(m_iProgram, KRENGINE_ATTRIB_TANGENT, "myTangent");
|
glBindAttribLocation(m_iProgram, KRENGINE_ATTRIB_TANGENT, "vertex_tangent");
|
||||||
glBindAttribLocation(m_iProgram, KRENGINE_ATTRIB_TEXUVA, "myUV");
|
glBindAttribLocation(m_iProgram, KRENGINE_ATTRIB_TEXUVA, "vertex_uv");
|
||||||
|
|
||||||
// Link program.
|
// Link program.
|
||||||
glLinkProgram(m_iProgram);
|
glLinkProgram(m_iProgram);
|
||||||
|
|
||||||
|
// Report any linking issues to stderr
|
||||||
|
glGetProgramiv(m_iProgram, GL_INFO_LOG_LENGTH, &logLength);
|
||||||
|
if (logLength > 0)
|
||||||
|
{
|
||||||
|
GLchar *log = (GLchar *)malloc(logLength);
|
||||||
|
glGetProgramInfoLog(m_iProgram, logLength, &logLength, log);
|
||||||
|
fprintf(stderr, "KREngine - Failed to link shader program: %s\nProgram link log:\n%s", szKey, log);
|
||||||
|
free(log);
|
||||||
|
}
|
||||||
|
|
||||||
// Get uniform locations
|
// Get uniform locations
|
||||||
m_uniforms[KRENGINE_UNIFORM_MATERIAL_AMBIENT] = glGetUniformLocation(m_iProgram, "material_ambient");
|
m_uniforms[KRENGINE_UNIFORM_MATERIAL_AMBIENT] = glGetUniformLocation(m_iProgram, "material_ambient");
|
||||||
m_uniforms[KRENGINE_UNIFORM_MATERIAL_DIFFUSE] = glGetUniformLocation(m_iProgram, "material_diffuse");
|
m_uniforms[KRENGINE_UNIFORM_MATERIAL_DIFFUSE] = glGetUniformLocation(m_iProgram, "material_diffuse");
|
||||||
@@ -78,11 +108,11 @@ KRShader::KRShader(char *szKey, std::string options, const GLchar *szVertShaderS
|
|||||||
m_uniforms[KRENGINE_UNIFORM_MATERIAL_ALPHA] = glGetUniformLocation(m_iProgram, "material_alpha");
|
m_uniforms[KRENGINE_UNIFORM_MATERIAL_ALPHA] = glGetUniformLocation(m_iProgram, "material_alpha");
|
||||||
m_uniforms[KRENGINE_UNIFORM_MATERIAL_SHININESS] = glGetUniformLocation(m_iProgram, "material_shininess");
|
m_uniforms[KRENGINE_UNIFORM_MATERIAL_SHININESS] = glGetUniformLocation(m_iProgram, "material_shininess");
|
||||||
|
|
||||||
m_uniforms[KRENGINE_UNIFORM_MVP] = glGetUniformLocation(m_iProgram, "myMVPMatrix");
|
m_uniforms[KRENGINE_UNIFORM_MVP] = glGetUniformLocation(m_iProgram, "mvp_matrix");
|
||||||
m_uniforms[KRENGINE_UNIFORM_M2V] = glGetUniformLocation(m_iProgram, "model_to_view");
|
m_uniforms[KRENGINE_UNIFORM_M2V] = glGetUniformLocation(m_iProgram, "model_to_view_matrix");
|
||||||
m_uniforms[KRENGINE_UNIFORM_SHADOWMVP1] = glGetUniformLocation(m_iProgram, "myShadowMVPMatrix1");
|
m_uniforms[KRENGINE_UNIFORM_SHADOWMVP1] = glGetUniformLocation(m_iProgram, "shadow_mvp1");
|
||||||
m_uniforms[KRENGINE_UNIFORM_SHADOWMVP2] = glGetUniformLocation(m_iProgram, "myShadowMVPMatrix2");
|
m_uniforms[KRENGINE_UNIFORM_SHADOWMVP2] = glGetUniformLocation(m_iProgram, "shadow_mvp2");
|
||||||
m_uniforms[KRENGINE_UNIFORM_SHADOWMVP3] = glGetUniformLocation(m_iProgram, "myShadowMVPMatrix3");
|
m_uniforms[KRENGINE_UNIFORM_SHADOWMVP3] = glGetUniformLocation(m_iProgram, "shadow_mvp3");
|
||||||
m_uniforms[KRENGINE_UNIFORM_LIGHTDIRECTION] = glGetUniformLocation(m_iProgram, "lightDirection");
|
m_uniforms[KRENGINE_UNIFORM_LIGHTDIRECTION] = glGetUniformLocation(m_iProgram, "lightDirection");
|
||||||
m_uniforms[KRENGINE_UNIFORM_CAMERAPOS] = glGetUniformLocation(m_iProgram, "cameraPosition");
|
m_uniforms[KRENGINE_UNIFORM_CAMERAPOS] = glGetUniformLocation(m_iProgram, "cameraPosition");
|
||||||
|
|
||||||
@@ -104,6 +134,9 @@ KRShader::KRShader(char *szKey, std::string options, const GLchar *szVertShaderS
|
|||||||
m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE3] = glGetUniformLocation(m_iProgram, "shadowTexture3");
|
m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE3] = glGetUniformLocation(m_iProgram, "shadowTexture3");
|
||||||
|
|
||||||
|
|
||||||
|
m_uniforms[KRENGINE_UNIFORM_GBUFFER_FRAME] = glGetUniformLocation(m_iProgram, "gbuffer_frame");
|
||||||
|
m_uniforms[KRENGINE_UNIFORM_GBUFFER_DEPTH] = glGetUniformLocation(m_iProgram, "gbuffer_depth");
|
||||||
|
|
||||||
} catch(...) {
|
} catch(...) {
|
||||||
if(vertexShader) {
|
if(vertexShader) {
|
||||||
glDeleteShader(vertexShader);
|
glDeleteShader(vertexShader);
|
||||||
@@ -180,6 +213,9 @@ void KRShader::bind(KRCamera *pCamera, KRMat4 &matModelToView, KRMat4 &mvpMatrix
|
|||||||
glUniform1i(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE2], 4);
|
glUniform1i(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE2], 4);
|
||||||
glUniform1i(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE3], 5);
|
glUniform1i(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE3], 5);
|
||||||
|
|
||||||
|
glUniform1i(m_uniforms[KRENGINE_UNIFORM_GBUFFER_FRAME], 6);
|
||||||
|
glUniform1i(m_uniforms[KRENGINE_UNIFORM_GBUFFER_DEPTH], 7);
|
||||||
|
|
||||||
#if defined(DEBUG)
|
#if defined(DEBUG)
|
||||||
GLint logLength;
|
GLint logLength;
|
||||||
|
|
||||||
@@ -189,7 +225,7 @@ void KRShader::bind(KRCamera *pCamera, KRMat4 &matModelToView, KRMat4 &mvpMatrix
|
|||||||
{
|
{
|
||||||
GLchar *log = (GLchar *)malloc(logLength);
|
GLchar *log = (GLchar *)malloc(logLength);
|
||||||
glGetProgramInfoLog(m_iProgram, logLength, &logLength, log);
|
glGetProgramInfoLog(m_iProgram, logLength, &logLength, log);
|
||||||
fprintf(stderr, "Program validate log:\n%s", log);
|
fprintf(stderr, "KREngine - Failed to validate shader program: %s\n Program validate log:\n%s", m_szKey, log);
|
||||||
free(log);
|
free(log);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -89,6 +89,8 @@ public:
|
|||||||
KRENGINE_UNIFORM_SHADOWTEXTURE1,
|
KRENGINE_UNIFORM_SHADOWTEXTURE1,
|
||||||
KRENGINE_UNIFORM_SHADOWTEXTURE2,
|
KRENGINE_UNIFORM_SHADOWTEXTURE2,
|
||||||
KRENGINE_UNIFORM_SHADOWTEXTURE3,
|
KRENGINE_UNIFORM_SHADOWTEXTURE3,
|
||||||
|
KRENGINE_UNIFORM_GBUFFER_FRAME,
|
||||||
|
KRENGINE_UNIFORM_GBUFFER_DEPTH,
|
||||||
|
|
||||||
KRENGINE_NUM_UNIFORMS
|
KRENGINE_NUM_UNIFORMS
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -25,213 +25,238 @@
|
|||||||
// or implied, of Kearwood Gilbert.
|
// or implied, of Kearwood Gilbert.
|
||||||
//
|
//
|
||||||
|
|
||||||
uniform lowp vec3 material_ambient, material_diffuse, material_specular;
|
|
||||||
uniform lowp float material_alpha;
|
#if ENABLE_PER_PIXEL == 1 || GBUFFER_PASS == 1
|
||||||
|
uniform mediump float material_shininess;
|
||||||
|
#if HAS_NORMAL_MAP == 1
|
||||||
|
uniform sampler2D normalTexture;
|
||||||
|
#else
|
||||||
|
varying mediump vec3 normal;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if HAS_DIFFUSE_MAP == 1 || HAS_NORMAL_MAP == 1 || HAS_SPEC_MAP == 1
|
||||||
|
varying highp vec2 texCoord;
|
||||||
|
#endif
|
||||||
|
#if HAS_NORMAL_MAP_OFFSET == 1 || HAS_NORMAL_MAP_SCALE == 1
|
||||||
|
varying highp vec2 normal_uv;
|
||||||
|
#else
|
||||||
|
#define normal_uv texCoord
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#if HAS_DIFFUSE_MAP == 1
|
||||||
|
varying highp vec2 texCoord;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if GBUFFER_PASS == 2 || GBUFFER_PASS == 3
|
||||||
|
uniform sampler2D gbuffer_frame;
|
||||||
|
uniform sampler2D gbuffer_depth;
|
||||||
|
|
||||||
|
varying mediump vec2 gbuffer_uv;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if GBUFFER_PASS == 1
|
#if GBUFFER_PASS == 1
|
||||||
#if HAS_NORMAL_MAP == 1
|
#if HAS_NORMAL_MAP == 1
|
||||||
varying highp mat3 tangent_to_view;
|
varying highp mat3 tangent_to_view_matrix;
|
||||||
|
#else
|
||||||
|
uniform highp mat4 model_to_view_matrix;
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
uniform highp mat4 model_to_view;
|
uniform lowp vec3 material_ambient, material_diffuse, material_specular;
|
||||||
#endif
|
uniform lowp float material_alpha;
|
||||||
#endif
|
|
||||||
|
|
||||||
|
#if HAS_DIFFUSE_MAP == 1
|
||||||
|
uniform sampler2D diffuseTexture;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if HAS_SPEC_MAP == 1
|
||||||
|
uniform sampler2D specularTexture;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if ENABLE_PER_PIXEL == 1
|
#if SHADOW_QUALITY >= 1
|
||||||
uniform mediump float material_shininess;
|
uniform sampler2D shadowTexture1;
|
||||||
#endif
|
varying highp vec4 shadowMapCoord1;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if HAS_DIFFUSE_MAP == 1
|
#if HAS_LIGHT_MAP == 1
|
||||||
uniform sampler2D diffuseTexture;
|
uniform sampler2D shadowTexture1;
|
||||||
#endif
|
varying mediump vec2 lightmap_uv;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if HAS_SPEC_MAP == 1
|
#if SHADOW_QUALITY >= 2
|
||||||
uniform sampler2D specularTexture;
|
uniform sampler2D shadowTexture2;
|
||||||
#endif
|
varying highp vec4 shadowMapCoord2;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if HAS_NORMAL_MAP == 1 && ENABLE_PER_PIXEL == 1
|
#if SHADOW_QUALITY >= 3
|
||||||
uniform sampler2D normalTexture;
|
uniform sampler2D shadowTexture3;
|
||||||
#endif
|
varying highp vec4 shadowMapCoord3;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if SHADOW_QUALITY >= 1
|
#if ENABLE_PER_PIXEL == 1
|
||||||
uniform sampler2D shadowTexture1;
|
varying mediump vec3 lightVec;
|
||||||
varying highp vec4 shadowMapCoord1;
|
varying mediump vec3 halfVec;
|
||||||
#endif
|
#else
|
||||||
|
varying mediump float lamberFactor;
|
||||||
|
varying mediump float specularFactor;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if HAS_LIGHT_MAP == 1
|
#if (HAS_SPEC_MAP_OFFSET == 1|| HAS_SPEC_MAP_SCALE == 1) && ENABLE_PER_PIXEL == 1
|
||||||
uniform sampler2D shadowTexture1;
|
varying mediump vec2 spec_uv;
|
||||||
varying mediump vec2 shadowCoord;
|
#else
|
||||||
#endif
|
#define spec_uv texCoord
|
||||||
|
#endif
|
||||||
|
|
||||||
#if SHADOW_QUALITY >= 2
|
#if HAS_DIFFUSE_MAP_OFFSET == 1 || HAS_DIFFUSE_MAP_SCALE == 1
|
||||||
uniform sampler2D shadowTexture2;
|
varying highp vec2 diffuse_uv;
|
||||||
varying highp vec4 shadowMapCoord2;
|
#else
|
||||||
#endif
|
#define diffuse_uv texCoord
|
||||||
|
#endif
|
||||||
|
|
||||||
#if SHADOW_QUALITY >= 3
|
|
||||||
uniform sampler2D shadowTexture3;
|
|
||||||
varying highp vec4 shadowMapCoord3;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if HAS_DIFFUSE_MAP == 1 || (HAS_NORMAL_MAP == 1 && ENABLE_PER_PIXEL == 1) || HAS_SPEC_MAP == 1
|
|
||||||
varying highp vec2 texCoord;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if HAS_NORMAL_MAP == 0 && ENABLE_PER_PIXEL == 1
|
|
||||||
varying mediump vec3 normal;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if ENABLE_PER_PIXEL == 1
|
|
||||||
varying mediump vec3 lightVec;
|
|
||||||
varying mediump vec3 halfVec;
|
|
||||||
#else
|
|
||||||
varying mediump float lamberFactor;
|
|
||||||
varying mediump float specularFactor;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#if (HAS_NORMAL_MAP_OFFSET == 1 || HAS_NORMAL_MAP_SCALE == 1) && ENABLE_PER_PIXEL == 1
|
|
||||||
varying highp vec2 normal_uv;
|
|
||||||
#else
|
|
||||||
#define normal_uv texCoord
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if (HAS_SPEC_MAP_OFFSET == 1|| HAS_SPEC_MAP_SCALE == 1) && ENABLE_PER_PIXEL == 1
|
|
||||||
varying mediump vec2 spec_uv;
|
|
||||||
#else
|
|
||||||
#define spec_uv texCoord
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if HAS_DIFFUSE_MAP_OFFSET == 1 || HAS_DIFFUSE_MAP_SCALE == 1
|
|
||||||
varying highp vec2 diffuse_uv;
|
|
||||||
#else
|
|
||||||
#define diffuse_uv texCoord
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
#if HAS_NORMAL_MAP == 1 && ENABLE_PER_PIXEL == 1
|
#if GBUFFER_PASS == 2
|
||||||
// lookup normal from normal map, move from [0,1] to [-1, 1] range, normalize
|
lowp vec4 gbuffer_sample = texture2D(gbuffer_frame, gbuffer_uv);
|
||||||
mediump vec3 normal = normalize(2.0 * texture2D(normalTexture,normal_uv).rgb - 1.0);
|
mediump vec3 gbuffer_normal = normalize(2.0 * gbuffer_sample.rgb - 1.0);
|
||||||
#endif
|
mediump float gbuffer_specular_exponent = gbuffer_sample.a;
|
||||||
|
|
||||||
#if ENABLE_PER_PIXEL == 1
|
|
||||||
mediump float lamberFactor = max(0.0,dot(lightVec, normal));
|
|
||||||
mediump float specularFactor = 0.0;
|
|
||||||
if(material_shininess > 0.0) {
|
|
||||||
specularFactor = max(0.0,pow(dot(halfVec,normal), material_shininess));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if HAS_DIFFUSE_MAP == 1
|
|
||||||
mediump vec4 diffuseMaterial = vec4(vec3(texture2D(diffuseTexture, diffuse_uv)), material_alpha);
|
|
||||||
#else
|
|
||||||
mediump vec4 diffuseMaterial = vec4(vec3(1.0), material_alpha);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if SHADOW_QUALITY == 1
|
|
||||||
highp float shadowMapDepth = 1.0;
|
|
||||||
highp float vertexShadowDepth = 1.0;
|
|
||||||
highp vec2 shadowMapPos = ((shadowMapCoord1 / shadowMapCoord1.w + 1.0) / 2.0).st;
|
|
||||||
|
|
||||||
if(shadowMapCoord1.x >= -1.0 && shadowMapCoord1.x <= 1.0 && shadowMapCoord1.y >= -1.0 && shadowMapCoord1.y <= 1.0 && shadowMapCoord1.z >= 0.0 && shadowMapCoord1.z <= 1.0) {
|
|
||||||
#if DEBUG_PSSM == 1
|
|
||||||
diffuseMaterial = diffuseMaterial * vec4(0.75, 0.75, 0.5, 1.0) + vec4(0.0, 0.0, 0.5, 0.0);
|
|
||||||
#endif
|
|
||||||
shadowMapDepth = texture2D(shadowTexture1, shadowMapPos).z;
|
|
||||||
vertexShadowDepth = ((shadowMapCoord1 / shadowMapCoord1.w + 1.0) / 2.0).z;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if SHADOW_QUALITY >= 2
|
|
||||||
|
|
||||||
highp float shadowMapDepth = 1.0;
|
|
||||||
highp float vertexShadowDepth = 1.0;
|
|
||||||
|
|
||||||
if(shadowMapCoord1.x >= -1.0 && shadowMapCoord1.x <= 1.0 && shadowMapCoord1.y >= -1.0 && shadowMapCoord1.y <= 1.0 && shadowMapCoord1.z >= 0.0 && shadowMapCoord1.z <= 1.0) {
|
|
||||||
#if DEBUG_PSSM == 1
|
|
||||||
diffuseMaterial = diffuseMaterial * vec4(0.75, 0.75, 0.5, 1.0) + vec4(0.0, 0.0, 0.5, 0.0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
highp vec2 shadowMapPos = ((shadowMapCoord1 / shadowMapCoord1.w + 1.0) / 2.0).st;
|
|
||||||
shadowMapDepth = texture2D(shadowTexture1, shadowMapPos).z;
|
|
||||||
vertexShadowDepth = ((shadowMapCoord1 / shadowMapCoord1.w + 1.0) / 2.0).z;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if(shadowMapCoord2.s >= -1.0 && shadowMapCoord2.s <= 1.0 && shadowMapCoord2.t >= -1.0 && shadowMapCoord2.t <= 1.0 && shadowMapCoord2.z >= 0.0 && shadowMapCoord2.z <= 1.0) {
|
|
||||||
#if DEBUG_PSSM == 1
|
|
||||||
diffuseMaterial = diffuseMaterial * vec4(0.75, 0.50, 0.75, 1.0) + vec4(0.0, 0.5, 0.0, 0.0);
|
|
||||||
#endif
|
|
||||||
highp vec2 shadowMapPos = ((shadowMapCoord2 / shadowMapCoord2.w + 1.0) / 2.0).st;
|
|
||||||
shadowMapDepth = texture2D(shadowTexture2, shadowMapPos).z;
|
|
||||||
vertexShadowDepth = ((shadowMapCoord2 / shadowMapCoord2.w + 1.0) / 2.0).z;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if SHADOW_QUALITY >= 3
|
|
||||||
|
|
||||||
else if(shadowMapCoord3.s >= -1.0 && shadowMapCoord3.s <= 1.0 && shadowMapCoord3.t >= -1.0 && shadowMapCoord3.t <= 1.0 && shadowMapCoord3.z >= 0.0 && shadowMapCoord3.z <= 1.0) {
|
|
||||||
#if DEBUG_PSSM == 1
|
|
||||||
diffuseMaterial = diffuseMaterial * vec4(0.50, 0.75, 0.75, 1.0) + vec4(0.5, 0.0, 0.0, 0.0);
|
|
||||||
#endif
|
|
||||||
highp vec2 shadowMapPos = ((shadowMapCoord3 / shadowMapCoord3.w + 1.0) / 2.0).st;
|
|
||||||
shadowMapDepth = texture2D(shadowTexture3, shadowMapPos).z;
|
|
||||||
vertexShadowDepth = ((shadowMapCoord3 / shadowMapCoord3.w + 1.0) / 2.0).z;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if SHADOW_QUALITY >= 1
|
|
||||||
if(vertexShadowDepth >= shadowMapDepth && shadowMapDepth < 1.0) {
|
|
||||||
lamberFactor = 0.0;
|
|
||||||
specularFactor = 0.0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#if GBUFFER_PASS == 0 || GBUFFER_PASS == 2
|
|
||||||
|
|
||||||
#if ENABLE_AMBIENT
|
|
||||||
// -------------------- Add ambient light and alpha component --------------------
|
|
||||||
gl_FragColor = vec4(vec3(diffuseMaterial) * material_ambient, material_alpha);
|
|
||||||
#else
|
|
||||||
gl_FragColor = vec4(0.0, 0.0, 0.0, material_alpha);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ENABLE_DIFFUSE
|
|
||||||
// -------------------- Add diffuse light --------------------
|
|
||||||
gl_FragColor += vec4(vec3(diffuseMaterial) * material_diffuse * lamberFactor, 0.0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if ENABLE_SPECULAR
|
|
||||||
|
|
||||||
// -------------------- Add specular light --------------------
|
|
||||||
#if HAS_SPEC_MAP == 1
|
|
||||||
gl_FragColor += vec4(material_specular * vec3(texture2D(specularTexture, spec_uv)) * specularFactor, 0.0);
|
|
||||||
#else
|
|
||||||
gl_FragColor += vec4(material_specular * specularFactor, 0.0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
// -------------------- Multiply light map --------------------
|
|
||||||
|
|
||||||
#if HAS_LIGHT_MAP
|
|
||||||
mediump vec3 shadowColor = vec3(texture2D(shadowTexture1, shadowCoord));
|
|
||||||
gl_FragColor = vec4(gl_FragColor.r * shadowColor.r, gl_FragColor.g * shadowColor.g, gl_FragColor.b * shadowColor.b, 1.0);
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if GBUFFER_PASS == 1
|
#if GBUFFER_PASS == 3
|
||||||
#if HAS_NORMAL_MAP == 1
|
lowp vec4 gbuffer_sample = texture2D(gbuffer_frame, gbuffer_uv);
|
||||||
mediump vec3 view_space_normal = tangent_to_view * normal;
|
lowp vec3 gbuffer_lamber_factor = gbuffer_sample.rgb;
|
||||||
#else
|
lowp float gbuffer_specular_factor = gbuffer_sample.a;
|
||||||
mediump vec3 view_space_normal = vec3(model_to_view * vec4(normal, 1.0));
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if GBUFFER_PASS == 1
|
||||||
|
#if HAS_NORMAL_MAP == 1
|
||||||
|
// lookup normal from normal map, move from [0,1] to [-1, 1] range, normalize
|
||||||
|
mediump vec3 normal = normalize(2.0 * texture2D(normalTexture,normal_uv).rgb - 1.0);
|
||||||
|
mediump vec3 view_space_normal = tangent_to_view_matrix * normal;
|
||||||
|
#else
|
||||||
|
mediump vec3 view_space_normal = vec3(model_to_view_matrix * vec4(normal, 1.0));
|
||||||
|
#endif
|
||||||
gl_FragColor = vec4(view_space_normal * 0.5 + 0.5, material_shininess / 100.0);
|
gl_FragColor = vec4(view_space_normal * 0.5 + 0.5, material_shininess / 100.0);
|
||||||
|
#else
|
||||||
|
#if HAS_DIFFUSE_MAP == 1
|
||||||
|
mediump vec4 diffuseMaterial = vec4(vec3(texture2D(diffuseTexture, diffuse_uv)), material_alpha);
|
||||||
|
#else
|
||||||
|
mediump vec4 diffuseMaterial = vec4(vec3(1.0), material_alpha);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if ENABLE_PER_PIXEL == 1
|
||||||
|
#if HAS_NORMAL_MAP == 1
|
||||||
|
// lookup normal from normal map, move from [0,1] to [-1, 1] range, normalize
|
||||||
|
mediump vec3 normal = normalize(2.0 * texture2D(normalTexture,normal_uv).rgb - 1.0);
|
||||||
|
#endif
|
||||||
|
mediump float lamberFactor = max(0.0,dot(lightVec, normal));
|
||||||
|
mediump float specularFactor = 0.0;
|
||||||
|
if(material_shininess > 0.0) {
|
||||||
|
specularFactor = max(0.0,pow(dot(halfVec,normal), material_shininess));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if SHADOW_QUALITY == 1
|
||||||
|
highp float shadowMapDepth = 1.0;
|
||||||
|
highp float vertexShadowDepth = 1.0;
|
||||||
|
highp vec2 shadowMapPos = ((shadowMapCoord1 / shadowMapCoord1.w + 1.0) / 2.0).st;
|
||||||
|
|
||||||
|
if(shadowMapCoord1.x >= -1.0 && shadowMapCoord1.x <= 1.0 && shadowMapCoord1.y >= -1.0 && shadowMapCoord1.y <= 1.0 && shadowMapCoord1.z >= 0.0 && shadowMapCoord1.z <= 1.0) {
|
||||||
|
#if DEBUG_PSSM == 1
|
||||||
|
diffuseMaterial = diffuseMaterial * vec4(0.75, 0.75, 0.5, 1.0) + vec4(0.0, 0.0, 0.5, 0.0);
|
||||||
|
#endif
|
||||||
|
shadowMapDepth = texture2D(shadowTexture1, shadowMapPos).z;
|
||||||
|
vertexShadowDepth = ((shadowMapCoord1 / shadowMapCoord1.w + 1.0) / 2.0).z;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if SHADOW_QUALITY >= 2
|
||||||
|
|
||||||
|
highp float shadowMapDepth = 1.0;
|
||||||
|
highp float vertexShadowDepth = 1.0;
|
||||||
|
|
||||||
|
if(shadowMapCoord1.x >= -1.0 && shadowMapCoord1.x <= 1.0 && shadowMapCoord1.y >= -1.0 && shadowMapCoord1.y <= 1.0 && shadowMapCoord1.z >= 0.0 && shadowMapCoord1.z <= 1.0) {
|
||||||
|
#if DEBUG_PSSM == 1
|
||||||
|
diffuseMaterial = diffuseMaterial * vec4(0.75, 0.75, 0.5, 1.0) + vec4(0.0, 0.0, 0.5, 0.0);
|
||||||
|
#endif
|
||||||
|
highp vec2 shadowMapPos = ((shadowMapCoord1 / shadowMapCoord1.w + 1.0) / 2.0).st;
|
||||||
|
shadowMapDepth = texture2D(shadowTexture1, shadowMapPos).z;
|
||||||
|
vertexShadowDepth = ((shadowMapCoord1 / shadowMapCoord1.w + 1.0) / 2.0).z;
|
||||||
|
} else if(shadowMapCoord2.s >= -1.0 && shadowMapCoord2.s <= 1.0 && shadowMapCoord2.t >= -1.0 && shadowMapCoord2.t <= 1.0 && shadowMapCoord2.z >= 0.0 && shadowMapCoord2.z <= 1.0) {
|
||||||
|
#if DEBUG_PSSM == 1
|
||||||
|
diffuseMaterial = diffuseMaterial * vec4(0.75, 0.50, 0.75, 1.0) + vec4(0.0, 0.5, 0.0, 0.0);
|
||||||
|
#endif
|
||||||
|
highp vec2 shadowMapPos = ((shadowMapCoord2 / shadowMapCoord2.w + 1.0) / 2.0).st;
|
||||||
|
shadowMapDepth = texture2D(shadowTexture2, shadowMapPos).z;
|
||||||
|
vertexShadowDepth = ((shadowMapCoord2 / shadowMapCoord2.w + 1.0) / 2.0).z;
|
||||||
|
}
|
||||||
|
#if SHADOW_QUALITY >= 3
|
||||||
|
else if(shadowMapCoord3.s >= -1.0 && shadowMapCoord3.s <= 1.0 && shadowMapCoord3.t >= -1.0 && shadowMapCoord3.t <= 1.0 && shadowMapCoord3.z >= 0.0 && shadowMapCoord3.z <= 1.0) {
|
||||||
|
#if DEBUG_PSSM == 1
|
||||||
|
diffuseMaterial = diffuseMaterial * vec4(0.50, 0.75, 0.75, 1.0) + vec4(0.5, 0.0, 0.0, 0.0);
|
||||||
|
#endif
|
||||||
|
highp vec2 shadowMapPos = ((shadowMapCoord3 / shadowMapCoord3.w + 1.0) / 2.0).st;
|
||||||
|
shadowMapDepth = texture2D(shadowTexture3, shadowMapPos).z;
|
||||||
|
vertexShadowDepth = ((shadowMapCoord3 / shadowMapCoord3.w + 1.0) / 2.0).z;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if SHADOW_QUALITY >= 1
|
||||||
|
if(vertexShadowDepth >= shadowMapDepth && shadowMapDepth < 1.0) {
|
||||||
|
lamberFactor = 0.0;
|
||||||
|
specularFactor = 0.0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if ENABLE_AMBIENT
|
||||||
|
// -------------------- Add ambient light and alpha component --------------------
|
||||||
|
gl_FragColor = vec4(vec3(diffuseMaterial) * material_ambient, material_alpha);
|
||||||
|
#else
|
||||||
|
gl_FragColor = vec4(0.0, 0.0, 0.0, material_alpha);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if ENABLE_DIFFUSE
|
||||||
|
// -------------------- Add diffuse light --------------------
|
||||||
|
gl_FragColor += vec4(vec3(diffuseMaterial) * material_diffuse * lamberFactor, 0.0);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if ENABLE_SPECULAR
|
||||||
|
|
||||||
|
// -------------------- Add specular light --------------------
|
||||||
|
#if HAS_SPEC_MAP == 1 && ENABLE_PER_PIXEL == 1
|
||||||
|
gl_FragColor += vec4(material_specular * vec3(texture2D(specularTexture, spec_uv)) * specularFactor, 0.0);
|
||||||
|
#else
|
||||||
|
gl_FragColor += vec4(material_specular * specularFactor, 0.0);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// -------------------- Multiply light map --------------------
|
||||||
|
|
||||||
|
#if HAS_LIGHT_MAP
|
||||||
|
mediump vec3 lightMapColor = vec3(texture2D(shadowTexture1, lightmap_uv));
|
||||||
|
gl_FragColor = vec4(gl_FragColor.r * lightMapColor.r, gl_FragColor.g * lightMapColor.g, gl_FragColor.b * lightMapColor.b, 1.0);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if GBUFFER_PASS == 2
|
||||||
|
// mediump vec3 gbuffer_normal = normalize(2.0 * gbuffer_sample.rgb - 1.0);
|
||||||
|
// mediump float gbuffer_specular_exponent = gbuffer_sample.a;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if GBUFFER_PASS == 3
|
||||||
|
// lowp vec3 gbuffer_lamber_factor = gbuffer_sample.rgb;
|
||||||
|
// lowp float gbuffer_specular_factor = gbuffer_sample.a;
|
||||||
|
|
||||||
|
gl_FragColor = vec4(vec3(gbuffer_lamber_factor), 1.0);
|
||||||
|
gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,204 +29,210 @@
|
|||||||
// or implied, of Kearwood Gilbert.
|
// or implied, of Kearwood Gilbert.
|
||||||
//
|
//
|
||||||
|
|
||||||
attribute highp vec3 myVertex, myNormal;
|
attribute highp vec3 vertex_position, vertex_normal, vertex_tangent;
|
||||||
attribute highp vec3 myTangent;
|
attribute mediump vec2 vertex_uv;
|
||||||
attribute mediump vec2 myUV;
|
uniform highp mat4 mvp_matrix; // mvp_matrix is the result of multiplying the model, view, and projection matrices
|
||||||
attribute mediump vec2 shadowuv;
|
|
||||||
uniform highp mat4 myMVPMatrix, myShadowMVPMatrix1,myShadowMVPMatrix2,myShadowMVPMatrix3; // mvpmatrix is the result of multiplying the model, view, and projection matrices
|
|
||||||
|
|
||||||
#if GBUFFER_PASS == 1 && HAS_NORMAL_MAP == 1
|
#if ENABLE_PER_PIXEL == 1 || GBUFFER_PASS == 1
|
||||||
uniform highp mat4 model_to_view;
|
#if HAS_DIFFUSE_MAP == 1 || HAS_NORMAL_MAP == 1 || HAS_SPEC_MAP == 1
|
||||||
varying highp mat3 tangent_to_view;
|
varying highp vec2 texCoord;
|
||||||
|
#endif
|
||||||
|
#if HAS_NORMAL_MAP == 1
|
||||||
|
#if HAS_NORMAL_MAP_SCALE == 1
|
||||||
|
uniform highp vec2 normalTexture_Scale;
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#if HAS_NORMAL_MAP_OFFSET == 1
|
||||||
|
uniform highp vec2 normalTexture_Offset;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if HAS_NORMAL_MAP_OFFSET == 1 || HAS_NORMAL_MAP_SCALE == 1
|
||||||
// uniform lowp vec3 material_ambient, material_diffuse, material_specular;
|
varying highp vec2 normal_uv;
|
||||||
uniform highp vec3 lightDirection; // Must be normalized before entering shader
|
#endif
|
||||||
uniform highp vec3 cameraPosition;
|
#else
|
||||||
|
varying mediump vec3 normal;
|
||||||
#if ENABLE_PER_PIXEL == 0
|
#endif
|
||||||
uniform mediump float material_shininess;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if HAS_DIFFUSE_MAP == 1 || (HAS_NORMAL_MAP == 1 && ENABLE_PER_PIXEL == 1) || HAS_SPEC_MAP == 1
|
|
||||||
varying highp vec2 texCoord;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if HAS_LIGHT_MAP == 1
|
|
||||||
varying mediump vec2 shadowCoord;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#if ENABLE_PER_PIXEL == 1
|
|
||||||
varying mediump vec3 lightVec;
|
|
||||||
varying mediump vec3 halfVec;
|
|
||||||
#else
|
#else
|
||||||
varying mediump float lamberFactor;
|
uniform mediump float material_shininess;
|
||||||
varying mediump float specularFactor;
|
#if HAS_DIFFUSE_MAP == 1
|
||||||
|
varying highp vec2 texCoord;
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if HAS_DIFFUSE_MAP_SCALE == 1
|
#if GBUFFER_PASS == 2 || GBUFFER_PASS == 3
|
||||||
uniform highp vec2 diffuseTexture_Scale;
|
varying mediump vec2 gbuffer_uv;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if HAS_NORMAL_MAP_SCALE == 1
|
#if GBUFFER_PASS == 1
|
||||||
uniform highp vec2 normalTexture_Scale;
|
#if HAS_NORMAL_MAP == 1
|
||||||
|
uniform highp mat4 model_to_view_matrix;
|
||||||
|
varying highp mat3 tangent_to_view_matrix;
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
|
||||||
|
uniform highp vec3 lightDirection; // Must be normalized before entering shader
|
||||||
|
uniform highp vec3 cameraPosition;
|
||||||
|
|
||||||
|
#if HAS_LIGHT_MAP == 1
|
||||||
|
attribute mediump vec2 vertex_lightmap_uv;
|
||||||
|
varying mediump vec2 lightmap_uv;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if ENABLE_PER_PIXEL == 1
|
||||||
|
varying mediump vec3 lightVec;
|
||||||
|
varying mediump vec3 halfVec;
|
||||||
|
|
||||||
|
#if HAS_SPEC_MAP_OFFSET == 1 || HAS_SPEC_MAP_SCALE == 1
|
||||||
|
varying highp vec2 spec_uv;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if HAS_SPEC_MAP_SCALE == 1
|
||||||
|
uniform highp vec2 specularTexture_Scale;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if HAS_SPEC_MAP_OFFSET == 1
|
||||||
|
uniform highp vec2 specularTexture_Offset;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if SHADOW_QUALITY >= 1
|
||||||
|
uniform highp mat4 shadow_mvp1;
|
||||||
|
varying highp vec4 shadowMapCoord1;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if SHADOW_QUALITY >= 2
|
||||||
|
uniform highp mat4 shadow_mvp2;
|
||||||
|
varying highp vec4 shadowMapCoord2;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if SHADOW_QUALITY >= 3
|
||||||
|
uniform highp mat4 shadow_mvp3;
|
||||||
|
varying highp vec4 shadowMapCoord3;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#else
|
||||||
|
varying mediump float lamberFactor;
|
||||||
|
varying mediump float specularFactor;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if HAS_DIFFUSE_MAP_SCALE == 1
|
||||||
|
uniform highp vec2 diffuseTexture_Scale;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if HAS_DIFFUSE_MAP_OFFSET == 1
|
||||||
|
uniform highp vec2 diffuseTexture_Offset;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if HAS_DIFFUSE_MAP_OFFSET == 1 || HAS_DIFFUSE_MAP_SCALE == 1
|
||||||
|
varying highp vec2 diffuse_uv;
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if HAS_SPEC_MAP_SCALE == 1
|
|
||||||
uniform highp vec2 specularTexture_Scale;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if HAS_NORMAL_MAP_OFFSET == 1
|
|
||||||
uniform highp vec2 normalTexture_Offset;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if HAS_SPEC_MAP_OFFSET == 1
|
|
||||||
uniform highp vec2 specularTexture_Offset;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if HAS_DIFFUSE_MAP_OFFSET == 1
|
|
||||||
uniform highp vec2 diffuseTexture_Offset;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if HAS_NORMAL_MAP == 0 && ENABLE_PER_PIXEL == 1
|
|
||||||
varying mediump vec3 normal;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if SHADOW_QUALITY >= 1
|
|
||||||
varying highp vec4 shadowMapCoord1;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if SHADOW_QUALITY >= 2
|
|
||||||
varying highp vec4 shadowMapCoord2;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if SHADOW_QUALITY >= 3
|
|
||||||
varying highp vec4 shadowMapCoord3;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if (HAS_NORMAL_MAP_OFFSET == 1 || HAS_NORMAL_MAP_SCALE == 1) && ENABLE_PER_PIXEL == 1
|
|
||||||
varying highp vec2 normal_uv;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if (HAS_SPEC_MAP_OFFSET == 1|| HAS_SPEC_MAP_SCALE == 1) && ENABLE_PER_PIXEL == 1
|
|
||||||
varying highp vec2 spec_uv;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if HAS_DIFFUSE_MAP_OFFSET == 1 || HAS_DIFFUSE_MAP_SCALE == 1
|
|
||||||
varying highp vec2 diffuse_uv;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
// Transform position
|
// Transform position
|
||||||
gl_Position = myMVPMatrix * vec4(myVertex,1.0);
|
gl_Position = mvp_matrix * vec4(vertex_position,1.0);
|
||||||
|
|
||||||
|
#if GBUFFER_PASS == 2 || GBUFFER_PASS == 3
|
||||||
|
gbuffer_uv = gl_Position.xy;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if HAS_DIFFUSE_MAP == 1 || (HAS_NORMAL_MAP == 1 && ENABLE_PER_PIXEL == 1) || (HAS_SPEC_MAP == 1 && ENABLE_PER_PIXEL == 1)
|
||||||
|
// Pass UV co-ordinates
|
||||||
|
texCoord = vertex_uv.st;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// Scaled and translated normal map UV's
|
||||||
#if HAS_DIFFUSE_MAP == 1 || (HAS_NORMAL_MAP == 1 && ENABLE_PER_PIXEL == 1) || HAS_SPEC_MAP == 1
|
#if (HAS_NORMAL_MAP_OFFSET == 1 || HAS_NORMAL_MAP_SCALE == 1) && ENABLE_PER_PIXEL == 1
|
||||||
// Pass UV co-ordinates
|
normal_uv = texCoord;
|
||||||
texCoord = myUV.st;
|
|
||||||
#endif
|
#if HAS_NORMAL_MAP_OFFSET == 1
|
||||||
|
normal_uv + normalTexture_Offset;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if HAS_NORMAL_MAP_SCALE == 1
|
||||||
|
normal_uv *= normalTexture_Scale;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
// Scaled and translated normal map UV's
|
#if GBUFFER_PASS == 1
|
||||||
#if (HAS_NORMAL_MAP_OFFSET == 1 || HAS_NORMAL_MAP_SCALE == 1) && ENABLE_PER_PIXEL == 1
|
#if HAS_NORMAL_MAP == 1
|
||||||
normal_uv = texCoord;
|
mediump vec3 a_bitangent = cross(vertex_normal, vertex_tangent);
|
||||||
|
tangent_to_view_matrix[0] = vec3(model_to_view_matrix * vec4(vertex_tangent, 1.0));
|
||||||
|
tangent_to_view_matrix[1] = vec3(model_to_view_matrix * vec4(a_bitangent, 1.0));
|
||||||
|
tangent_to_view_matrix[2] = vec3(model_to_view_matrix * vec4(vertex_normal, 1.0));
|
||||||
|
#else
|
||||||
|
normal = vertex_normal;
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#if HAS_LIGHT_MAP == 1
|
||||||
|
// Pass shadow UV co-ordinates
|
||||||
|
lightmap_uv = vertex_lightmap_uv.st;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if HAS_NORMAL_MAP_OFFSET == 1
|
// Scaled and translated diffuse map UV's
|
||||||
normal_uv + normalTexture_Offset;
|
#if HAS_DIFFUSE_MAP_OFFSET == 1 || HAS_DIFFUSE_MAP_SCALE == 1
|
||||||
#endif
|
diffuse_uv = texCoord;
|
||||||
|
|
||||||
#if HAS_NORMAL_MAP_SCALE == 1
|
#if HAS_DIFFUSE_MAP_OFFSET == 1
|
||||||
normal_uv *= normalTexture_Scale;
|
diffuse_uv + diffuseTexture_Offset;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#if HAS_DIFFUSE_MAP_SCALE == 1
|
||||||
|
diffuse_uv *= diffuseTexture_Scale;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if ENABLE_PER_PIXEL == 1
|
||||||
// Scaled and translated diffuse map UV's
|
// Scaled and translated specular map UV's
|
||||||
#if HAS_DIFFUSE_MAP_OFFSET == 1 || HAS_DIFFUSE_MAP_SCALE == 1
|
#if (HAS_SPEC_MAP_OFFSET == 1 || HAS_SPEC_MAP_SCALE == 1) && ENABLE_PER_PIXEL == 1
|
||||||
diffuse_uv = texCoord;
|
spec_uv = texCoord;
|
||||||
|
#if HAS_SPEC_MAP_OFFSET == 1
|
||||||
#if HAS_DIFFUSE_MAP_OFFSET == 1
|
spec_uv + specularTexture_Offset;
|
||||||
diffuse_uv + diffuseTexture_Offset;
|
#endif
|
||||||
#endif
|
|
||||||
|
#if HAS_SPEC_MAP_SCALE == 1
|
||||||
#if HAS_DIFFUSE_MAP_SCALE == 1
|
spec_uv *= specularTexture_Scale;
|
||||||
diffuse_uv *= diffuseTexture_Scale;
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
|
||||||
|
#if SHADOW_QUALITY >= 1
|
||||||
|
shadowMapCoord1 = shadow_mvp1 * vec4(vertex_position,1.0);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if SHADOW_QUALITY >= 2
|
||||||
|
shadowMapCoord2 = shadow_mvp2 * vec4(vertex_position,1.0);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if SHADOW_QUALITY >= 3
|
||||||
|
shadowMapCoord3 = shadow_mvp3 * vec4(vertex_position,1.0);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ----------- Directional Light (Sun) -----------
|
||||||
// Scaled and translated specular map UV's
|
#if HAS_NORMAL_MAP == 1
|
||||||
#if (HAS_SPEC_MAP_OFFSET == 1 || HAS_SPEC_MAP_SCALE == 1) && ENABLE_PER_PIXEL == 1
|
// ----- Calculate per-pixel lighting in tangent space, for normal mapping ------
|
||||||
spec_uv = texCoord;
|
mediump vec3 a_bitangent = cross(vertex_normal, vertex_tangent);
|
||||||
#if HAS_SPEC_MAP_OFFSET == 1
|
mediump vec3 eyeVec = normalize(cameraPosition - vertex_position);
|
||||||
spec_uv + specularTexture_Offset;
|
|
||||||
#endif
|
lightVec = normalize(vec3(dot(lightDirection, vertex_tangent), dot(lightDirection, a_bitangent), dot(lightDirection, vertex_normal)));
|
||||||
|
halfVec = normalize(vec3(dot(eyeVec, vertex_tangent), dot(eyeVec, a_bitangent), dot(eyeVec, vertex_normal)));
|
||||||
#if HAS_SPEC_MAP_SCALE == 1
|
halfVec = normalize(halfVec + lightVec); // Normalizing anyways, no need to divide by 2
|
||||||
spec_uv *= specularTexture_Scale;
|
#else
|
||||||
#endif
|
// ------ Calculate per-pixel lighting without normal mapping ------
|
||||||
|
normal = vertex_normal;
|
||||||
#endif
|
lightVec = lightDirection;
|
||||||
|
halfVec = normalize((normalize(cameraPosition - vertex_position) + lightVec)); // Normalizing anyways, no need to divide by 2
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
#if HAS_LIGHT_MAP == 1
|
// ------ Calculate per-vertex lighting ------
|
||||||
// Pass shadow UV co-ordinates
|
mediump vec3 halfVec = normalize((normalize(cameraPosition - vertex_position) + lightDirection)); // Normalizing anyways, no need to divide by 2
|
||||||
shadowCoord = shadowuv.st;
|
lamberFactor = max(0.0,dot(lightDirection, vertex_normal));
|
||||||
#endif
|
specularFactor = max(0.0,pow(dot(halfVec,vertex_normal), material_shininess));
|
||||||
|
#endif
|
||||||
#if SHADOW_QUALITY >= 1
|
#endif
|
||||||
shadowMapCoord1 = myShadowMVPMatrix1 * vec4(myVertex,1.0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if SHADOW_QUALITY >= 2
|
|
||||||
shadowMapCoord2 = myShadowMVPMatrix2 * vec4(myVertex,1.0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if SHADOW_QUALITY >= 3
|
|
||||||
shadowMapCoord3 = myShadowMVPMatrix3 * vec4(myVertex,1.0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#if (HAS_NORMAL_MAP == 1 && ENABLE_PER_PIXEL == 1) || GBUFFER_PASS == 1
|
|
||||||
mediump vec3 a_bitangent = cross(myNormal, myTangent);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// ----------- Directional Light (Sun) -----------
|
|
||||||
#if HAS_NORMAL_MAP == 1 && ENABLE_PER_PIXEL == 1
|
|
||||||
// ----- Calculate per-pixel lighting in tangent space, for normal mapping ------
|
|
||||||
mediump vec3 eyeVec = normalize(cameraPosition - myVertex);
|
|
||||||
|
|
||||||
lightVec = normalize(vec3(dot(lightDirection, myTangent), dot(lightDirection, a_bitangent), dot(lightDirection, myNormal)));
|
|
||||||
halfVec = normalize(vec3(dot(eyeVec, myTangent), dot(eyeVec, a_bitangent), dot(eyeVec, myNormal)));
|
|
||||||
halfVec = normalize(halfVec + lightVec); // Normalizing anyways, no need to divide by 2
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
#if ENABLE_PER_PIXEL == 1
|
|
||||||
// ------ Calculate per-pixel lighting without normal mapping ------
|
|
||||||
normal = myNormal;
|
|
||||||
lightVec = lightDirection;
|
|
||||||
halfVec = normalize((normalize(cameraPosition - myVertex) + lightVec)); // Normalizing anyways, no need to divide by 2
|
|
||||||
#else
|
|
||||||
// ------ Calculate per-vertex lighting ------
|
|
||||||
mediump vec3 halfVec = normalize((normalize(cameraPosition - myVertex) + lightDirection)); // Normalizing anyways, no need to divide by 2
|
|
||||||
lamberFactor = max(0.0,dot(lightDirection, myNormal));
|
|
||||||
specularFactor = max(0.0,pow(dot(halfVec,myNormal), material_shininess));
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#if GBUFFER_PASS == 1 && HAS_NORMAL_MAP == 1
|
|
||||||
tangent_to_view[0] = vec3(model_to_view * vec4(myTangent, 1.0));
|
|
||||||
tangent_to_view[1] = vec3(model_to_view * vec4(a_bitangent, 1.0));
|
|
||||||
tangent_to_view[2] = vec3(model_to_view * vec4(myNormal, 1.0));
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,12 +28,8 @@
|
|||||||
#define SHADOW_BIAS 0.01
|
#define SHADOW_BIAS 0.01
|
||||||
|
|
||||||
|
|
||||||
attribute highp vec3 myVertex;
|
attribute highp vec3 vertex_position;
|
||||||
/*
|
uniform highp mat4 shadow_mvp1; // Shadowmvpmatrix is the result of multiplying the model, view, and projection matrices
|
||||||
attribute mediump vec2 myUV;
|
|
||||||
varying mediump vec2 texCoord;
|
|
||||||
*/
|
|
||||||
uniform highp mat4 myShadowMVPMatrix1; // Shadowmvpmatrix is the result of multiplying the model, view, and projection matrices
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -41,13 +37,13 @@ void main()
|
|||||||
{
|
{
|
||||||
// Transform position
|
// Transform position
|
||||||
/*
|
/*
|
||||||
position = myShadowMVPMatrix1 * vec4(myVertex,1.0);
|
position = shadow_mvp1 * vec4(vertex_position,1.0);
|
||||||
*/
|
*/
|
||||||
gl_Position = myShadowMVPMatrix1 * vec4(myVertex,1.0);
|
gl_Position = shadow_mvp1 * vec4(vertex_position,1.0);
|
||||||
gl_Position.z += SHADOW_BIAS;
|
gl_Position.z += SHADOW_BIAS;
|
||||||
/*
|
/*
|
||||||
// Pass UV co-ordinates
|
// Pass UV co-ordinates
|
||||||
texCoord = myUV.st;
|
texCoord = vertex_uv.st;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user