/** Sets shader parameter values */ void SetParameters( FRHICommandList& RHICmdList, FSamplerStateRHIParamRef SamplerStateRHI, FTextureRHIParamRef FilterTextureRHI, FTextureRHIParamRef AdditiveTextureRHI, const FLinearColor* SampleWeightValues, const FVector2D* SampleOffsetValues, uint32 NumSamples ) { check(CompileTimeNumSamples == 0 && NumSamples > 0 && NumSamples <= MAX_FILTER_SAMPLES || CompileTimeNumSamples == NumSamples); const FPixelShaderRHIParamRef ShaderRHI = GetPixelShader(); SetTextureParameter(RHICmdList, ShaderRHI, FilterTexture, FilterTextureSampler, SamplerStateRHI, FilterTextureRHI); SetTextureParameter(RHICmdList, ShaderRHI, AdditiveTexture, AdditiveTextureSampler, SamplerStateRHI, AdditiveTextureRHI); SetShaderValueArray(RHICmdList, ShaderRHI, SampleWeights, SampleWeightValues, NumSamples); if (CompileTimeNumSamples == 0) { // we needs additional setups for the dynamic loop FVector4 PackedSampleOffsetsValues[MAX_PACKED_SAMPLES_OFFSET]; for(uint32 SampleIndex = 0;SampleIndex < NumSamples;SampleIndex += 2) { PackedSampleOffsetsValues[SampleIndex / 2].X = SampleOffsetValues[SampleIndex + 0].X; PackedSampleOffsetsValues[SampleIndex / 2].Y = SampleOffsetValues[SampleIndex + 0].Y; if(SampleIndex + 1 < NumSamples) { PackedSampleOffsetsValues[SampleIndex / 2].W = SampleOffsetValues[SampleIndex + 1].X; PackedSampleOffsetsValues[SampleIndex / 2].Z = SampleOffsetValues[SampleIndex + 1].Y; } } SetShaderValueArray(RHICmdList, ShaderRHI, SampleOffsets, PackedSampleOffsetsValues, MAX_PACKED_SAMPLES_OFFSET); SetShaderValue(RHICmdList, ShaderRHI, SampleCount, NumSamples); } }
void SetPS(const FRenderingCompositePassContext& Context, uint16 InShadingModelMaskInView) { const FPixelShaderRHIParamRef ShaderRHI = GetPixelShader(); FGlobalShader::SetParameters(Context.RHICmdList, ShaderRHI, Context.View); PostprocessParameter.SetPS(ShaderRHI, Context, TStaticSamplerState<SF_Point,AM_Clamp,AM_Clamp,AM_Clamp>::GetRHI()); DeferredParameters.Set(Context.RHICmdList, ShaderRHI, Context.View); static FLinearColor SoftBits[sizeof(InShadingModelMaskInView) * 8] = {}; // init with 0.0f for(uint32 i = 0; i < sizeof(InShadingModelMaskInView) * 8; ++i) { float& ref = SoftBits[i].R; ref -= Context.View.Family->DeltaWorldTime; ref = FMath::Max(0.0f, ref); if(InShadingModelMaskInView & (1 << i)) { ref = 1.0f; } } SetShaderValueArray(Context.RHICmdList, ShaderRHI, ShadingModelMaskInView, SoftBits, sizeof(InShadingModelMaskInView) * 8); }
void SetParameters(FRHICommandList& RHICmdList, const FScene* Scene, const FSceneView& View, const FMatrix& WorldToShadowValue, int32 NumPlanes, const FPlane* PlaneData, const FVector4& ShadowBoundingSphereValue) { FComputeShaderRHIParamRef ShaderRHI = GetComputeShader(); FGlobalShader::SetParameters(RHICmdList, ShaderRHI, View); ObjectBufferParameters.Set(RHICmdList, ShaderRHI, *(Scene->DistanceFieldSceneData.ObjectBuffers), Scene->DistanceFieldSceneData.NumObjectsInBuffer); ObjectIndirectArguments.SetBuffer(RHICmdList, ShaderRHI, GShadowCulledObjectBuffers.Buffers.ObjectIndirectArguments); CulledObjectBounds.SetBuffer(RHICmdList, ShaderRHI, GShadowCulledObjectBuffers.Buffers.Bounds); CulledObjectData.SetBuffer(RHICmdList, ShaderRHI, GShadowCulledObjectBuffers.Buffers.Data); CulledObjectBoxBounds.SetBuffer(RHICmdList, ShaderRHI, GShadowCulledObjectBuffers.Buffers.BoxBounds); SetShaderValue(RHICmdList, ShaderRHI, ObjectBoundingGeometryIndexCount, StencilingGeometry::GLowPolyStencilSphereIndexBuffer.GetIndexCount()); SetShaderValue(RHICmdList, ShaderRHI, WorldToShadow, WorldToShadowValue); SetShaderValue(RHICmdList, ShaderRHI, ShadowBoundingSphere, ShadowBoundingSphereValue); if (NumPlanes < 12) { SetShaderValue(RHICmdList, ShaderRHI, NumShadowHullPlanes, NumPlanes); SetShaderValueArray(RHICmdList, ShaderRHI, ShadowConvexHull, PlaneData, NumPlanes); } else { SetShaderValue(RHICmdList, ShaderRHI, NumShadowHullPlanes, 0); } }
/** Sets shader parameter values */ void SetParameters(FRHICommandList& RHICmdList, FSamplerStateRHIParamRef SamplerStateRHI, FTextureRHIParamRef FilterTextureRHI, FTextureRHIParamRef AdditiveTextureRHI, const FLinearColor* SampleWeightValues) { const FPixelShaderRHIParamRef ShaderRHI = GetPixelShader(); SetTextureParameter(RHICmdList, ShaderRHI, FilterTexture, FilterTextureSampler, SamplerStateRHI, FilterTextureRHI); SetTextureParameter(RHICmdList, ShaderRHI, AdditiveTexture, AdditiveTextureSampler, SamplerStateRHI, AdditiveTextureRHI); SetShaderValueArray(RHICmdList, ShaderRHI, SampleWeights, SampleWeightValues, NumSamples); }
void SetPS(const FRenderingCompositePassContext& Context) { const FPixelShaderRHIParamRef ShaderRHI = GetPixelShader(); FGlobalShader::SetParameters(Context.RHICmdList, ShaderRHI, Context.View); const FPostProcessSettings& Settings = Context.View.FinalPostProcessSettings; const FSceneViewFamily& ViewFamily = *(Context.View.Family); PostprocessParameter.SetPS(ShaderRHI, Context, TStaticSamplerState<SF_Point,AM_Clamp,AM_Clamp,AM_Clamp>::GetRHI()); { FVector4 Temp[3]; FRCPassPostProcessEyeAdaptation::ComputeEyeAdaptationParamsValue(Context.View, Temp); SetShaderValueArray(Context.RHICmdList, ShaderRHI, EyeAdaptationParams, Temp, 3); } SetTextureParameter(Context.RHICmdList, ShaderRHI, MiniFontTexture, GEngine->MiniFontTexture ? GEngine->MiniFontTexture->Resource->TextureRHI : GSystemTextures.WhiteDummy->GetRenderTargetItem().TargetableTexture); { FIntPoint GatherExtent = FRCPassPostProcessHistogram::ComputeGatherExtent(Context.View); uint32 TexelPerThreadGroupX = FRCPassPostProcessHistogram::ThreadGroupSizeX * FRCPassPostProcessHistogram::LoopCountX; uint32 TexelPerThreadGroupY = FRCPassPostProcessHistogram::ThreadGroupSizeY * FRCPassPostProcessHistogram::LoopCountY; FIntRect Value(GatherExtent, FIntPoint(TexelPerThreadGroupX, TexelPerThreadGroupY)); SetShaderValue(Context.RHICmdList, ShaderRHI, HistogramParams, Value); } { float InvDisplayGammaValue = 1.0f / ViewFamily.RenderTarget->GetDisplayGamma(); SetShaderValue(Context.RHICmdList, ShaderRHI, InverseGamma, InvDisplayGammaValue); } { FVector4 Constants[8]; FilmPostSetConstants(Constants, ~0, &Context.View.FinalPostProcessSettings, false); SetShaderValue(Context.RHICmdList, ShaderRHI, ColorMatrixR_ColorCurveCd1, Constants[0]); SetShaderValue(Context.RHICmdList, ShaderRHI, ColorMatrixG_ColorCurveCd3Cm3, Constants[1]); SetShaderValue(Context.RHICmdList, ShaderRHI, ColorMatrixB_ColorCurveCm2, Constants[2]); SetShaderValue(Context.RHICmdList, ShaderRHI, ColorCurve_Cm0Cd0_Cd2_Ch0Cm1_Ch3, Constants[3]); SetShaderValue(Context.RHICmdList, ShaderRHI, ColorCurve_Ch1_Ch2, Constants[4]); SetShaderValue(Context.RHICmdList, ShaderRHI, ColorShadow_Luma, Constants[5]); SetShaderValue(Context.RHICmdList, ShaderRHI, ColorShadow_Tint1, Constants[6]); SetShaderValue(Context.RHICmdList, ShaderRHI, ColorShadow_Tint2, Constants[7]); } }
void SetPS(const FRenderingCompositePassContext& Context) { const FPixelShaderRHIParamRef ShaderRHI = GetPixelShader(); FGlobalShader::SetParameters(Context.RHICmdList, ShaderRHI, Context.View); PostprocessParameter.SetPS(ShaderRHI, Context, TStaticSamplerState<SF_Bilinear,AM_Clamp,AM_Clamp,AM_Clamp>::GetRHI()); { FVector4 Temp[3]; FRCPassPostProcessEyeAdaptation::ComputeEyeAdaptationParamsValue(Context.View, Temp); SetShaderValueArray(Context.RHICmdList, ShaderRHI, EyeAdaptationParams, Temp, 3); } }
void SetParameters(const FRenderingCompositePassContext& Context) { const FPixelShaderRHIParamRef ShaderRHI = GetPixelShader(); FGlobalShader::SetParameters(Context.RHICmdList, ShaderRHI, Context.View); PostprocessParameter.SetPS(ShaderRHI, Context, TStaticSamplerState<SF_Point,AM_Border,AM_Border,AM_Clamp>::GetRHI()); DeferredParameters.Set(Context.RHICmdList, ShaderRHI, Context.View); { FVector4 DepthOfFieldParamValues[2]; FRCPassPostProcessBokehDOF::ComputeDepthOfFieldParams(Context, DepthOfFieldParamValues); SetShaderValueArray(Context.RHICmdList, ShaderRHI, DepthOfFieldParams, DepthOfFieldParamValues, 2); } }
void SetPS(const FRenderingCompositePassContext& Context) { const FPixelShaderRHIParamRef ShaderRHI = GetPixelShader(); FGlobalShader::SetParameters(Context.RHICmdList, ShaderRHI, Context.View); PostprocessParameter.SetPS(ShaderRHI, Context, TStaticSamplerState<SF_Point,AM_Clamp,AM_Clamp,AM_Clamp>::GetRHI()); DeferredParameters.Set(Context.RHICmdList, ShaderRHI, Context.View); { FVector4 Temp[3]; FRCPassPostProcessEyeAdaptation::ComputeEyeAdaptationParamsValue(Context.View, Temp); SetShaderValueArray(Context.RHICmdList, ShaderRHI, EyeAdaptationParams, Temp, 3); } SetTextureParameter(Context.RHICmdList, ShaderRHI, MiniFontTexture, GEngine->MiniFontTexture ? GEngine->MiniFontTexture->Resource->TextureRHI : GSystemTextures.WhiteDummy->GetRenderTargetItem().TargetableTexture); }
void SetCS(const FRenderingCompositePassContext& Context, FIntPoint ThreadGroupCountValue, FIntPoint LeftTopOffsetValue, FIntPoint GatherExtent) { const FComputeShaderRHIParamRef ShaderRHI = GetComputeShader(); FGlobalShader::SetParameters(ShaderRHI, Context.View); PostprocessParameter.SetCS(ShaderRHI, Context, TStaticSamplerState<SF_Point,AM_Clamp,AM_Clamp,AM_Clamp>::GetRHI()); SetShaderValue(ShaderRHI, ThreadGroupCount, ThreadGroupCountValue); SetShaderValue(ShaderRHI, LeftTopOffset, LeftTopOffsetValue); FVector4 HistogramParametersValue(GatherExtent.X, GatherExtent.Y, 0, 0); SetShaderValue(ShaderRHI, HistogramParameters, HistogramParametersValue); { FVector4 Temp[3]; FRCPassPostProcessEyeAdaptation::ComputeEyeAdaptationParamsValue(Context.View, Temp); SetShaderValueArray(ShaderRHI, EyeAdaptationParams, Temp, 3); } }
void SetParameters(FRHICommandList& RHICmdList, const FScene* Scene, const FSceneView& View, const FProjectedShadowInfo* ProjectedShadowInfo) { FComputeShaderRHIParamRef ShaderRHI = GetComputeShader(); FGlobalShader::SetParameters(RHICmdList, ShaderRHI, View); ObjectBufferParameters.Set(RHICmdList, ShaderRHI, *(Scene->DistanceFieldSceneData.ObjectBuffers), Scene->DistanceFieldSceneData.NumObjectsInBuffer); ObjectIndirectArguments.SetBuffer(RHICmdList, ShaderRHI, GShadowCulledObjectBuffers.Buffers.ObjectIndirectArguments); CulledObjectBounds.SetBuffer(RHICmdList, ShaderRHI, GShadowCulledObjectBuffers.Buffers.Bounds); CulledObjectData.SetBuffer(RHICmdList, ShaderRHI, GShadowCulledObjectBuffers.Buffers.Data); CulledObjectBoxBounds.SetBuffer(RHICmdList, ShaderRHI, GShadowCulledObjectBuffers.Buffers.BoxBounds); SetShaderValue(RHICmdList, ShaderRHI, ObjectBoundingGeometryIndexCount, StencilingGeometry::GLowPolyStencilSphereIndexBuffer.GetIndexCount()); const FMatrix WorldToShadowValue = FTranslationMatrix(ProjectedShadowInfo->PreShadowTranslation) * ProjectedShadowInfo->SubjectAndReceiverMatrix; SetShaderValue(RHICmdList, ShaderRHI, WorldToShadow, WorldToShadowValue); int32 NumPlanes = 0; const FPlane* PlaneData = NULL; FVector4 ShadowBoundingSphereValue(0, 0, 0, 0); if (ProjectedShadowInfo->bDirectionalLight) { NumPlanes = ProjectedShadowInfo->CascadeSettings.ShadowBoundsAccurate.Planes.Num(); PlaneData = ProjectedShadowInfo->CascadeSettings.ShadowBoundsAccurate.Planes.GetData(); } else if (ProjectedShadowInfo->bOnePassPointLightShadow) { ShadowBoundingSphereValue = FVector4(ProjectedShadowInfo->ShadowBounds.Center.X, ProjectedShadowInfo->ShadowBounds.Center.Y, ProjectedShadowInfo->ShadowBounds.Center.Z, ProjectedShadowInfo->ShadowBounds.W); } else { NumPlanes = ProjectedShadowInfo->CasterFrustum.Planes.Num(); PlaneData = ProjectedShadowInfo->CasterFrustum.Planes.GetData(); ShadowBoundingSphereValue = FVector4(ProjectedShadowInfo->PreShadowTranslation, 0); } check(NumPlanes < 12); SetShaderValue(RHICmdList, ShaderRHI, NumShadowHullPlanes, NumPlanes); SetShaderValue(RHICmdList, ShaderRHI, ShadowBoundingSphere, ShadowBoundingSphereValue); SetShaderValueArray(RHICmdList, ShaderRHI, ShadowConvexHull, PlaneData, NumPlanes); }
void SetParameters(const FRenderingCompositePassContext& Context) { const FPixelShaderRHIParamRef ShaderRHI = GetPixelShader(); const FSceneView& View = Context.View; FGlobalShader::SetParameters(Context.RHICmdList, ShaderRHI, View); PostprocessParameter.SetPS(ShaderRHI, Context, TStaticSamplerState<SF_Bilinear,AM_Clamp,AM_Clamp,AM_Clamp>::GetRHI()); { FVector4 Value[3]; float Alpha = View.FinalPostProcessSettings.SceneFringeSaturation; float t = 1.0f / 3.0f; Value[0] = FMath::Lerp(FVector4(t, t, t, 0), FVector4(1, 0, 0, 0), Alpha); Value[1] = FMath::Lerp(FVector4(t, t, t, 0), FVector4(0, 1, 0, 0), Alpha); Value[2] = FMath::Lerp(FVector4(t, t, t, 0), FVector4(0, 0, 1, 0), Alpha); SetShaderValueArray(Context.RHICmdList, ShaderRHI, FringeColorParams, Value, 3); } }
void SetParameters(const FRenderingCompositePassContext& Context) { const FPixelShaderRHIParamRef ShaderRHI = GetPixelShader(); FGlobalShader::SetParameters(Context.RHICmdList, ShaderRHI, Context.View); DeferredParameters.Set(Context.RHICmdList, ShaderRHI, Context.View); PostprocessParameter.SetPS(ShaderRHI, Context, TStaticSamplerState<SF_Bilinear,AM_Clamp,AM_Clamp,AM_Clamp>::GetRHI()); FSceneRenderTargets& SceneContext = FSceneRenderTargets::Get(Context.RHICmdList); FIntPoint OutScaledSize; float OutScale; SceneContext.GetSeparateTranslucencyDimensions(OutScaledSize, OutScale); SetShaderValue(Context.RHICmdList, ShaderRHI, SeparateTranslucencyResMultParam, FVector4(OutScale, OutScale, OutScale, OutScale)); { FVector4 DepthOfFieldParamValues[2]; FRCPassPostProcessBokehDOF::ComputeDepthOfFieldParams(Context, DepthOfFieldParamValues); SetShaderValueArray(Context.RHICmdList, ShaderRHI, DepthOfFieldParams, DepthOfFieldParamValues, 2); } if (UseNearestDepthNeighborUpsample()) { check(SceneContext.IsSeparateTranslucencyDepthValid()); FTextureRHIParamRef LowResDepth = SceneContext.GetSeparateTranslucencyDepthSurface(); SetTextureParameter(Context.RHICmdList, ShaderRHI, LowResDepthTexture, LowResDepth); const auto& BuiltinSamplersUBParameter = GetUniformBufferParameter<FBuiltinSamplersParameters>(); SetUniformBufferParameter(Context.RHICmdList, ShaderRHI, BuiltinSamplersUBParameter, GBuiltinSamplersUniformBuffer.GetUniformBufferRHI()); } else { checkSlow(!LowResDepthTexture.IsBound()); } }
void SetParameters(const FVisualizeTextureData& Data) { const FPixelShaderRHIParamRef ShaderRHI = GetPixelShader(); { // alternates between 0 and 1 with a short pause const float FracTimeScale = 2.0f; float FracTime = GCurrentTime * FracTimeScale - floor(GCurrentTime * FracTimeScale); float BlinkState = (FracTime > 0.5f) ? 1.0f : 0.0f; FVector4 VisualizeParamValue[3]; float Add = 0.0f; float FracScale = 1.0f; // w * almost_1 to avoid frac(1) => 0 VisualizeParamValue[0] = FVector4(Data.RGBMul, Data.AMul, Add, FracScale * 0.9999f); VisualizeParamValue[1] = FVector4(BlinkState, Data.bSaturateInsteadOfFrac ? 1.0f : 0.0f, Data.ArrayIndex, Data.CustomMip); VisualizeParamValue[2] = FVector4(Data.InputValueMapping, 0, 0,0); SetShaderValueArray(ShaderRHI, VisualizeParam, VisualizeParamValue, 3); } { FVector4 TextureExtentValue(Data.Desc.Extent.X, Data.Desc.Extent.Y, Data.Desc.Depth, 0); SetShaderValue(ShaderRHI, TextureExtent, TextureExtentValue); } SetSRVParameter( ShaderRHI, VisualizeDepthStencilTexture, Data.StencilSRV ); SetTextureParameter(ShaderRHI, VisualizeTexture2D, VisualizeTexture2DSampler, TStaticSamplerState<SF_Point,AM_Clamp,AM_Clamp,AM_Clamp>::GetRHI(), (FTextureRHIRef&)Data.RenderTargetItem.ShaderResourceTexture); SetTextureParameter(ShaderRHI, VisualizeTexture2DMS, (FTextureRHIRef&)Data.RenderTargetItem.TargetableTexture); SetTextureParameter(ShaderRHI, VisualizeTexture3D, VisualizeTexture3DSampler, TStaticSamplerState<SF_Point,AM_Clamp,AM_Clamp,AM_Clamp>::GetRHI(), (FTextureRHIRef&)Data.RenderTargetItem.ShaderResourceTexture); SetTextureParameter(ShaderRHI, VisualizeTextureCube, VisualizeTextureCubeSampler, TStaticSamplerState<SF_Point,AM_Clamp,AM_Clamp,AM_Clamp>::GetRHI(), (FTextureRHIRef&)Data.RenderTargetItem.ShaderResourceTexture); SetTextureParameter(ShaderRHI, VisualizeTextureCubeArray, VisualizeTextureCubeArraySampler, TStaticSamplerState<SF_Point,AM_Clamp,AM_Clamp,AM_Clamp>::GetRHI(), (FTextureRHIRef&)Data.RenderTargetItem.ShaderResourceTexture); }
// TODO support ExcludeRect void DrawClearQuadMRT(FRHICommandList& RHICmdList, ERHIFeatureLevel::Type FeatureLevel, bool bClearColor, int32 NumClearColors, const FLinearColor* ClearColorArray, bool bClearDepth, float Depth, bool bClearStencil, uint32 Stencil) { // Set new states FBlendStateRHIParamRef BlendStateRHI; if (NumClearColors <= 1) { BlendStateRHI = bClearColor ? TStaticBlendState<>::GetRHI() : TStaticBlendState<CW_NONE>::GetRHI(); } else { BlendStateRHI = bClearColor ? TStaticBlendState<>::GetRHI() : TStaticBlendStateWriteMask<CW_NONE,CW_NONE,CW_NONE,CW_NONE,CW_NONE,CW_NONE,CW_NONE,CW_NONE>::GetRHI(); } const FDepthStencilStateRHIParamRef DepthStencilStateRHI = (bClearDepth && bClearStencil) ? TStaticDepthStencilState< true, CF_Always, true,CF_Always,SO_Replace,SO_Replace,SO_Replace, false,CF_Always,SO_Replace,SO_Replace,SO_Replace, 0xff,0xff >::GetRHI() : bClearDepth ? TStaticDepthStencilState<true, CF_Always>::GetRHI() : bClearStencil ? TStaticDepthStencilState< false, CF_Always, true,CF_Always,SO_Replace,SO_Replace,SO_Replace, false,CF_Always,SO_Replace,SO_Replace,SO_Replace, 0xff,0xff >::GetRHI() : TStaticDepthStencilState<false, CF_Always>::GetRHI(); RHICmdList.SetRasterizerState(TStaticRasterizerState<FM_Solid, CM_None>::GetRHI()); RHICmdList.SetBlendState(BlendStateRHI); RHICmdList.SetDepthStencilState(DepthStencilStateRHI); auto ShaderMap = GetGlobalShaderMap(FeatureLevel); // Set the new shaders TShaderMapRef<TOneColorVS<true> > VertexShader(ShaderMap); FOneColorPS* PixelShader = NULL; // Set the shader to write to the appropriate number of render targets // On AMD PC hardware, outputting to a color index in the shader without a matching render target set has a significant performance hit if (NumClearColors <= 1) { TShaderMapRef<TOneColorPixelShaderMRT<1> > MRTPixelShader(ShaderMap); PixelShader = *MRTPixelShader; } else if (NumClearColors == 2) { TShaderMapRef<TOneColorPixelShaderMRT<2> > MRTPixelShader(ShaderMap); PixelShader = *MRTPixelShader; } else if (NumClearColors == 3) { TShaderMapRef<TOneColorPixelShaderMRT<3> > MRTPixelShader(ShaderMap); PixelShader = *MRTPixelShader; } else if (NumClearColors == 4) { TShaderMapRef<TOneColorPixelShaderMRT<4> > MRTPixelShader(ShaderMap); PixelShader = *MRTPixelShader; } else if (NumClearColors == 5) { TShaderMapRef<TOneColorPixelShaderMRT<5> > MRTPixelShader(ShaderMap); PixelShader = *MRTPixelShader; } else if (NumClearColors == 6) { TShaderMapRef<TOneColorPixelShaderMRT<6> > MRTPixelShader(ShaderMap); PixelShader = *MRTPixelShader; } else if (NumClearColors == 7) { TShaderMapRef<TOneColorPixelShaderMRT<7> > MRTPixelShader(ShaderMap); PixelShader = *MRTPixelShader; } else if (NumClearColors == 8) { TShaderMapRef<TOneColorPixelShaderMRT<8> > MRTPixelShader(ShaderMap); PixelShader = *MRTPixelShader; } SetGlobalBoundShaderState(RHICmdList, FeatureLevel, GClearMRTBoundShaderState[FMath::Max(NumClearColors - 1, 0)], GetVertexDeclarationFVector4(), *VertexShader, PixelShader); FLinearColor ShaderClearColors[MaxSimultaneousRenderTargets]; FMemory::Memzero(ShaderClearColors); for (int32 i = 0; i < NumClearColors; i++) { ShaderClearColors[i] = ClearColorArray[i]; } SetShaderValueArray(RHICmdList, PixelShader->GetPixelShader(),PixelShader->ColorParameter,ShaderClearColors,NumClearColors); { // Draw a fullscreen quad /*if(ExcludeRect.Width() > 0 && ExcludeRect.Height() > 0) { // with a hole in it (optimization in case the hardware has non constant clear performance) FVector4 OuterVertices[4]; OuterVertices[0].Set( -1.0f, 1.0f, Depth, 1.0f ); OuterVertices[1].Set( 1.0f, 1.0f, Depth, 1.0f ); OuterVertices[2].Set( 1.0f, -1.0f, Depth, 1.0f ); OuterVertices[3].Set( -1.0f, -1.0f, Depth, 1.0f ); float InvViewWidth = 1.0f / Viewport.Width; float InvViewHeight = 1.0f / Viewport.Height; FVector4 FractionRect = FVector4(ExcludeRect.Min.X * InvViewWidth, ExcludeRect.Min.Y * InvViewHeight, (ExcludeRect.Max.X - 1) * InvViewWidth, (ExcludeRect.Max.Y - 1) * InvViewHeight); FVector4 InnerVertices[4]; InnerVertices[0].Set( FMath::Lerp(-1.0f, 1.0f, FractionRect.X), FMath::Lerp(1.0f, -1.0f, FractionRect.Y), Depth, 1.0f ); InnerVertices[1].Set( FMath::Lerp(-1.0f, 1.0f, FractionRect.Z), FMath::Lerp(1.0f, -1.0f, FractionRect.Y), Depth, 1.0f ); InnerVertices[2].Set( FMath::Lerp(-1.0f, 1.0f, FractionRect.Z), FMath::Lerp(1.0f, -1.0f, FractionRect.W), Depth, 1.0f ); InnerVertices[3].Set( FMath::Lerp(-1.0f, 1.0f, FractionRect.X), FMath::Lerp(1.0f, -1.0f, FractionRect.W), Depth, 1.0f ); FVector4 Vertices[10]; Vertices[0] = OuterVertices[0]; Vertices[1] = InnerVertices[0]; Vertices[2] = OuterVertices[1]; Vertices[3] = InnerVertices[1]; Vertices[4] = OuterVertices[2]; Vertices[5] = InnerVertices[2]; Vertices[6] = OuterVertices[3]; Vertices[7] = InnerVertices[3]; Vertices[8] = OuterVertices[0]; Vertices[9] = InnerVertices[0]; DrawPrimitiveUP(RHICmdList, PT_TriangleStrip, 8, Vertices, sizeof(Vertices[0]) ); } else*/ { // without a hole FVector4 Vertices[4]; Vertices[0].Set( -1.0f, 1.0f, Depth, 1.0f ); Vertices[1].Set( 1.0f, 1.0f, Depth, 1.0f ); Vertices[2].Set( -1.0f, -1.0f, Depth, 1.0f ); Vertices[3].Set( 1.0f, -1.0f, Depth, 1.0f ); DrawPrimitiveUP(RHICmdList, PT_TriangleStrip, 2, Vertices, sizeof(Vertices[0])); } } }
/** * Clears view where Z is still at the maximum value (ie no geometry rendered) */ void FDeferredShadingSceneRenderer::ClearGBufferAtMaxZ() { // Assumes BeginRenderingSceneColor() has been called before this function SCOPED_DRAW_EVENT(ClearGBufferAtMaxZ, DEC_SCENE_ITEMS); // Clear the G Buffer render targets const bool bClearBlack = Views[0].Family->EngineShowFlags.ShaderComplexity || Views[0].Family->EngineShowFlags.StationaryLightOverlap; // Same clear color from RHIClearMRT FLinearColor ClearColors[6] = {bClearBlack ? FLinearColor(0,0,0,0) : Views[0].BackgroundColor, FLinearColor(0.5f,0.5f,0.5f,0), FLinearColor(0,0,0,1), FLinearColor(0,0,0,0), FLinearColor(0,1,1,1), FLinearColor(1,1,1,1)}; uint32 NumActiveRenderTargets = GSceneRenderTargets.GetNumGBufferTargets(); TShaderMapRef<FOneColorVS> VertexShader(GetGlobalShaderMap()); FOneColorPS* PixelShader = NULL; // Assume for now all code path supports SM4, otherwise render target numbers are changed switch(NumActiveRenderTargets) { case 5: { TShaderMapRef<TOneColorPixelShaderMRT<5> > MRTPixelShader(GetGlobalShaderMap()); PixelShader = *MRTPixelShader; } break; case 6: { TShaderMapRef<TOneColorPixelShaderMRT<6> > MRTPixelShader(GetGlobalShaderMap()); PixelShader = *MRTPixelShader; } break; default: case 1: { TShaderMapRef<TOneColorPixelShaderMRT<1> > MRTPixelShader(GetGlobalShaderMap()); PixelShader = *MRTPixelShader; } break; } SetGlobalBoundShaderState(GClearMRTBoundShaderState[NumActiveRenderTargets - 1], GetVertexDeclarationFVector4(), *VertexShader, PixelShader); // Opaque rendering, depth test but no depth writes RHISetRasterizerState( TStaticRasterizerState<FM_Solid,CM_None>::GetRHI() ); RHISetBlendState(TStaticBlendStateWriteMask<>::GetRHI()); // Note, this is a reversed Z depth surface, using CF_GreaterEqual. RHISetDepthStencilState(TStaticDepthStencilState<false,CF_GreaterEqual>::GetRHI()); // Clear each viewport by drawing background color at MaxZ depth for(int32 ViewIndex = 0;ViewIndex < Views.Num();ViewIndex++) { SCOPED_CONDITIONAL_DRAW_EVENTF(EventView, Views.Num() > 1, DEC_SCENE_ITEMS, TEXT("ClearView%d"), ViewIndex); FViewInfo& View = Views[ViewIndex]; // Set viewport for this view RHISetViewport(View.ViewRect.Min.X, View.ViewRect.Min.Y, 0, View.ViewRect.Max.X, View.ViewRect.Max.Y, 1); // Setup PS SetShaderValueArray(PixelShader->GetPixelShader(),PixelShader->ColorParameter, ClearColors, NumActiveRenderTargets); // Render quad RHIDrawPrimitiveUP(PT_TriangleStrip, 2, ClearQuadVertices, sizeof(ClearQuadVertices[0]) ); } }