Deferred lighting now working with directional lights

--HG--
extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%4047
This commit is contained in:
kearwood
2012-04-14 02:15:35 +00:00
parent 97d8054cd0
commit 2ead2995d5
12 changed files with 183 additions and 94 deletions

View File

@@ -97,6 +97,8 @@
E4D13365153767FF0070068C /* KRShaderManager.h in Headers */ = {isa = PBXBuildFile; fileRef = E47C25A113F4F65A00FF4370 /* KRShaderManager.h */; settings = {ATTRIBUTES = (Public, ); }; };
E4D133661537685A0070068C /* KRShader.h in Headers */ = {isa = PBXBuildFile; fileRef = E47C25A413F4F66F00FF4370 /* KRShader.h */; settings = {ATTRIBUTES = (Public, ); }; };
E4D13367153768610070068C /* KRShader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E47C25A813F4F6DD00FF4370 /* KRShader.cpp */; settings = {ATTRIBUTES = (Public, ); }; };
E4D133BA1538F7480070068C /* light_directional.fsh in Sources */ = {isa = PBXBuildFile; fileRef = E4D133B91538F7480070068C /* light_directional.fsh */; };
E4D133BC1538F7560070068C /* light_directional.vsh in Sources */ = {isa = PBXBuildFile; fileRef = E4D133BB1538F7560070068C /* light_directional.vsh */; };
E4F711A51512BB56007EE923 /* libfbxsdk-2012.2-static.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E4F711A41512BB56007EE923 /* libfbxsdk-2012.2-static.a */; };
E4F975321536220900FD60B2 /* KRNode.h in Headers */ = {isa = PBXBuildFile; fileRef = E4F975311536220900FD60B2 /* KRNode.h */; };
E4F975331536220900FD60B2 /* KRNode.h in Headers */ = {isa = PBXBuildFile; fileRef = E4F975311536220900FD60B2 /* KRNode.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -144,8 +146,8 @@
E45772F113C9A13C0037BEEA /* ShadowShader.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; lineEnding = 0; name = ShadowShader.vsh; path = Shaders/ShadowShader.vsh; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.glsl; };
E45772F213C9A13C0037BEEA /* ShadowShader.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = ShadowShader.fsh; path = Shaders/ShadowShader.fsh; sourceTree = "<group>"; };
E45772F313C9A13C0037BEEA /* PostShader.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = PostShader.fsh; path = Shaders/PostShader.fsh; sourceTree = "<group>"; };
E45772F413C9A13C0037BEEA /* ObjectShader.fsh */ = {isa = PBXFileReference; fileEncoding = 4; name = ObjectShader.fsh; path = Shaders/ObjectShader.fsh; sourceTree = "<group>"; };
E45772F513C9A13C0037BEEA /* ObjectShader.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lineEnding = 0; name = ObjectShader.vsh; path = Shaders/ObjectShader.vsh; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.glsl; };
E45772F413C9A13C0037BEEA /* ObjectShader.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = ObjectShader.fsh; path = Shaders/ObjectShader.fsh; sourceTree = "<group>"; };
E45772F513C9A13C0037BEEA /* ObjectShader.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; lineEnding = 0; name = ObjectShader.vsh; path = Shaders/ObjectShader.vsh; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.glsl; };
E45772F613C9A13C0037BEEA /* PostShader.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = PostShader.vsh; path = Shaders/PostShader.vsh; sourceTree = "<group>"; };
E461A151152E54B500F2044A /* KRLight.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRLight.h; path = Classes/KRLight.h; sourceTree = "<group>"; };
E461A155152E54F700F2044A /* KRLight.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRLight.cpp; path = Classes/KRLight.cpp; sourceTree = "<group>"; };
@@ -212,6 +214,8 @@
E4BBBB961512A46700F43B5B /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/AppKit.framework; sourceTree = DEVELOPER_DIR; };
E4BBBB981512A47500F43B5B /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/CoreData.framework; sourceTree = DEVELOPER_DIR; };
E4BBBB9A1512A48200F43B5B /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/Foundation.framework; sourceTree = DEVELOPER_DIR; };
E4D133B91538F7480070068C /* light_directional.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = light_directional.fsh; path = Shaders/light_directional.fsh; sourceTree = "<group>"; };
E4D133BB1538F7560070068C /* light_directional.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = light_directional.vsh; path = Shaders/light_directional.vsh; sourceTree = "<group>"; };
E4F711A41512BB56007EE923 /* libfbxsdk-2012.2-static.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libfbxsdk-2012.2-static.a"; path = "../../../../../../../../Applications/Autodesk/FBXSDK20122/lib/gcc4/ub/libfbxsdk-2012.2-static.a"; sourceTree = "<group>"; };
E4F975311536220900FD60B2 /* KRNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRNode.h; path = Classes/KRNode.h; sourceTree = "<group>"; };
E4F975351536221C00FD60B2 /* KRNode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRNode.cpp; path = Classes/KRNode.cpp; sourceTree = "<group>"; };
@@ -254,6 +258,8 @@
E45772F313C9A13C0037BEEA /* PostShader.fsh */,
E45772F413C9A13C0037BEEA /* ObjectShader.fsh */,
E45772F613C9A13C0037BEEA /* PostShader.vsh */,
E4D133B91538F7480070068C /* light_directional.fsh */,
E4D133BB1538F7560070068C /* light_directional.vsh */,
);
name = Shaders;
sourceTree = "<group>";
@@ -642,6 +648,8 @@
E46C214515364BC8009CABF3 /* tinyxml2.cpp in Sources */,
E46C214B15364DEC009CABF3 /* KRSceneManager.cpp in Sources */,
E48C697215374F7E00232E28 /* KRContext.cpp in Sources */,
E4D133BA1538F7480070068C /* light_directional.fsh in Sources */,
E4D133BC1538F7560070068C /* light_directional.vsh in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@@ -9,6 +9,8 @@
#include <iostream>
#import "KRDirectionalLight.h"
#import "KRShader.h"
#import "KRContext.h"
KRDirectionalLight::KRDirectionalLight(std::string name) : KRLight(name)
{
@@ -30,48 +32,34 @@ void KRDirectionalLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundi
if(gBufferPass == 2) {
// Lights are rendered on the second pass of the deferred renderer
/*
if(m_pModel == NULL) {
m_pModel = pContext->getModelManager()->getModel(m_model_name.c_str());
}
KRMat4 projectionMatrix = pCamera->getProjectionMatrix();
if(m_pModel != NULL && (getExtents(pContext).test_intersect(frustrumVolume) || bRenderShadowMap)) {
if(m_pLightMap == NULL && m_lightMap.size()) {
m_pLightMap = pContext->getTextureManager()->getTexture(m_lightMap.c_str());
}
if(cShadowBuffers == 0 && m_pLightMap && pCamera->bEnableLightMap && !bRenderShadowMap) {
int iTextureName = m_pLightMap->getName();
glActiveTexture(GL_TEXTURE3);
glBindTexture(GL_TEXTURE_2D, iTextureName);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0f);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
}
KRMat4 projectionMatrix;
if(!bRenderShadowMap) {
projectionMatrix = pCamera->getProjectionMatrix();
}
KRMat4 mvpmatrix = m_modelMatrix * viewMatrix * projectionMatrix;
KRMat4 matModelToView = viewMatrix * m_modelMatrix;
matModelToView.transpose();
matModelToView.invert();
// Transform location of camera to object space for calculation of specular halfVec
KRMat4 inverseModelMatrix = m_modelMatrix;
inverseModelMatrix.invert();
KRVector3 cameraPosObject = inverseModelMatrix.dot(cameraPosition);
KRVector3 lightDirObject = inverseModelMatrix.dot(lightDirection);
m_pModel->render(pCamera, pContext, bRenderShadowMap, matModelToView, mvpmatrix, cameraPosObject, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, m_pLightMap, gBufferPass);
}
*/
KRShader *pShader = pContext->getShaderManager()->getShader("light_directional", pCamera, false, false, false, 0, false, false, false, false, false, false, false, gBufferPass);
pShader->bind(pCamera, matModelToView, mvpmatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, 0, gBufferPass);
// Render a full screen quad
static const GLfloat squareVertices[] = {
-1.0f, -1.0f,
1.0f, -1.0f,
-1.0f, 1.0f,
1.0f, 1.0f,
};
// Disable z-buffer test
glDisable(GL_DEPTH_TEST);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, squareVertices);
glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
KRNode::render(pCamera, pContext, frustrumVolume, bRenderShadowMap, viewMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, gBufferPass);

