瀏覽代碼

Merge pull request #1 from JeffProgrammer/moreshadergenforkermitthefrog

More shadergen fixes for poor kermit
Brian Roberts 3 年之前
父節點
當前提交
e8d7258d91

+ 1 - 0
Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp

@@ -1982,6 +1982,7 @@ void ReflectCubeFeatGLSL::processPix(  Vector<ShaderComponent*> &componentList,
          Var *envColor = new Var("envColor", "vec3");
          meta->addStatement(new GenOp("   @ = @.rgb - (@.rgb * @);\r\n", new DecOp(dColor), targ, targ, metalness));
          meta->addStatement(new GenOp("   @ = @.rgb*(@).rgb;\r\n", new DecOp(envColor), targ, texCube));
+         meta->addStatement(new GenOp("   @.rgb = @+@;\r\n", targ, dColor, envColor));
       }
       else if (lerpVal)
          meta->addStatement(new GenOp("   @ *= vec4(@.rgb*@.a, @.a);\r\n", targ, texCube, lerpVal, targ));

+ 8 - 0
Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp

@@ -892,6 +892,14 @@ Var* ShaderFeatureHLSL::getSurface(Vector<ShaderComponent*>& componentList, Mult
    }
 
    Var* wsEyePos = (Var*)LangElement::find("eyePosWorld");
+
+   if (!wsEyePos)
+   {
+      wsEyePos = new Var("eyePosWorld", "float3");
+      wsEyePos->uniform = true;
+      wsEyePos->constSortPos = cspPass;
+   }
+
    Var* wsPosition = getInWsPosition(componentList);
    Var* wsView = getWsView(wsPosition, meta);
 

+ 25 - 16
Engine/source/terrain/glsl/terrFeatureGLSL.cpp

@@ -281,6 +281,8 @@ void TerrainBaseMapFeatGLSL::processVert( Vector<ShaderComponent*> &componentLis
    Var *squareSize = _getUniformVar( "squareSize", "float", cspPass );
    meta->addStatement( new GenOp( "   @ = normalize( vec3( @, 0, @ ) );\r\n", 
       new DecOp( inTanget ), squareSize, inTangentZ ) );
+
+   getOutViewToTangent(componentList, meta, fd);
 }
 
 void TerrainBaseMapFeatGLSL::processPix(  Vector<ShaderComponent*> &componentList, 
@@ -331,6 +333,8 @@ void TerrainBaseMapFeatGLSL::processPix(  Vector<ShaderComponent*> &componentLis
    meta->addStatement(new GenOp("   @ = float4(0.0, 1.0, 1.0, 0.0);\r\n", ormConfig));
 
    output = meta;
+
+   Var* viewToTangent = getInViewToTangent(componentList);
 }
 
 ShaderFeature::Resources TerrainBaseMapFeatGLSL::getResources( const MaterialFeatureData &fd )
@@ -781,6 +785,22 @@ void TerrainMacroMapFeatGLSL::processPix(   Vector<ShaderComponent*> &componentL
    meta->addStatement( new GenOp( "   @ = calcBlend( @.x, @.xy, @, @ );\r\n", 
                                     new DecOp( detailBlend ), detailInfo, inTex, layerSize, layerSample ) );
 
+   // Check to see if we have a gbuffer normal.
+   Var* gbNormal = (Var*)LangElement::find("gbNormal");
+
+   // If we have a gbuffer normal and we don't have a
+   // normal map feature then we need to lerp in a 
+   // default normal else the normals below this layer
+   // will show thru.
+   if (gbNormal &&
+      !fd.features.hasFeature(MFT_TerrainNormalMap, detailIndex))
+   {
+      Var* viewToTangent = getInViewToTangent(componentList);
+
+      meta->addStatement(new GenOp("   @ = lerp( @, @[2], min( @, @.w ) );\r\n",
+         gbNormal, gbNormal, viewToTangent, detailBlend, inDet));
+   }
+
    Var *detailColor = (Var*)LangElement::find( "macroColor" ); 
    if ( !detailColor )
    {
@@ -1224,21 +1244,7 @@ void TerrainORMMapFeatGLSL::processPix(Vector<ShaderComponent*> &componentList,
 ShaderFeature::Resources TerrainORMMapFeatGLSL::getResources(const MaterialFeatureData &fd)
 {
    Resources res;
-
-   S32 featureIndex = 0, firstOrmMapIndex = 0;
-   for (int idx = 0; idx < fd.features.getCount(); ++idx) {
-      const FeatureType& type = fd.features.getAt(idx, &featureIndex);
-      if (type == MFT_TerrainORMMap) {
-         firstOrmMapIndex = getMin(firstOrmMapIndex, featureIndex);
-      }
-   }
-
-   // We only need to process normals during the deferred.
-   if (getProcessIndex() == firstOrmMapIndex)
-   {
-      res.numTexReg = 1;
-      res.numTex = 1;
-   }
+   res.numTex = 1;
    return res;
 }
 
@@ -1283,7 +1289,10 @@ void TerrainBlankInfoMapFeatGLSL::processPix(Vector<ShaderComponent*> &component
 
    String matinfoName(String::ToString("matinfoCol%d", compositeIndex));
 
-   meta->addStatement(new GenOp("   @.gba += vec3(@, @, 0.0);\r\n", ormConfig, detailBlend, detailBlend));
+   if (!fd.features.hasFeature(MFT_TerrainHeightBlend))
+   {
+      meta->addStatement(new GenOp("   @.gba += vec3(@, @, 0.0);\r\n", ormConfig, detailBlend, detailBlend));
+   }
 
    output = meta;
 }