Reduced precision of shader variables to increase performance

OSX library now compiling again

--HG--
extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%4052
This commit is contained in:
kearwood
2012-04-20 01:06:12 +00:00
parent b2c67f5276
commit 1df9ac00ca
5 changed files with 14 additions and 22 deletions

View File

@@ -167,6 +167,8 @@ KRShader::~KRShader() {
} }
} }
#if TARGET_OS_IPHONE
void KRShader::bind(KRCamera *pCamera, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, int gBufferPass) { void KRShader::bind(KRCamera *pCamera, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, int gBufferPass) {
glUseProgram(m_iProgram); glUseProgram(m_iProgram);
@@ -240,6 +242,8 @@ void KRShader::bind(KRCamera *pCamera, KRMat4 &matModelToView, KRMat4 &mvpMatrix
} }
#endif
GLuint KRShader::getProgram() { GLuint KRShader::getProgram() {
return m_iProgram; return m_iProgram;
} }

View File

@@ -51,8 +51,12 @@ public:
GLuint getProgram(); GLuint getProgram();
char *getKey(); char *getKey();
#if TARGET_OS_IPHONE
void bind(KRCamera *pCamera, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, int gBufferPass); void bind(KRCamera *pCamera, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, int gBufferPass);
#endif
enum { enum {
KRENGINE_ATTRIB_VERTEX, KRENGINE_ATTRIB_VERTEX,
KRENGINE_ATTRIB_NORMAL, KRENGINE_ATTRIB_NORMAL,

View File

@@ -258,7 +258,5 @@ void main()
gl_FragColor = vec4(gl_FragColor.r * lightMapColor.r, gl_FragColor.g * lightMapColor.g, gl_FragColor.b * lightMapColor.b, 1.0); gl_FragColor = vec4(gl_FragColor.r * lightMapColor.r, gl_FragColor.g * lightMapColor.g, gl_FragColor.b * lightMapColor.b, 1.0);
#endif #endif
//gl_FragColor = vec4(vec3(specularFactor), 1.0);
#endif #endif
} }

View File

@@ -111,11 +111,11 @@ uniform highp mat4 mvp_matrix; // mvp_matrix is the result of multiplying t
#endif #endif
#if HAS_DIFFUSE_MAP_SCALE == 1 #if HAS_DIFFUSE_MAP_SCALE == 1
uniform highp vec2 diffuseTexture_Scale; uniform highp vec2 diffuseTexture_Scale;
#endif #endif
#if HAS_DIFFUSE_MAP_OFFSET == 1 #if HAS_DIFFUSE_MAP_OFFSET == 1
uniform highp vec2 diffuseTexture_Offset; uniform highp vec2 diffuseTexture_Offset;
#endif #endif
#if HAS_DIFFUSE_MAP_OFFSET == 1 || HAS_DIFFUSE_MAP_SCALE == 1 #if HAS_DIFFUSE_MAP_OFFSET == 1 || HAS_DIFFUSE_MAP_SCALE == 1

View File

@@ -30,42 +30,28 @@ uniform sampler2D gbuffer_frame;
uniform sampler2D gbuffer_depth; uniform sampler2D gbuffer_depth;
uniform highp vec3 lightDirection; // Must be normalized and converted to view space before entering shader uniform highp vec3 lightDirection; // Must be normalized and converted to view space before entering shader
uniform highp mat4 model_to_view_matrix;
uniform mediump vec4 viewport; uniform mediump vec4 viewport;
void main() void main()
{ {
mediump vec2 gbuffer_uv = vec2(gl_FragCoord.xy / viewport.zw); mediump vec2 gbuffer_uv = vec2(gl_FragCoord.xy / viewport.zw);
lowp vec4 gbuffer_sample = texture2D(gbuffer_frame, gbuffer_uv); lowp vec4 gbuffer_sample = texture2D(gbuffer_frame, gbuffer_uv);
mediump vec3 gbuffer_normal = 2.0 * gbuffer_sample.rgb - 1.0; mediump vec3 gbuffer_normal = 2.0 * gbuffer_sample.rgb - 1.0;
mediump float gbuffer_specular_exponent = gbuffer_sample.a * 100.0; mediump float gbuffer_specular_exponent = gbuffer_sample.a * 100.0;
mediump vec3 view_space_light = lightDirection; // vec3(model_to_view_matrix * vec4(lightDirection, 1.0)); mediump float lamberFactor = max(0.0,dot(lightDirection, gbuffer_normal));
mediump float lamberFactor = max(0.0,dot(view_space_light, gbuffer_normal));
mediump vec3 view_space_vertex_position;
highp vec3 view_space_vertex_position;
view_space_vertex_position.xy = ((2.0 * gl_FragCoord.xy) - (2.0 * viewport.xy)) / (viewport.zw) - 1.0; view_space_vertex_position.xy = ((2.0 * gl_FragCoord.xy) - (2.0 * viewport.xy)) / (viewport.zw) - 1.0;
//view_space_vertex_position.z = -texture2D(gbuffer_depth, gbuffer_uv).r * 2.0;
view_space_vertex_position.z = (2.0 * -texture2D(gbuffer_depth, gbuffer_uv).r - gl_DepthRange.near - gl_DepthRange.far) / view_space_vertex_position.z = (2.0 * -texture2D(gbuffer_depth, gbuffer_uv).r - gl_DepthRange.near - gl_DepthRange.far) /
(gl_DepthRange.far - gl_DepthRange.near); (gl_DepthRange.far - gl_DepthRange.near);
highp vec3 halfVec = normalize((normalize(vec3(0.0, 0.0, 0.0) - view_space_vertex_position) + view_space_light)); // Normalizing anyways, no need to divide by 2
mediump float specularFactor = 0.0; mediump float specularFactor = 0.0;
if(gbuffer_specular_exponent > 0.0) { if(gbuffer_specular_exponent > 0.0) {
mediump vec3 halfVec = normalize((normalize(vec3(0.0, 0.0, 0.0) - view_space_vertex_position) + lightDirection)); // Normalizing anyways, no need to divide by 2
specularFactor = clamp(pow(dot(halfVec,normalize(gbuffer_normal)), gbuffer_specular_exponent), 0.0, 1.0); specularFactor = clamp(pow(dot(halfVec,normalize(gbuffer_normal)), gbuffer_specular_exponent), 0.0, 1.0);
} }