View File

@@ -10,6 +10,7 @@
#define KREngine_KRDirectionalLight_h
#import "KRLight.h"
#import "KRMat4.h"
class KRDirectionalLight : public KRLight {
@@ -23,6 +24,9 @@ public:
virtual void render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, bool bRenderShadowMap, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, int gBufferPass);
#endif
private:
KRMat4 m_modelMatrix;
};

View File

@@ -53,7 +53,7 @@ typedef enum KREngineParameterType {KRENGINE_PARAMETER_INT, KRENGINE_PARAMETER_F
GLint backingWidth, backingHeight;
GLuint compositeFramebuffer, compositeDepthTexture, compositeColorTexture;
GLuint lightAccumulationBuffer;
GLuint lightAccumulationBuffer, lightAccumulationTexture;
int m_cShadowBuffers;
GLuint shadowFramebuffer[KRENGINE_MAX_SHADOW_BUFFERS], shadowDepthTexture[KRENGINE_MAX_SHADOW_BUFFERS];

View File

@@ -159,14 +159,14 @@ double const PI = 3.141592653589793f;
glBindFramebuffer(GL_FRAMEBUFFER, lightAccumulationBuffer);
// ----- Create texture color buffer for compositeFramebuffer -----
glGenTextures(1, &lightAccumulationBuffer);
glBindTexture(GL_TEXTURE_2D, lightAccumulationBuffer);
glGenTextures(1, &lightAccumulationTexture);
glBindTexture(GL_TEXTURE_2D, lightAccumulationTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); // This is necessary for non-power-of-two textures
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // This is necessary for non-power-of-two textures
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, backingWidth, backingHeight, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, compositeColorTexture, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, lightAccumulationTexture, 0);
[self allocateShadowBuffers];
return TRUE;
@@ -187,6 +187,11 @@ double const PI = 3.141592653589793f;
compositeColorTexture = 0;
}
if (lightAccumulationTexture) {
glDeleteTextures(1, &lightAccumulationTexture);
lightAccumulationTexture = 0;
}
if (compositeFramebuffer) {
glDeleteFramebuffers(1, &compositeFramebuffer);
compositeFramebuffer = 0;
@@ -386,29 +391,34 @@ double const PI = 3.141592653589793f;
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
// Enable additive blending
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE);
// 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
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE);
// Render the geometry
pScene->render(&m_camera, m_pContext, frustrumVolume, false, viewMatrix, cameraPosition, lightDirection, shadowmvpmatrix, shadowDepthTexture, m_cShadowBuffers, 2);
pScene->render(&m_camera, m_pContext, frustrumVolume, false, viewMatrix, cameraPosition, lightDirection, shadowmvpmatrix, shadowDepthTexture, 0, 2);
// ----====---- Opaque Geometry, Deferred rendering Pass 3 ----====----
// Set render target
glBindFramebuffer(GL_FRAMEBUFFER, compositeFramebuffer);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, compositeDepthTexture, 0);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
// Disable alpha blending
glDisable(GL_BLEND);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
// Set source to buffers from pass 2
glActiveTexture(GL_TEXTURE6);
glBindTexture(GL_TEXTURE_2D, lightAccumulationBuffer);
glBindTexture(GL_TEXTURE_2D, lightAccumulationTexture);
// Enable backface culling
glCullFace(GL_BACK);
@@ -427,12 +437,15 @@ double const PI = 3.141592653589793f;
glBindTexture(GL_TEXTURE_2D, 0);
glActiveTexture(GL_TEXTURE7);
glBindTexture(GL_TEXTURE_2D, 0);
} else {
// ----====---- Opaque Geometry, Forward Rendering ----====----
// Set render target
glBindFramebuffer(GL_FRAMEBUFFER, compositeFramebuffer);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, compositeDepthTexture, 0);
// Disable alpha blending
glDisable(GL_BLEND);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
@@ -446,8 +459,7 @@ double const PI = 3.141592653589793f;
glDepthFunc(GL_LEQUAL);
glDepthRangef(0.0, 1.0);
// Disable alpha blending
glDisable(GL_BLEND);
// Render the geometry
pScene->render(&m_camera, m_pContext, frustrumVolume, false, viewMatrix, cameraPosition, lightDirection, shadowmvpmatrix, shadowDepthTexture, m_cShadowBuffers, 0);
@@ -598,8 +610,6 @@ double const PI = 3.141592653589793f;
// Bind attribute locations.
// This needs to be done prior to linking.
glBindAttribLocation(*programPointer, KRShader::KRENGINE_ATTRIB_VERTEX, "position");
glBindAttribLocation(*programPointer, KRShader::KRENGINE_ATTRIB_TEXUVA, "inputTextureCoordinate");
glBindAttribLocation(*programPointer, KRShader::KRENGINE_ATTRIB_TEXUVB, "vertex_lightmap_uv");
glBindAttribLocation(*programPointer, KRShader::KRENGINE_ATTRIB_VERTEX, "vertex_position");
glBindAttribLocation(*programPointer, KRShader::KRENGINE_ATTRIB_NORMAL, "vertex_normal");
@@ -725,7 +735,6 @@ double const PI = 3.141592653589793f;
// Disable alpha blending
glDisable(GL_BLEND);
// Replace the implementation of this method to do your own custom drawing.
static const GLfloat squareVertices[] = {
-1.0f, -1.0f,
1.0f, -1.0f,
@@ -766,6 +775,7 @@ double const PI = 3.141592653589793f;
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, compositeColorTexture);
//glBindTexture(GL_TEXTURE_2D, lightAccumulationTexture);
glUniform1i(glGetUniformLocation(m_postShaderProgram, "renderFrame"), 1);

