diff --git a/Engine/source/materials/materialFeatureTypes.cpp b/Engine/source/materials/materialFeatureTypes.cpp index 921236ce3..0b5c76b1e 100644 --- a/Engine/source/materials/materialFeatureTypes.cpp +++ b/Engine/source/materials/materialFeatureTypes.cpp @@ -51,6 +51,7 @@ ImplementFeatureType( MFT_Imposter, U32(-1), -1, true ); ImplementFeatureType( MFT_AccuMap, MFG_PreLighting, 2.0f, true ); +ImplementFeatureType(MFT_ReflectionProbes, MFG_Lighting, 1.0f, true); ImplementFeatureType( MFT_RTLighting, MFG_Lighting, 2.0f, true ); ImplementFeatureType( MFT_LightMap, MFG_Lighting, 3.0f, true ); ImplementFeatureType( MFT_ToneMap, MFG_Lighting, 4.0f, true ); @@ -62,7 +63,6 @@ ImplementFeatureType( MFT_SubSurface, MFG_Lighting, 8.0f, true ); ImplementFeatureType( MFT_VertLit, MFG_Lighting, 9.0f, true ); ImplementFeatureType( MFT_MinnaertShading, MFG_Lighting, 10.0f, true ); -ImplementFeatureType(MFT_ReflectionProbes, MFG_Lighting, 11.0f, true); ImplementFeatureType( MFT_GlowMask, MFG_PostLighting, 1.0f, true ); ImplementFeatureType( MFT_Visibility, MFG_PostLighting, 2.0f, true ); diff --git a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp index cd0d8d1f8..a7a6cfc39 100644 --- a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp +++ b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp @@ -2949,6 +2949,17 @@ ReflectionProbeFeatHLSL::ReflectionProbeFeatHLSL() addDependency(&mDep); } +void ReflectionProbeFeatHLSL::processVert(Vector& componentList, + const MaterialFeatureData& fd) +{ + MultiLine* meta = new MultiLine; + output = meta; + + // Also output the worldToTanget transform which + // we use to create the world space normal. + getOutWorldToTangent(componentList, meta, fd); +} + void ReflectionProbeFeatHLSL::processPix(Vector &componentList, const MaterialFeatureData &fd) { @@ -2969,8 +2980,6 @@ void ReflectionProbeFeatHLSL::processPix(Vector &componentList Var *wsPosition = getInWsPosition(componentList); Var *wsView = getWsView(wsPosition, meta); - Var *albedo = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::DefaultTarget)); - //Reflection Probe WIP U32 MAX_FORWARD_PROBES = 4; @@ -3070,15 +3079,7 @@ void ReflectionProbeFeatHLSL::processPix(Vector &componentList if (!inTex) return; - Var *diffuseColor = (Var*)LangElement::find("diffuseColor"); - if (!diffuseColor) - { - diffuseColor = new Var; - diffuseColor->setType("float4"); - diffuseColor->setName("diffuseColor"); - LangElement* colorDecl = new DecOp(diffuseColor); - meta->addStatement(new GenOp(" @ = float4(1.0,1.0,1.0,1.0);\r\n", colorDecl)); //default to flat white - } + Var *diffuseColor = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::DefaultTarget)); Var *matinfo = (Var*)LangElement::find("specularColor"); if (!matinfo) @@ -3114,30 +3115,18 @@ void ReflectionProbeFeatHLSL::processPix(Vector &componentList Var *wsEyePos = (Var*)LangElement::find("eyePosWorld"); - Var *worldToTangent = (Var*)LangElement::find("worldToTangent"); - if (!worldToTangent) - return; - - /*Var *worldToCamera = (Var*)LangElement::find("worldToCamera"); - if (!worldToCamera) - { - worldToCamera = new Var; - worldToCamera->setType("float4x4"); - worldToCamera->setName("worldToCamera"); - worldToCamera->uniform = true; - worldToCamera->constSortPos = cspPass; - }*/ + Var *worldToTangent = getInWorldToTangent(componentList); //Reflection vec Var *surface = new Var("surface", "Surface"); - meta->addStatement(new GenOp(" @ = createForwardSurface(@,@,@,@,@,@,@,@);\r\n\n", new DecOp(surface), diffuseColor, bumpNormal, matinfo, + meta->addStatement(new GenOp(" @ = createForwardSurface(@,@,@,@,@,@,@,float3x3(@));\r\n\n", new DecOp(surface), diffuseColor, bumpNormal, matinfo, inTex, wsPosition, wsEyePos, wsView, worldToTangent)); String computeForwardProbes = String::String(" @.rgb = computeForwardProbes(@,@,@,@,@,@,@,@,@,\r\n\t\t"); computeForwardProbes += String::String("@,TORQUE_SAMPLER2D_MAKEARG(@),\r\n\t\t"); computeForwardProbes += String::String("TORQUE_SAMPLERCUBE_MAKEARG(@), TORQUE_SAMPLERCUBE_MAKEARG(@), \r\n\t\t"); computeForwardProbes += String::String("TORQUE_SAMPLERCUBEARRAY_MAKEARG(@),TORQUE_SAMPLERCUBEARRAY_MAKEARG(@)).rgb; \r\n"); - meta->addStatement(new GenOp(computeForwardProbes.c_str(), albedo, surface, cubeMips, numProbes, worldToObjArray, probeConfigData, inProbePosArray, bbMinArray, bbMaxArray, inRefPosArray, + meta->addStatement(new GenOp(computeForwardProbes.c_str(), diffuseColor, surface, cubeMips, numProbes, worldToObjArray, probeConfigData, inProbePosArray, bbMinArray, bbMaxArray, inRefPosArray, hasSkylight, BRDFTexture, skylightIrradMap, skylightSpecularMap, irradianceCubemapAR, specularCubemapAR)); diff --git a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.h b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.h index 6303ae641..1aac22fc6 100644 --- a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.h +++ b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.h @@ -681,6 +681,9 @@ protected: public: ReflectionProbeFeatHLSL(); + virtual void processVert(Vector& componentList, + const MaterialFeatureData& fd); + virtual void processPix(Vector &componentList, const MaterialFeatureData &fd); diff --git a/Templates/Full/game/shaders/common/lighting.hlsl b/Templates/Full/game/shaders/common/lighting.hlsl index 7cdc3d484..62181ba1e 100644 --- a/Templates/Full/game/shaders/common/lighting.hlsl +++ b/Templates/Full/game/shaders/common/lighting.hlsl @@ -360,11 +360,8 @@ float4 computeForwardProbes(Surface surface, { blendFactor[i] *= invBlendSumWeighted; contribution[i] *= blendFactor[i]; - //alpha -= contribution[i]; } } - //else - // alpha -= blendSum; float3 irradiance = float3(0, 0, 0); float3 specular = float3(0, 0, 0); @@ -387,11 +384,11 @@ float4 computeForwardProbes(Surface surface, } }*/ - //if (hasSkylight && alpha > 0.001) - //{ + if (hasSkylight && alpha > 0.001) + { irradiance += TORQUE_TEXCUBELOD(skylightIrradMap, float4(surface.R, 0)).xyz; specular = TORQUE_TEXCUBELOD(skylightSpecularMap, float4(surface.R, lod)).xyz; - //} + } float3 F = FresnelSchlickRoughness(surface.NdotV, surface.f0, surface.roughness); @@ -408,7 +405,5 @@ float4 computeForwardProbes(Surface surface, float3 diffuse = kD * irradiance * surface.baseColor.rgb; float4 finalColor = float4(diffuse + specular, 1.0); - //finalColor = float4(max(diffuse, specular),1); - return finalColor; } \ No newline at end of file