GLES2RICE: Update from upstream
[mupen64plus-pandora.git] / source / gles2rice / src / OGLES2FragmentShaders.cpp
index 29b8e97..d43fcae 100755 (executable)
@@ -35,6 +35,7 @@ const char *vertexShader =
 "attribute lowp vec2    aTexCoord0;                         \n"\
 "attribute lowp vec2    aTexCoord1;                         \n"\
 "attribute lowp vec2    aAtlasTransform;                    \n"\
+"attribute mediump float aFogCoord;                         \n"\
 "                                                           \n"\
 "varying lowp float vFactor;                                \n"\
 "varying lowp vec4  vShadeColor;                            \n"\
@@ -48,6 +49,7 @@ const char *vertexShader =
 "vShadeColor = aColor;                                      \n"\
 "vTexCoord0 = aTexCoord0;                                   \n"\
 "vTexCoord1 = aTexCoord1;                                   \n"\
+"vFog = clamp((FogMinMax[1] - aFogCoord)/(FogMinMax[1]-FogMinMax[0]),0.0,1.0);                       \n"\
 "                                                           \n"\
 "}                                                          \n"\
 "                                                           \n";
@@ -71,7 +73,6 @@ const char *fragmentHeader =
 "uniform vec4 FogColor;                                     \n"\
 "uniform vec2  FogMinMax;                                   \n"\
 "                                                           \n"\
-"varying lowp float vFactor;                                \n"\
 "varying lowp vec4  vShadeColor;                            \n"\
 "varying mediump vec2  vTexCoord0;                          \n"\
 "varying lowp vec2  vTexCoord1;                             \n"\
@@ -80,7 +81,7 @@ const char *fragmentHeader =
 "{                                                          \n"\
 "vec4 comb,comb2;                                           \n"\
 "                                                           \n"\
-"#ifdef NEED_TEX0                                              \n"\
+"#ifdef NEED_TEX0                                           \n"\
 "vec4 t0 = texture2D(uTex0,vTexCoord0);                     \n"\
 "#endif                                                     \n"\
 "                                                           \n"\
@@ -91,19 +92,15 @@ const char *fragmentHeader =
 const char *fragmentFooter =
 "                                                           \n"\
 "#ifdef FOG                                                 \n"\
-"   float z = gl_FragCoord.z * 2.0 - 1.0;                                   \n"\
-"   float FogFactor = (FogMinMax[1] - z) / (FogMinMax[1] - FogMinMax[0]);   \n"\
-"   FogFactor = clamp(FogFactor, 0.0, 1.0);                                 \n"\
-"                                                                           \n"\
-"   gl_FragColor.rgb = mix(FogColor.rgb, comb.rgb, FogFactor );             \n"\
-"   gl_FragColor.a = comb.a;                                                \n"\
-"#else                                                                      \n"\
-"   gl_FragColor = comb;                                                    \n"\
-"#endif                                                                     \n"\
-"                                                                           \n"\
-"#ifdef ALPHA_TEST                                                          \n"\
+"gl_FragColor.rgb = mix(FogColor.rgb,comb.rgb,vFog);        \n"\
+"gl_FragColor.a = comb.a;                                   \n"\
+"#else                                                      \n"\
+"gl_FragColor = comb;                                       \n"\
+"#endif                                                     \n"\
+"                                                           \n"\
+"#ifdef ALPHA_TEST                                          \n"\
    ALPHA_TEST                                                                  
-"#endif                                                                     \n"\
+"#endif                                                     \n"\
 "}                                                          \n";
 
 //Fragment shader for InitCycleCopy
@@ -194,10 +191,10 @@ COGL_FragmentProgramCombiner::COGL_FragmentProgramCombiner(CRender *pRender)
     m_pDecodedMux = new DecodedMuxForPixelShader;
     m_bFragmentProgramIsSupported = true;
     m_AlphaRef = 0.0f;
-    bAlphaTestState = DISABLE;
-    bAlphaTestPreviousState = DISABLE;
-    bFogState = DISABLE;
-    bFogPreviousState = DISABLE;
+    bAlphaTestState = false;
+    bAlphaTestPreviousState = false;
+    bFogState = false;
+    bFogPreviousState = false;
 
     //Create shaders for fill and copy
     GLint success;
@@ -328,6 +325,8 @@ void COGL_FragmentProgramCombiner::InitCombinerCycleCopy(void)
     OPENGL_CHECK_ERRORS;
     glDisableVertexAttribArray(VS_TEXCOORD1);
     OPENGL_CHECK_ERRORS;
+       glDisableVertexAttribArray(VS_FOG);
+       OPENGL_CHECK_ERRORS;
     COGLTexture* pTexture = g_textures[gRSP.curTile].m_pCOGLTexture;
     if( pTexture )
     {
@@ -573,6 +572,8 @@ int COGL_FragmentProgramCombiner::ParseDecodedMux()
                        OPENGL_CHECK_ERRORS;
                        glBindAttribLocation(res.programID,VS_POSITION,"aPosition");
                        OPENGL_CHECK_ERRORS;
+                       glBindAttribLocation(res.programID,VS_FOG,"aFogCoord");
+                       OPENGL_CHECK_ERRORS;
 
                        glLinkProgram(res.programID);
                        OPENGL_CHECK_ERRORS;
@@ -650,6 +651,11 @@ void COGL_FragmentProgramCombiner::GenerateCombinerSetting(int index)
     OPENGL_CHECK_ERRORS;
     glVertexAttribPointer(VS_COLOR, 4, GL_UNSIGNED_BYTE,GL_TRUE, sizeof(uint8)*4, &(g_oglVtxColors[0][0]) );
     OPENGL_CHECK_ERRORS;
+       
+       glEnableVertexAttribArray(VS_FOG);
+       OPENGL_CHECK_ERRORS;
+       glVertexAttribPointer(VS_FOG,1,GL_FLOAT,GL_FALSE,sizeof(float)*5,&(g_vtxProjected5[0][4]));
+       OPENGL_CHECK_ERRORS;
 }
 
 void COGL_FragmentProgramCombiner::GenerateCombinerSettingConstants(int index)