View File

@@ -80,13 +80,12 @@ KRShader::KRShader(char *szKey, std::string options, std::string vertShaderSourc
// Bind attribute locations.
// This needs to be done prior to linking.
glBindAttribLocation(m_iProgram, KRENGINE_ATTRIB_VERTEX, "position");
glBindAttribLocation(m_iProgram, KRENGINE_ATTRIB_TEXUVA, "inputTextureCoordinate");
glBindAttribLocation(m_iProgram, KRENGINE_ATTRIB_TEXUVB, "vertex_lightmap_uv");
glBindAttribLocation(m_iProgram, KRENGINE_ATTRIB_VERTEX, "vertex_position");
glBindAttribLocation(m_iProgram, KRENGINE_ATTRIB_NORMAL, "vertex_normal");
glBindAttribLocation(m_iProgram, KRENGINE_ATTRIB_TANGENT, "vertex_tangent");
glBindAttribLocation(m_iProgram, KRENGINE_ATTRIB_TEXUVA, "vertex_uv");
glBindAttribLocation(m_iProgram, KRENGINE_ATTRIB_TEXUVB, "vertex_lightmap_uv");
// Link program.
glLinkProgram(m_iProgram);

View File

@@ -49,11 +49,9 @@
#endif
#if GBUFFER_PASS == 2 || GBUFFER_PASS == 3
#if GBUFFER_PASS == 3
uniform sampler2D gbuffer_frame;
uniform sampler2D gbuffer_depth;
varying mediump vec2 gbuffer_uv;
#endif
#if GBUFFER_PASS == 1
@@ -118,6 +116,10 @@
void main()
{
#if GBUFFER_PASS == 2 || GBUFFER_PASS == 3
mediump vec2 gbuffer_uv = vec2(gl_FragCoord.x / 768.0, gl_FragCoord.y / 1024.0);
#endif
#if GBUFFER_PASS == 2
lowp vec4 gbuffer_sample = texture2D(gbuffer_frame, gbuffer_uv);
mediump vec3 gbuffer_normal = normalize(2.0 * gbuffer_sample.rgb - 1.0);
@@ -151,15 +153,17 @@ void main()
// 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
#if GBUFFER_PASS == 3
mediump float lamberFactor = gbuffer_lamber_factor.r;
#else
mediump float lamberFactor = max(0.0,dot(lightVec, normal));
#endif
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;
@@ -246,17 +250,4 @@ void main()
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
#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
}

View File

@@ -59,10 +59,6 @@ uniform highp mat4 mvp_matrix; // mvp_matrix is the result of multiplying t
#endif
#endif
#if GBUFFER_PASS == 2 || GBUFFER_PASS == 3
varying mediump vec2 gbuffer_uv;
#endif
#if GBUFFER_PASS == 1
#if HAS_NORMAL_MAP == 1
uniform highp mat4 model_to_view_matrix;
@@ -135,10 +131,6 @@ void main()
// Transform position
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;
@@ -189,7 +181,7 @@ void main()
#if ENABLE_PER_PIXEL == 1
// Scaled and translated specular map UV's
#if (HAS_SPEC_MAP_OFFSET == 1 || HAS_SPEC_MAP_SCALE == 1) && ENABLE_PER_PIXEL == 1
#if HAS_SPEC_MAP_OFFSET == 1 || HAS_SPEC_MAP_SCALE == 1
spec_uv = texCoord;
#if HAS_SPEC_MAP_OFFSET == 1
spec_uv + specularTexture_Offset;
@@ -229,6 +221,7 @@ void main()
halfVec = normalize((normalize(cameraPosition - vertex_position) + lightVec)); // Normalizing anyways, no need to divide by 2
#endif
#else
// ------ Calculate per-vertex lighting ------
mediump vec3 halfVec = normalize((normalize(cameraPosition - vertex_position) + lightDirection)); // Normalizing anyways, no need to divide by 2
lamberFactor = max(0.0,dot(lightDirection, vertex_normal));

View File

@@ -25,13 +25,13 @@
// or implied, of Kearwood Gilbert.
//
attribute vec4 position;
attribute lowp vec4 inputTextureCoordinate;
attribute vec4 vertex_position;
attribute lowp vec4 vertex_uv;
varying mediump vec2 textureCoordinate;
void main()
{
gl_Position = position;
textureCoordinate = inputTextureCoordinate.xy;
gl_Position = vertex_position;
textureCoordinate = vertex_uv.xy;
}

View File

@@ -0,0 +1,51 @@
// Copyright 2012 Kearwood Gilbert. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// The views and conclusions contained in the software and documentation are those of the
// authors and should not be interpreted as representing official policies, either expressed
// or implied, of Kearwood Gilbert.
//
uniform sampler2D gbuffer_frame;
uniform sampler2D gbuffer_depth;
uniform highp vec3 lightDirection; // Must be normalized before entering shader
uniform highp mat4 model_to_view_matrix;
void main()
{
mediump vec2 gbuffer_uv = vec2(gl_FragCoord.x / 768.0, gl_FragCoord.y / 1024.0);
lowp vec4 gbuffer_sample = texture2D(gbuffer_frame, gbuffer_uv);
mediump vec3 gbuffer_normal = normalize(2.0 * gbuffer_sample.rgb - 1.0);
mediump float gbuffer_specular_exponent = gbuffer_sample.a;
mediump vec3 view_space_light = vec3(model_to_view_matrix * vec4(lightDirection, 1.0));
mediump float lamberFactor = max(0.0,dot(view_space_light, gbuffer_normal));
gl_FragColor = vec4(vec3(lamberFactor), 0.0);
}

View File

@@ -0,0 +1,33 @@
// Copyright 2012 Kearwood Gilbert. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// The views and conclusions contained in the software and documentation are those of the
// authors and should not be interpreted as representing official policies, either expressed
// or implied, of Kearwood Gilbert.
//
attribute vec4 vertex_position;
void main()
{
gl_Position = vertex_position;
}

View File

@@ -30,6 +30,10 @@
E46FED3113C9A49F009F5814 /* ObjectShader.vsh in Resources */ = {isa = PBXBuildFile; fileRef = E46FED2513C9A488009F5814 /* ObjectShader.vsh */; };
E46FED3213C9A49F009F5814 /* PostShader.vsh in Resources */ = {isa = PBXBuildFile; fileRef = E46FED2613C9A488009F5814 /* PostShader.vsh */; };
E49EB29C13806C5D00A4E727 /* MainWindow-iPad.xib in Resources */ = {isa = PBXBuildFile; fileRef = E49EB29B13806C5D00A4E727 /* MainWindow-iPad.xib */; };
E4FF48C21538FBF0002053FC /* light_directional.fsh in Sources */ = {isa = PBXBuildFile; fileRef = E4FF48C01538FBF0002053FC /* light_directional.fsh */; };
E4FF48C31538FBF0002053FC /* light_directional.vsh in Sources */ = {isa = PBXBuildFile; fileRef = E4FF48C11538FBF0002053FC /* light_directional.vsh */; };
E4FF48C51538FBF8002053FC /* light_directional.fsh in Resources */ = {isa = PBXBuildFile; fileRef = E4FF48C01538FBF0002053FC /* light_directional.fsh */; };
E4FF48C61538FBFC002053FC /* light_directional.vsh in Resources */ = {isa = PBXBuildFile; fileRef = E4FF48C11538FBF0002053FC /* light_directional.vsh */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -63,6 +67,8 @@
E46FED2513C9A488009F5814 /* ObjectShader.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; lineEnding = 0; name = ObjectShader.vsh; path = ../KREngine/KREngine/Shaders/ObjectShader.vsh; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.glsl; };
E46FED2613C9A488009F5814 /* PostShader.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = PostShader.vsh; path = ../KREngine/KREngine/Shaders/PostShader.vsh; sourceTree = "<group>"; };
E49EB29B13806C5D00A4E727 /* MainWindow-iPad.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = "MainWindow-iPad.xib"; path = "iPad/MainWindow-iPad.xib"; sourceTree = "<group>"; };
E4FF48C01538FBF0002053FC /* light_directional.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = light_directional.fsh; path = ../KREngine/KREngine/Shaders/light_directional.fsh; sourceTree = "<group>"; };
E4FF48C11538FBF0002053FC /* light_directional.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = light_directional.vsh; path = ../KREngine/KREngine/Shaders/light_directional.vsh; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -176,6 +182,8 @@
E46FED2013C9A472009F5814 /* Shaders */ = {
isa = PBXGroup;
children = (
E4FF48C01538FBF0002053FC /* light_directional.fsh */,
E4FF48C11538FBF0002053FC /* light_directional.vsh */,
E46FED2113C9A488009F5814 /* ShadowShader.vsh */,
E46FED2213C9A488009F5814 /* ShadowShader.fsh */,
E46FED2313C9A488009F5814 /* PostShader.fsh */,
@@ -259,6 +267,8 @@
E46FED2E13C9A49F009F5814 /* ShadowShader.fsh in Resources */,
E46FED2F13C9A49F009F5814 /* PostShader.fsh in Resources */,
E46FED3013C9A49F009F5814 /* ObjectShader.fsh in Resources */,
E4FF48C51538FBF8002053FC /* light_directional.fsh in Resources */,
E4FF48C61538FBFC002053FC /* light_directional.vsh in Resources */,
E46FED3113C9A49F009F5814 /* ObjectShader.vsh in Resources */,
E46FED3213C9A49F009F5814 /* PostShader.vsh in Resources */,
28AD733F0D9D9553002E5188 /* MainWindow.xib in Resources */,
@@ -279,6 +289,8 @@
1D3623260D0F684500981E51 /* KRObjViewAppDelegate.mm in Sources */,
28D7ACF80DDB3853001CB0EB /* KRObjViewViewController.mm in Sources */,
1063FC77136D6A1B00EE555B /* KRObjViewGLView.mm in Sources */,
E4FF48C21538FBF0002053FC /* light_directional.fsh in Sources */,
E4FF48C31538FBF0002053FC /* light_directional.vsh in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};