Browse Source

Merge pull request #809 from Azaezel/alpha40/ambientAug

allow ambient light injection into ibl
Brian Roberts 3 năm trước cách đây
mục cha
commit
53aea82614

+ 1 - 0
Engine/source/T3D/decal/decalManager.cpp

@@ -1425,6 +1425,7 @@ void DecalManager::prepRenderImage( SceneRenderState* state )
       ri->prim->numPrimitives = currentBatch->iCount / 3;
       ri->prim->startVertex = 0;
       ri->prim->numVertices = currentBatch->vCount;
+      ri->translucentSort = !currentBatch->matInst->getMaterial()->isTranslucent();
 
       // Ugly hack for ProjectedShadow!
       if ( customTex )

+ 3 - 1
Engine/source/environment/decalRoad.cpp

@@ -734,7 +734,7 @@ void DecalRoad::prepRenderImage( SceneRenderState* state )
    coreRI.sortDistSq = F32_MAX;
 
 	// If we need lights then set them up.
-   if ( matInst->isForwardLit() )
+   if ( matInst->isForwardLit() && !coreRI.lights[0])
    {
       LightQuery query;
       query.init( getWorldSphere() );
@@ -784,6 +784,7 @@ void DecalRoad::prepRenderImage( SceneRenderState* state )
 
       *ri = coreRI;
 
+      ri->matInst = matInst;
       ri->prim = renderPass->allocPrim();
       ri->prim->type = GFXTriangleList;
       ri->prim->minIndex = 0;
@@ -791,6 +792,7 @@ void DecalRoad::prepRenderImage( SceneRenderState* state )
       ri->prim->numPrimitives = triangleCount;
       ri->prim->startVertex = 0;
       ri->prim->numVertices = endBatch.endVert + 1;
+      ri->translucentSort = !matInst->getMaterial()->isTranslucent();
 
       // For sorting we first sort by render priority
       // and then by objectId. 

+ 1 - 1
Engine/source/materials/materialDefinition.cpp

@@ -536,7 +536,7 @@ bool Material::onAdd()
    if (mTranslucentBlendOp >= NumBlendTypes || mTranslucentBlendOp < 0)
    {
       Con::errorf("Invalid blend op in material: %s", getName());
-      mTranslucentBlendOp = LerpAlpha;
+      mTranslucentBlendOp = PreMul;
    }
 
    SimSet* matSet = MATMGR->getMaterialSet();

+ 21 - 4
Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp

@@ -3033,6 +3033,15 @@ void ReflectionProbeFeatGLSL::processPix(Vector<ShaderComponent*>& componentList
       return;
    }
 
+   Var *curColor = (Var *)LangElement::find(getOutputTargetVarName(ShaderFeature::DefaultTarget));
+
+   //Reflection vec
+   Var *ibl = (Var *)LangElement::find("ibl");
+   if (!ibl)
+   {
+      ibl = new Var("ibl", "float3");
+   }
+
    Var* eyePos = (Var*)LangElement::find("eyePosWorld");
    if (!eyePos)
    {
@@ -3042,18 +3051,26 @@ void ReflectionProbeFeatGLSL::processPix(Vector<ShaderComponent*>& componentList
       eyePos->uniform = true;
       eyePos->constSortPos = cspPass;
    }
-
-   Var *curColor = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::DefaultTarget));
-      
+         
    //Reflection vec
    String computeForwardProbes = String("   @.rgb = computeForwardProbes(@,@,@,@,@,@,@,@,@,\r\n\t\t");
    computeForwardProbes += String("@,@,\r\n\t\t");
    computeForwardProbes += String("@,@).rgb; \r\n");
 
-   meta->addStatement(new GenOp(computeForwardProbes.c_str(), curColor, surface, cubeMips, numProbes, worldToObjArray, probeConfigData, inProbePosArray, refScaleArray, inRefPosArray, eyePos,
+   meta->addStatement(new GenOp(computeForwardProbes.c_str(), new DecOp(ibl), surface, cubeMips, numProbes, worldToObjArray, probeConfigData, inProbePosArray, refScaleArray, inRefPosArray, eyePos,
       skylightCubemapIdx, BRDFTexture,
       irradianceCubemapAR, specularCubemapAR));
 
+   Var *ambient = (Var *)LangElement::find("ambient");
+   if (!ambient)
+   {
+      ambient = new Var("ambient", "vec3");
+      eyePos->uniform = true;
+      eyePos->constSortPos = cspPass;
+   }
+   meta->addStatement(new GenOp("   @.rgb *= @.rgb;\r\n", ibl, ambient));
+   meta->addStatement(new GenOp("   @.rgb = @.rgb;\r\n", curColor, ibl));
+
    output = meta;
 }
 

+ 9 - 1
Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp

@@ -3149,7 +3149,15 @@ void ReflectionProbeFeatHLSL::processPix(Vector<ShaderComponent*> &componentList
    meta->addStatement(new GenOp(computeForwardProbes.c_str(), new DecOp(ibl), surface, cubeMips, numProbes, worldToObjArray, probeConfigData, inProbePosArray, refScaleArray, inRefPosArray, eyePos,
       skylightCubemapIdx, BRDFTexture,
       irradianceCubemapAR, specularCubemapAR));
-
+   
+   Var *ambient = (Var *)LangElement::find("ambient");
+   if (!ambient)
+   {
+      ambient = new Var("ambient","float3");
+      eyePos->uniform = true;
+      eyePos->constSortPos = cspPass;
+   }
+   meta->addStatement(new GenOp("   @.rgb *= @.rgb;\r\n", ibl, ambient));
    meta->addStatement(new GenOp("   @.rgb = @.rgb;\r\n", curColor, ibl));
 
    output = meta;

+ 2 - 1
Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/reflectionProbeArrayP.glsl

@@ -12,6 +12,7 @@ uniform sampler2D colorBuffer;
 uniform sampler2D matInfoBuffer;
 uniform sampler2D BRDFTexture;
 
+uniform vec3 ambientColor;
 uniform vec4 rtParams0;
 uniform vec4 vsFarPlane;
 uniform mat4 cameraToWorld;
@@ -202,6 +203,6 @@ void main()
 #if CAPTURING == 1
    OUT_col = vec4(mix(surface.baseColor.rgb,(irradiance + specular* horizon) ,surface.metalness/2),0);
 #else
-   OUT_col = vec4((irradiance + specular* horizon) , 0);//alpha writes disabled
+   OUT_col = vec4((irradiance + specular* horizon)*ambientColor, 0);//alpha writes disabled
 #endif
 }

+ 2 - 2
Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/reflectionProbeArrayP.hlsl

@@ -8,7 +8,7 @@ TORQUE_UNIFORM_SAMPLER2D(deferredBuffer, 0);
 TORQUE_UNIFORM_SAMPLER2D(colorBuffer, 1);
 TORQUE_UNIFORM_SAMPLER2D(matInfoBuffer, 2);
 TORQUE_UNIFORM_SAMPLER2D(BRDFTexture, 3);
-
+uniform float3 ambientColor;
 uniform float4 rtParams0;
 uniform float4 vsFarPlane;
 uniform float4x4 cameraToWorld;
@@ -190,6 +190,6 @@ float4 main(PFXVertToPix IN) : SV_TARGET
 #if CAPTURING == 1
     return float4(lerp(surface.baseColor.rgb,(irradiance + specular* horizon) ,surface.metalness/2),0);
 #else
-   return float4((irradiance + specular* horizon) , 0);//alpha writes disabled   
+   return float4((irradiance + specular* horizon)*ambientColor, 0);//alpha writes disabled   
 #endif
 }