internal static void OnDeviceReset() { MyHwBuffers.OnDeviceReset(); MyShaders.OnDeviceReset(); MyMaterialShaders.OnDeviceReset(); MyPipelineStates.OnDeviceReset(); MyTextures.OnDeviceReset(); MyRwTextures.OnDeviceEnd(); MyShadows.OnDeviceReset(); MyBillboardRenderer.OnDeviceRestart(); MyMeshMaterials1.InvalidateMaterials(); MyVoxelMaterials1.InvalidateMaterials(); MyRenderableComponent.MarkAllDirty(); foreach (var f in MyComponentFactory <MyFoliageComponent> .GetAll()) { f.Dispose(); } foreach (var c in MyComponentFactory <MyGroupRootComponent> .GetAll()) { c.OnDeviceReset(); } MyBigMeshTable.Table.OnDeviceReset(); MySceneMaterials.OnDeviceReset(); MyMeshes.OnDeviceReset(); MyInstancing.OnDeviceReset(); }
internal static void OnDeviceReset() { MyHwBuffers.OnDeviceReset(); MyShaders.OnDeviceReset(); MyMaterialShaders.OnDeviceReset(); MyPipelineStates.OnDeviceReset(); MyTextures.OnDeviceReset(); MyRwTextures.OnDeviceReset(); MyTransparentRendering.OnDeviceReset(); ResetShadows(Settings.ShadowCascadeCount, RenderSettings.ShadowQuality.ShadowCascadeResolution()); MyBillboardRenderer.OnDeviceRestart(); MyScreenDecals.OnDeviceReset(); MyMeshMaterials1.InvalidateMaterials(); MyVoxelMaterials1.InvalidateMaterials(); MyRenderableComponent.MarkAllDirty(); foreach (var f in MyComponentFactory <MyFoliageComponent> .GetAll()) { f.Dispose(); } foreach (var c in MyComponentFactory <MyGroupRootComponent> .GetAll()) { c.OnDeviceReset(); } MyBigMeshTable.Table.OnDeviceReset(); MySceneMaterials.OnDeviceReset(); MyMeshes.OnDeviceReset(); MyInstancing.OnDeviceReset(); MyScreenDecals.OnDeviceReset(); }
internal static void Init() { StandardSamplers[0] = MyPipelineStates.GetSampler(m_default); StandardSamplers[1] = MyPipelineStates.GetSampler(m_point); StandardSamplers[2] = MyPipelineStates.GetSampler(m_linear); StandardSamplers[3] = MyPipelineStates.GetSampler(m_texture); StandardSamplers[4] = MyPipelineStates.GetSampler(m_alphamask); StandardSamplers[5] = MyPipelineStates.GetSampler(m_alphamaskArray); }
internal static void OnDeviceEnd() { MyShaders.OnDeviceEnd(); MyMaterialShaders.OnDeviceEnd(); MyVoxelMaterials1.OnDeviceEnd(); MyTextures.OnDeviceEnd(); MyRwTextures.OnDeviceEnd(); MyHwBuffers.OnDeviceEnd(); MyPipelineStates.OnDeviceEnd(); }
static void InitializeRasterizerStates() { m_wireframeRasterizerState = MyPipelineStates.CreateRasterizerState(new RasterizerStateDescription { FillMode = FillMode.Wireframe, CullMode = CullMode.Back }); RasterizerStateDescription desc = new RasterizerStateDescription(); desc.FillMode = FillMode.Wireframe; desc.CullMode = CullMode.Back; m_wireframeRasterizerState = MyPipelineStates.CreateRasterizerState(desc); desc.FillMode = FillMode.Solid; desc.CullMode = CullMode.Front; m_invTriRasterizerState = MyPipelineStates.CreateRasterizerState(desc); desc.FillMode = FillMode.Solid; desc.CullMode = CullMode.None; m_nocullRasterizerState = MyPipelineStates.CreateRasterizerState(desc); desc.FillMode = FillMode.Wireframe; desc.CullMode = CullMode.None; m_nocullWireframeRasterizerState = MyPipelineStates.CreateRasterizerState(desc); desc = new RasterizerStateDescription(); desc.FillMode = FillMode.Solid; desc.CullMode = CullMode.Back; m_linesRasterizerState = MyPipelineStates.CreateRasterizerState(desc); desc = new RasterizerStateDescription(); desc.FillMode = FillMode.Solid; desc.CullMode = CullMode.None; desc.IsFrontCounterClockwise = true; desc.DepthBias = 20; desc.DepthBiasClamp = 2; desc.SlopeScaledDepthBias = 4; m_cascadesRasterizerState = MyPipelineStates.CreateRasterizerState(desc); desc = new RasterizerStateDescription(); desc.FillMode = FillMode.Solid; desc.CullMode = CullMode.None; desc.IsFrontCounterClockwise = true; desc.DepthBias = 25000; desc.DepthBiasClamp = 2; desc.SlopeScaledDepthBias = 1; m_shadowRasterizerState = MyPipelineStates.CreateRasterizerState(desc); desc.FillMode = FillMode.Solid; desc.CullMode = CullMode.Back; desc.IsFrontCounterClockwise = false; desc.IsScissorEnabled = true; m_scissorTestRasterizerState = MyPipelineStates.CreateRasterizerState(desc); }
internal static unsafe void InitSubsystems() { InitializeBlendStates(); InitializeRasterizerStates(); InitilizeSamplerStates(); MyCommon.Init(); MyPipelineStates.Init(); MyTextures.Init(); MyVertexLayouts.Init(); MyShaders.Init(); MyRwTextures.Init(); MyHwBuffers.Init(); MyMeshes.Init(); MyMeshTableSRV.Init(); MyMergeInstancing.Init(); MyGeometryRenderer.Init(); MyLightRendering.Init(); MyShadows.Init(); MyLinesRenderer.Init(); MySpritesRenderer.Init(); MyPrimitivesRenderer.Init(); MyFoliageRenderer.Init(); MyOutline.Init(); MyComponents.Init(); MyBillboardRenderer.Init(); // hardcoded limits MyDebugRenderer.Init(); MyGPUFoliageGenerating.Init(); MyScreenDecals.Init(); MyEnvProbeProcessing.Init(); MyShadowsResolve.Init(); MyAtmosphereRenderer.Init(); MyAAEdgeMarking.Init(); MyScreenPass.Init(); MyCopyToRT.Init(); MyBlendTargets.Init(); MyFXAA.Init(); MyDepthResolve.Init(); MyBloom.Init(); MyLuminanceAverage.Init(); MyToneMapping.Init(); MySSAO.Init(); MyHdrDebugTools.Init(); MySceneMaterials.Init(); MyMaterials1.Init(); MyVoxelMaterials1.Init(); MyMeshMaterials1.Init(); //MyShaderFactory.RunCompilation(); // rebuild }
internal static void OnDeviceEnd() { MyScreenDecals.OnDeviceEnd(); MyShaders.OnDeviceEnd(); MyMaterialShaders.OnDeviceEnd(); MyVoxelMaterials1.OnDeviceEnd(); MyTextures.OnDeviceEnd(); MyRwTextures.OnDeviceEnd(); MyHwBuffers.OnDeviceEnd(); MyPipelineStates.OnDeviceEnd(); MyTransparentRendering.OnDeviceEnd(); }
private static void InitilizeSamplerStates() { SamplerStateDescription description = new SamplerStateDescription(); description.AddressU = TextureAddressMode.Clamp; description.AddressV = TextureAddressMode.Clamp; description.AddressW = TextureAddressMode.Clamp; description.Filter = Filter.MinMagMipLinear; description.MaximumLod = System.Single.MaxValue; m_defaultSamplerState = MyPipelineStates.CreateSamplerState(description); description.AddressU = TextureAddressMode.Border; description.AddressV = TextureAddressMode.Border; description.AddressW = TextureAddressMode.Border; description.Filter = Filter.MinMagMipLinear; description.MaximumLod = System.Single.MaxValue; description.BorderColor = new Color4(0, 0, 0, 0); m_alphamaskSamplerState = MyPipelineStates.CreateSamplerState(description); description.AddressU = TextureAddressMode.Clamp; description.AddressV = TextureAddressMode.Clamp; description.AddressW = TextureAddressMode.Clamp; description.Filter = Filter.MinMagMipPoint; description.MaximumLod = System.Single.MaxValue; m_pointSamplerState = MyPipelineStates.CreateSamplerState(description); description.Filter = Filter.MinMagMipLinear; description.MaximumLod = System.Single.MaxValue; m_linearSamplerState = MyPipelineStates.CreateSamplerState(description); description.AddressU = TextureAddressMode.Clamp; description.AddressV = TextureAddressMode.Clamp; description.AddressW = TextureAddressMode.Clamp; description.Filter = Filter.ComparisonMinMagMipLinear; description.MaximumLod = System.Single.MaxValue; description.ComparisonFunction = Comparison.LessEqual; m_shadowmapSamplerState = MyPipelineStates.CreateSamplerState(description); m_textureSamplerState = MyPipelineStates.CreateSamplerState(description); m_alphamaskarraySamplerState = MyPipelineStates.CreateSamplerState(description); UpdateTextureSampler(m_textureSamplerState, TextureAddressMode.Wrap); UpdateTextureSampler(m_alphamaskarraySamplerState, TextureAddressMode.Clamp); StandardSamplers = new SamplerState[6]; StandardSamplers[0] = MyPipelineStates.GetSampler(m_defaultSamplerState); StandardSamplers[1] = MyPipelineStates.GetSampler(m_pointSamplerState); StandardSamplers[2] = MyPipelineStates.GetSampler(m_linearSamplerState); StandardSamplers[3] = MyPipelineStates.GetSampler(m_textureSamplerState); StandardSamplers[4] = MyPipelineStates.GetSampler(m_alphamaskSamplerState); StandardSamplers[5] = MyPipelineStates.GetSampler(m_alphamaskarraySamplerState); }
internal static unsafe void InitSubsystems() { MyRwTextures.Init(); MyHwBuffers.Init(); MyPipelineStates.Init(); ResetShadows(MyRenderProxy.Settings.ShadowCascadeCount, RenderSettings.ShadowQuality.ShadowCascadeResolution()); MyRender11.Init(); MyCommon.Init(); SamplerStates.Init(); MyDepthStencilState.Init(); MyTextures.Init(); MyVertexLayouts.Init(); MyShaders.Init(); MyMeshes.Init(); MyMeshTableSRV.Init(); MyLightRendering.Init(); MyLinesRenderer.Init(); MySpritesRenderer.Init(); MyPrimitivesRenderer.Init(); MyOutline.Init(); MyBlur.Init(); MyTransparentRendering.Init(); MyFoliageComponents.Init(); MyBillboardRenderer.Init(); // hardcoded limits MyDebugRenderer.Init(); MyScreenDecals.Init(); MyEnvProbeProcessing.Init(); MyAtmosphereRenderer.Init(); MyCloudRenderer.Init(); MyAAEdgeMarking.Init(); MyScreenPass.Init(); MyCopyToRT.Init(); MyBlendTargets.Init(); MyFXAA.Init(); MyDepthResolve.Init(); MyBloom.Init(); MyLuminanceAverage.Init(); MyToneMapping.Init(); MySSAO.Init(); MyPlanetBlur.Init(); MyHdrDebugTools.Init(); MySceneMaterials.Init(); MyMaterials1.Init(); MyVoxelMaterials1.Init(); MyMeshMaterials1.Init(); }
internal static void InitOnce() { SamplerStateDescription description = new SamplerStateDescription(); description.AddressU = TextureAddressMode.Clamp; description.AddressV = TextureAddressMode.Clamp; description.AddressW = TextureAddressMode.Clamp; description.Filter = Filter.MinMagMipLinear; description.MaximumLod = System.Single.MaxValue; m_default = MyPipelineStates.CreateSamplerState(description); description.AddressU = TextureAddressMode.Border; description.AddressV = TextureAddressMode.Border; description.AddressW = TextureAddressMode.Border; description.Filter = Filter.MinMagMipLinear; description.MaximumLod = System.Single.MaxValue; description.BorderColor = new Color4(0, 0, 0, 0); m_alphamask = MyPipelineStates.CreateSamplerState(description); description.AddressU = TextureAddressMode.Clamp; description.AddressV = TextureAddressMode.Clamp; description.AddressW = TextureAddressMode.Clamp; description.Filter = Filter.MinMagMipPoint; description.MaximumLod = System.Single.MaxValue; m_point = MyPipelineStates.CreateSamplerState(description); description.Filter = Filter.MinMagMipLinear; description.MaximumLod = System.Single.MaxValue; m_linear = MyPipelineStates.CreateSamplerState(description); description.AddressU = TextureAddressMode.Clamp; description.AddressV = TextureAddressMode.Clamp; description.AddressW = TextureAddressMode.Clamp; description.Filter = Filter.ComparisonMinMagMipLinear; description.MaximumLod = System.Single.MaxValue; description.ComparisonFunction = Comparison.LessEqual; m_shadowmap = MyPipelineStates.CreateSamplerState(description); m_texture = MyPipelineStates.CreateSamplerState(description); m_alphamaskArray = MyPipelineStates.CreateSamplerState(description); UpdateFiltering(); Init(); }
static void InitializeBlendStates() { BlendStateDescription desc = new BlendStateDescription(); desc.RenderTarget[0].IsBlendEnabled = true; desc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All; desc.RenderTarget[0].BlendOperation = BlendOperation.Add; desc.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add; desc.RenderTarget[0].DestinationBlend = BlendOption.InverseSourceAlpha; desc.RenderTarget[0].DestinationAlphaBlend = BlendOption.InverseSourceAlpha; desc.RenderTarget[0].SourceBlend = BlendOption.SourceAlpha; desc.RenderTarget[0].SourceAlphaBlend = BlendOption.SourceAlpha; BlendGui = MyPipelineStates.CreateBlendState(desc); desc.RenderTarget[0].IsBlendEnabled = true; desc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All; desc.RenderTarget[0].BlendOperation = BlendOperation.Add; desc.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add; desc.RenderTarget[0].DestinationBlend = BlendOption.One; desc.RenderTarget[0].DestinationAlphaBlend = BlendOption.One; desc.RenderTarget[0].SourceBlend = BlendOption.One; desc.RenderTarget[0].SourceAlphaBlend = BlendOption.One; BlendAdditive = MyPipelineStates.CreateBlendState(desc); desc.RenderTarget[0].IsBlendEnabled = true; desc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All; desc.RenderTarget[0].BlendOperation = BlendOperation.Add; desc.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add; desc.RenderTarget[0].DestinationBlend = BlendOption.InverseSourceAlpha; desc.RenderTarget[0].DestinationAlphaBlend = BlendOption.InverseSourceAlpha; desc.RenderTarget[0].SourceBlend = BlendOption.SourceAlpha; desc.RenderTarget[0].SourceAlphaBlend = BlendOption.One; BlendTransparent = MyPipelineStates.CreateBlendState(desc); desc.RenderTarget[0].IsBlendEnabled = true; desc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All; desc.RenderTarget[0].BlendOperation = BlendOperation.Add; desc.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add; desc.RenderTarget[0].DestinationBlend = BlendOption.InverseSourceAlpha; desc.RenderTarget[0].DestinationAlphaBlend = BlendOption.InverseSourceAlpha; desc.RenderTarget[0].SourceBlend = BlendOption.One; desc.RenderTarget[0].SourceAlphaBlend = BlendOption.One; BlendAlphaPremult = MyPipelineStates.CreateBlendState(desc); }
private static void UpdateTextureSampler(SamplerId samplerState, TextureAddressMode addressMode) { SamplerStateDescription description = new SamplerStateDescription(); description.AddressU = addressMode; description.AddressV = addressMode; description.AddressW = addressMode; description.MaximumLod = System.Single.MaxValue; if (MyRender11.RenderSettings.AnisotropicFiltering == MyTextureAnisoFiltering.NONE) { description.Filter = Filter.MinMagMipLinear; } else { description.Filter = Filter.Anisotropic; switch (MyRender11.RenderSettings.AnisotropicFiltering) { case MyTextureAnisoFiltering.ANISO_1: description.MaximumAnisotropy = 1; break; case MyTextureAnisoFiltering.ANISO_4: description.MaximumAnisotropy = 4; break; case MyTextureAnisoFiltering.ANISO_8: description.MaximumAnisotropy = 8; break; case MyTextureAnisoFiltering.ANISO_16: description.MaximumAnisotropy = 16; break; default: description.MaximumAnisotropy = 1; break; } } MyPipelineStates.ChangeSamplerState(samplerState, description); }
public static void ResizeMarkIfInsideCascade() { if (MarkIfInsideCascade == null || MarkIfInsideCascade.Length == 0) { return; } var desc = MyPipelineStates.GetDepthStencil(MarkIfInsideCascade[0]).Description; if (MarkIfInsideCascade.Length < MyRenderProxy.Settings.ShadowCascadeCount) { MarkIfInsideCascade = new DepthStencilId[MyRenderProxy.Settings.ShadowCascadeCount]; } for (int cascadeIndex = 0; cascadeIndex < MarkIfInsideCascade.Length; ++cascadeIndex) { desc.StencilWriteMask = (byte)(0x01 << cascadeIndex); MarkIfInsideCascade[cascadeIndex] = MyPipelineStates.CreateDepthStencil(desc); } }
internal static void Init() { m_proxyVs = MyShaders.CreateVs("clouds.hlsl"); m_cloudPs = MyShaders.CreatePs("clouds.hlsl"); m_proxyIL = MyShaders.CreateIL(m_proxyVs.BytecodeId, MyVertexLayouts.GetLayout( new MyVertexInputComponent(MyVertexInputComponentType.POSITION_PACKED, 0), new MyVertexInputComponent(MyVertexInputComponentType.NORMAL, 1), new MyVertexInputComponent(MyVertexInputComponentType.TANGENT_SIGN_OF_BITANGENT, 1), new MyVertexInputComponent(MyVertexInputComponentType.TEXCOORD0_H, 1))); m_fogShader = MyShaders.CreateCs("clouds.hlsl", new [] { new ShaderMacro("NUMTHREADS", m_numFogThreads) }); SamplerStateDescription description = new SamplerStateDescription { AddressU = TextureAddressMode.Wrap, AddressV = TextureAddressMode.Wrap, AddressW = TextureAddressMode.Wrap, Filter = Filter.MinMagMipLinear, MaximumLod = System.Single.MaxValue }; m_textureSampler = MyPipelineStates.CreateSamplerState(description); }
static MyDepthStencilState() { DepthStencilStateDescription desc = new DepthStencilStateDescription(); desc.DepthComparison = MyRender11.UseComplementaryDepthBuffer ? Comparison.Greater : Comparison.Less; desc.DepthWriteMask = DepthWriteMask.All; desc.IsDepthEnabled = true; desc.IsStencilEnabled = false; DepthTestWrite = MyPipelineStates.CreateDepthStencil(desc); desc.DepthComparison = MyRender11.UseComplementaryDepthBuffer ? Comparison.Greater : Comparison.Less; desc.DepthWriteMask = DepthWriteMask.Zero; desc.IsDepthEnabled = true; desc.IsStencilEnabled = false; DepthTest = MyPipelineStates.CreateDepthStencil(desc); desc.IsDepthEnabled = false; desc.IsStencilEnabled = false; IgnoreDepthStencil = MyPipelineStates.CreateDepthStencil(desc); desc.IsDepthEnabled = false; desc.IsStencilEnabled = true; desc.StencilReadMask = 0xFF; desc.StencilWriteMask = 0x80; desc.BackFace.Comparison = Comparison.Always; desc.BackFace.DepthFailOperation = StencilOperation.Replace; desc.BackFace.FailOperation = StencilOperation.Replace; desc.BackFace.PassOperation = StencilOperation.Replace; desc.FrontFace = desc.BackFace; MarkAAEdge = MyPipelineStates.CreateDepthStencil(desc); desc.IsDepthEnabled = false; desc.IsStencilEnabled = true; desc.StencilReadMask = 0x80; desc.StencilWriteMask = 0x00; desc.BackFace.Comparison = Comparison.Equal; desc.BackFace.DepthFailOperation = StencilOperation.Keep; desc.BackFace.FailOperation = StencilOperation.Keep; desc.BackFace.PassOperation = StencilOperation.Keep; desc.FrontFace = desc.BackFace; TestAAEdge = MyPipelineStates.CreateDepthStencil(desc); MarkIfInside = new DepthStencilId[4]; desc.IsDepthEnabled = true; desc.DepthComparison = MyRender11.UseComplementaryDepthBuffer ? Comparison.Less : Comparison.Greater; desc.DepthWriteMask = DepthWriteMask.Zero; desc.IsStencilEnabled = true; desc.StencilReadMask = 0x00; desc.StencilWriteMask = 0x01; desc.BackFace.Comparison = Comparison.Always; desc.BackFace.DepthFailOperation = StencilOperation.Keep; desc.BackFace.FailOperation = StencilOperation.Keep; desc.BackFace.PassOperation = StencilOperation.Replace; desc.FrontFace = desc.BackFace; MarkIfInside[0] = MyPipelineStates.CreateDepthStencil(desc); desc.StencilWriteMask = 0x02; MarkIfInside[1] = MyPipelineStates.CreateDepthStencil(desc); desc.StencilWriteMask = 0x04; MarkIfInside[2] = MyPipelineStates.CreateDepthStencil(desc); desc.StencilWriteMask = 0x08; MarkIfInside[3] = MyPipelineStates.CreateDepthStencil(desc); }
internal static unsafe void InitSubsystems() { MyRwTextures.Init(); MyHwBuffers.Init(); MyPipelineStates.Init(); ResetShadows(MyRenderProxy.Settings.ShadowCascadeCount, RenderSettings.ShadowQuality.ShadowCascadeResolution()); MyRender11.Init(); MyCommon.Init(); SamplerStates.Init(); MyDepthStencilState.Init(); MyTextures.Init(); MyVertexLayouts.Init(); MyShaders.Init(); MyMeshes.Init(); MyMeshTableSRV.Init(); MyLightRendering.Init(); MyLinesRenderer.Init(); MySpritesRenderer.Init(); MyPrimitivesRenderer.Init(); MyOutline.Init(); MyBlur.Init(); MyTransparentRendering.Init(); MyFoliageComponents.Init(); MyBillboardRenderer.Init(); // hardcoded limits MyDebugRenderer.Init(); MyScreenDecals.Init(); MyEnvProbeProcessing.Init(); MyAtmosphereRenderer.Init(); MyCloudRenderer.Init(); MyAAEdgeMarking.Init(); MyScreenPass.Init(); MyCopyToRT.Init(); MyBlendTargets.Init(); MyFXAA.Init(); MyDepthResolve.Init(); MyBloom.Init(); MyLuminanceAverage.Init(); MyToneMapping.Init(); MySSAO.Init(); MyPlanetBlur.Init(); MyHdrDebugTools.Init(); MySceneMaterials.Init(); MyMaterials1.Init(); MyVoxelMaterials1.Init(); MyMeshMaterials1.Init(); try { if (m_settings.UseStereoRendering) { var openVR = new MyOpenVR(); MyStereoStencilMask.InitUsingOpenVR(); } } catch (System.Exception e) { if (!VRage.MyCompilationSymbols.DX11ForceStereo) { throw; } MyStereoStencilMask.InitUsingUndefinedMask(); } }
static void InitializeBlendStates() { { BlendStateDescription desc = new BlendStateDescription(); desc.RenderTarget[0].IsBlendEnabled = true; desc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All; desc.RenderTarget[0].BlendOperation = BlendOperation.Add; desc.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add; desc.RenderTarget[0].DestinationBlend = BlendOption.InverseSourceAlpha; desc.RenderTarget[0].DestinationAlphaBlend = BlendOption.InverseSourceAlpha; desc.RenderTarget[0].SourceBlend = BlendOption.SourceAlpha; desc.RenderTarget[0].SourceAlphaBlend = BlendOption.SourceAlpha; BlendGui = MyPipelineStates.CreateBlendState(desc); } { BlendStateDescription desc = new BlendStateDescription(); desc.RenderTarget[0].IsBlendEnabled = true; desc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All; desc.RenderTarget[0].BlendOperation = BlendOperation.Add; desc.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add; desc.RenderTarget[0].DestinationBlend = BlendOption.One; desc.RenderTarget[0].DestinationAlphaBlend = BlendOption.One; desc.RenderTarget[0].SourceBlend = BlendOption.One; desc.RenderTarget[0].SourceAlphaBlend = BlendOption.One; BlendAdditive = MyPipelineStates.CreateBlendState(desc); } { BlendStateDescription desc = new BlendStateDescription(); desc.RenderTarget[0].IsBlendEnabled = true; desc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All; desc.RenderTarget[0].BlendOperation = BlendOperation.Add; desc.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add; desc.RenderTarget[0].DestinationBlend = BlendOption.SourceAlpha; desc.RenderTarget[0].DestinationAlphaBlend = BlendOption.One; desc.RenderTarget[0].SourceBlend = BlendOption.One; desc.RenderTarget[0].SourceAlphaBlend = BlendOption.One; BlendAtmosphere = MyPipelineStates.CreateBlendState(desc); } { BlendStateDescription desc = new BlendStateDescription(); desc.RenderTarget[0].IsBlendEnabled = true; desc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All; desc.RenderTarget[0].BlendOperation = BlendOperation.Add; desc.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add; desc.RenderTarget[0].DestinationBlend = BlendOption.InverseSourceAlpha; desc.RenderTarget[0].DestinationAlphaBlend = BlendOption.InverseSourceAlpha; desc.RenderTarget[0].SourceBlend = BlendOption.SourceAlpha; desc.RenderTarget[0].SourceAlphaBlend = BlendOption.SourceAlpha; BlendTransparent = MyPipelineStates.CreateBlendState(desc); } { BlendStateDescription desc = new BlendStateDescription(); desc.RenderTarget[0].IsBlendEnabled = true; desc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All; desc.RenderTarget[0].BlendOperation = BlendOperation.Add; desc.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add; desc.RenderTarget[0].DestinationBlend = BlendOption.InverseSourceAlpha; desc.RenderTarget[0].DestinationAlphaBlend = BlendOption.InverseSourceAlpha; desc.RenderTarget[0].SourceBlend = BlendOption.One; desc.RenderTarget[0].SourceAlphaBlend = BlendOption.One; BlendAlphaPremult = MyPipelineStates.CreateBlendState(desc); } { BlendStateDescription desc = new BlendStateDescription(); desc.RenderTarget[0].IsBlendEnabled = true; desc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All; desc.RenderTarget[0].BlendOperation = BlendOperation.Add; desc.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add; desc.RenderTarget[0].DestinationBlend = BlendOption.SourceColor; desc.RenderTarget[0].DestinationAlphaBlend = BlendOption.InverseSourceAlpha; desc.RenderTarget[0].SourceBlend = BlendOption.Zero; desc.RenderTarget[0].SourceAlphaBlend = BlendOption.One; BlendOutscatter = MyPipelineStates.CreateBlendState(desc); } { BlendStateDescription desc = new BlendStateDescription(); desc.IndependentBlendEnable = true; // color desc.RenderTarget[0].IsBlendEnabled = true; desc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.Red | ColorWriteMaskFlags.Green | ColorWriteMaskFlags.Blue; desc.RenderTarget[0].BlendOperation = BlendOperation.Add; desc.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add; desc.RenderTarget[0].DestinationBlend = BlendOption.InverseSourceAlpha; desc.RenderTarget[0].DestinationAlphaBlend = BlendOption.One; desc.RenderTarget[0].SourceBlend = BlendOption.One; desc.RenderTarget[0].SourceAlphaBlend = BlendOption.Zero; // metal desc.RenderTarget[2].IsBlendEnabled = true; desc.RenderTarget[2].RenderTargetWriteMask = ColorWriteMaskFlags.Red; desc.RenderTarget[2].BlendOperation = BlendOperation.Add; desc.RenderTarget[2].AlphaBlendOperation = BlendOperation.Add; desc.RenderTarget[2].DestinationBlend = BlendOption.InverseSourceAlpha; desc.RenderTarget[2].DestinationAlphaBlend = BlendOption.One; desc.RenderTarget[2].SourceBlend = BlendOption.One; desc.RenderTarget[2].SourceAlphaBlend = BlendOption.Zero; BlendDecalColor = MyPipelineStates.CreateBlendState(desc); } { BlendStateDescription desc = new BlendStateDescription(); desc.IndependentBlendEnable = true; // normal desc.RenderTarget[1].IsBlendEnabled = true; desc.RenderTarget[1].RenderTargetWriteMask = ColorWriteMaskFlags.Red | ColorWriteMaskFlags.Green | ColorWriteMaskFlags.Blue; desc.RenderTarget[1].BlendOperation = BlendOperation.Add; desc.RenderTarget[1].AlphaBlendOperation = BlendOperation.Add; desc.RenderTarget[1].DestinationBlend = BlendOption.InverseSourceAlpha; desc.RenderTarget[1].DestinationAlphaBlend = BlendOption.One; desc.RenderTarget[1].SourceBlend = BlendOption.SourceAlpha; desc.RenderTarget[1].SourceAlphaBlend = BlendOption.Zero; // gloss desc.RenderTarget[2].IsBlendEnabled = true; desc.RenderTarget[2].RenderTargetWriteMask = ColorWriteMaskFlags.Green; desc.RenderTarget[2].BlendOperation = BlendOperation.Add; desc.RenderTarget[2].AlphaBlendOperation = BlendOperation.Add; desc.RenderTarget[2].DestinationBlend = BlendOption.InverseSourceAlpha; desc.RenderTarget[2].DestinationAlphaBlend = BlendOption.One; desc.RenderTarget[2].SourceBlend = BlendOption.One; desc.RenderTarget[2].SourceAlphaBlend = BlendOption.Zero; BlendDecalNormal = MyPipelineStates.CreateBlendState(desc); } { BlendStateDescription desc = new BlendStateDescription(); desc.IndependentBlendEnable = true; // color desc.RenderTarget[0].IsBlendEnabled = true; desc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.Red | ColorWriteMaskFlags.Green | ColorWriteMaskFlags.Blue; desc.RenderTarget[0].BlendOperation = BlendOperation.Add; desc.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add; desc.RenderTarget[0].DestinationBlend = BlendOption.InverseSourceAlpha; desc.RenderTarget[0].DestinationAlphaBlend = BlendOption.One; desc.RenderTarget[0].SourceBlend = BlendOption.One; desc.RenderTarget[0].SourceAlphaBlend = BlendOption.Zero; // normal desc.RenderTarget[1].IsBlendEnabled = true; desc.RenderTarget[1].RenderTargetWriteMask = ColorWriteMaskFlags.Red | ColorWriteMaskFlags.Green | ColorWriteMaskFlags.Blue; desc.RenderTarget[1].BlendOperation = BlendOperation.Add; desc.RenderTarget[1].AlphaBlendOperation = BlendOperation.Add; desc.RenderTarget[1].DestinationBlend = BlendOption.InverseSourceAlpha; desc.RenderTarget[1].DestinationAlphaBlend = BlendOption.One; desc.RenderTarget[1].SourceBlend = BlendOption.SourceAlpha; desc.RenderTarget[1].SourceAlphaBlend = BlendOption.Zero; // metal/gloss desc.RenderTarget[2].IsBlendEnabled = true; desc.RenderTarget[2].RenderTargetWriteMask = ColorWriteMaskFlags.Red | ColorWriteMaskFlags.Green; desc.RenderTarget[2].BlendOperation = BlendOperation.Add; desc.RenderTarget[2].AlphaBlendOperation = BlendOperation.Add; desc.RenderTarget[2].DestinationBlend = BlendOption.InverseSourceAlpha; desc.RenderTarget[2].DestinationAlphaBlend = BlendOption.One; desc.RenderTarget[2].SourceBlend = BlendOption.One; desc.RenderTarget[2].SourceAlphaBlend = BlendOption.Zero; BlendDecalNormalColor = MyPipelineStates.CreateBlendState(desc); desc.RenderTarget[2].RenderTargetWriteMask = ColorWriteMaskFlags.Red | ColorWriteMaskFlags.Green | ColorWriteMaskFlags.Blue; BlendDecalNormalColorExt = MyPipelineStates.CreateBlendState(desc); } { BlendStateDescription desc = new BlendStateDescription(); desc.RenderTarget[0].IsBlendEnabled = true; desc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All; desc.RenderTarget[0].BlendOperation = BlendOperation.Add; desc.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add; desc.RenderTarget[0].DestinationBlend = BlendOption.SourceAlpha; desc.RenderTarget[0].DestinationAlphaBlend = BlendOption.SourceAlpha; desc.RenderTarget[0].SourceBlend = BlendOption.One; desc.RenderTarget[0].SourceAlphaBlend = BlendOption.One; BlendWeightedTransparencyResolve = MyPipelineStates.CreateBlendState(desc); } { BlendStateDescription desc = new BlendStateDescription(); desc.IndependentBlendEnable = true; // accumulation target desc.RenderTarget[0].IsBlendEnabled = true; desc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All; desc.RenderTarget[0].BlendOperation = BlendOperation.Add; desc.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add; desc.RenderTarget[0].DestinationBlend = BlendOption.One; desc.RenderTarget[0].DestinationAlphaBlend = BlendOption.One; desc.RenderTarget[0].SourceBlend = BlendOption.One; desc.RenderTarget[0].SourceAlphaBlend = BlendOption.One; // coverage target desc.RenderTarget[1].IsBlendEnabled = true; desc.RenderTarget[1].RenderTargetWriteMask = ColorWriteMaskFlags.All; desc.RenderTarget[1].BlendOperation = BlendOperation.Add; desc.RenderTarget[1].AlphaBlendOperation = BlendOperation.Add; desc.RenderTarget[1].DestinationBlend = BlendOption.InverseSourceColor; desc.RenderTarget[1].DestinationAlphaBlend = BlendOption.InverseSourceAlpha; desc.RenderTarget[1].SourceBlend = BlendOption.Zero; desc.RenderTarget[1].SourceAlphaBlend = BlendOption.Zero; BlendWeightedTransparency = MyPipelineStates.CreateBlendState(desc); } }
private static void UpdateSceneFrame() { var desc = new RasterizerStateDescription(); desc.FillMode = FillMode.Solid; desc.CullMode = CullMode.None; desc.IsFrontCounterClockwise = true; desc.DepthBias = 25000; desc.DepthBiasClamp = 2; desc.SlopeScaledDepthBias = 1; MyPipelineStates.Modify(m_shadowRasterizerState, desc); MyMeshes.Load(); QueryTexturesFromEntities(); MyTextures.Load(); GatherTextures(); MyComponents.UpdateCullProxies(); MyComponents.ProcessEntities(); MyComponents.SendVisible(); MyBillboardRenderer.OnFrameStart(); MyRender11.GetRenderProfiler().StartProfilingBlock("RebuildProxies"); foreach (var renderable in MyComponentFactory <MyRenderableComponent> .GetAll()) { renderable.RebuildRenderProxies(); } MyRender11.GetRenderProfiler().EndProfilingBlock(); MyRender11.GetRenderProfiler().StartProfilingBlock("UpdateProxies"); UpdateActors(); MyRender11.GetRenderProfiler().EndProfilingBlock(); MyBigMeshTable.Table.MoveToGPU(); MyRender11.GetRenderProfiler().StartProfilingBlock("Update merged groups"); MyRender11.GetRenderProfiler().StartProfilingBlock("UpdateBeforeDraw"); foreach (var r in MyComponentFactory <MyGroupRootComponent> .GetAll()) { r.UpdateBeforeDraw(); } MyRender11.GetRenderProfiler().EndProfilingBlock(); MyRender11.GetRenderProfiler().StartProfilingBlock("MoveToGPU"); foreach (var r in MyComponentFactory <MyGroupRootComponent> .GetAll()) { foreach (var val in r.m_materialGroups.Values) { // optimize: keep list+set for updating val.MoveToGPU(); } } MyRender11.GetRenderProfiler().EndProfilingBlock(); MyRender11.GetRenderProfiler().EndProfilingBlock(); MyRender11.GetRenderProfiler().StartProfilingBlock("Fill foliage streams"); MyGpuProfiler.IC_BeginBlock("Fill foliage streams"); MyGPUFoliageGenerating.GetInstance().PerFrame(); MyGPUFoliageGenerating.GetInstance().Begin(); foreach (var foliage in MyComponentFactory <MyFoliageComponent> .GetAll()) { if (foliage.m_owner.CalculateCameraDistance() < MyRender11.RenderSettings.FoliageDetails.GrassDrawDistance()) { foliage.FillStreams(); } else { foliage.InvalidateStreams(); } } MyGPUFoliageGenerating.GetInstance().End(); MyGpuProfiler.IC_EndBlock(); MyRender11.GetRenderProfiler().EndProfilingBlock(); MyCommon.MoveToNextFrame(); }
static void InitializeBlendStates() { BlendStateDescription desc = new BlendStateDescription(); desc.RenderTarget[0].IsBlendEnabled = true; desc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All; desc.RenderTarget[0].BlendOperation = BlendOperation.Add; desc.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add; desc.RenderTarget[0].DestinationBlend = BlendOption.InverseSourceAlpha; desc.RenderTarget[0].DestinationAlphaBlend = BlendOption.InverseSourceAlpha; desc.RenderTarget[0].SourceBlend = BlendOption.SourceAlpha; desc.RenderTarget[0].SourceAlphaBlend = BlendOption.SourceAlpha; BlendGui = MyPipelineStates.CreateBlendState(desc); desc.RenderTarget[0].IsBlendEnabled = true; desc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All; desc.RenderTarget[0].BlendOperation = BlendOperation.Add; desc.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add; desc.RenderTarget[0].DestinationBlend = BlendOption.One; desc.RenderTarget[0].DestinationAlphaBlend = BlendOption.One; desc.RenderTarget[0].SourceBlend = BlendOption.One; desc.RenderTarget[0].SourceAlphaBlend = BlendOption.One; BlendAdditive = MyPipelineStates.CreateBlendState(desc); desc.RenderTarget[0].IsBlendEnabled = true; desc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All; desc.RenderTarget[0].BlendOperation = BlendOperation.Add; desc.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add; desc.RenderTarget[0].DestinationBlend = BlendOption.InverseSourceAlpha; desc.RenderTarget[0].DestinationAlphaBlend = BlendOption.InverseSourceAlpha; desc.RenderTarget[0].SourceBlend = BlendOption.SourceAlpha; desc.RenderTarget[0].SourceAlphaBlend = BlendOption.One; BlendTransparent = MyPipelineStates.CreateBlendState(desc); desc.RenderTarget[0].IsBlendEnabled = true; desc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All; desc.RenderTarget[0].BlendOperation = BlendOperation.Add; desc.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add; desc.RenderTarget[0].DestinationBlend = BlendOption.InverseSourceAlpha; desc.RenderTarget[0].DestinationAlphaBlend = BlendOption.InverseSourceAlpha; desc.RenderTarget[0].SourceBlend = BlendOption.One; desc.RenderTarget[0].SourceAlphaBlend = BlendOption.One; BlendAlphaPremult = MyPipelineStates.CreateBlendState(desc); desc.RenderTarget[0].IsBlendEnabled = true; desc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All; desc.RenderTarget[0].BlendOperation = BlendOperation.Add; desc.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add; desc.RenderTarget[0].DestinationBlend = BlendOption.SourceColor; desc.RenderTarget[0].DestinationAlphaBlend = BlendOption.InverseSourceAlpha; desc.RenderTarget[0].SourceBlend = BlendOption.Zero; desc.RenderTarget[0].SourceAlphaBlend = BlendOption.One; BlendOutscatter = MyPipelineStates.CreateBlendState(desc); desc.IndependentBlendEnable = true; // color metal desc.RenderTarget[0].IsBlendEnabled = true; desc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All; desc.RenderTarget[0].BlendOperation = BlendOperation.Add; desc.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add; desc.RenderTarget[0].DestinationBlend = BlendOption.InverseBlendFactor; desc.RenderTarget[0].DestinationAlphaBlend = BlendOption.InverseBlendFactor; desc.RenderTarget[0].SourceBlend = BlendOption.BlendFactor; desc.RenderTarget[0].SourceAlphaBlend = BlendOption.BlendFactor; // normal gloss desc.RenderTarget[1].IsBlendEnabled = true; desc.RenderTarget[1].RenderTargetWriteMask = ColorWriteMaskFlags.All; desc.RenderTarget[1].BlendOperation = BlendOperation.Add; desc.RenderTarget[1].AlphaBlendOperation = BlendOperation.Add; desc.RenderTarget[1].DestinationBlend = BlendOption.Zero; desc.RenderTarget[1].DestinationAlphaBlend = BlendOption.Zero; desc.RenderTarget[1].SourceBlend = BlendOption.One; desc.RenderTarget[1].SourceAlphaBlend = BlendOption.One; // ao desc.RenderTarget[2].IsBlendEnabled = true; desc.RenderTarget[2].RenderTargetWriteMask = ColorWriteMaskFlags.Red; desc.RenderTarget[2].BlendOperation = BlendOperation.Minimum; desc.RenderTarget[2].AlphaBlendOperation = BlendOperation.Minimum; desc.RenderTarget[2].DestinationBlend = BlendOption.One; desc.RenderTarget[2].DestinationAlphaBlend = BlendOption.One; desc.RenderTarget[2].SourceBlend = BlendOption.InverseBlendFactor; desc.RenderTarget[2].SourceAlphaBlend = BlendOption.InverseBlendFactor; BlendDecal = MyPipelineStates.CreateBlendState(desc); }
static MyDepthStencilState() { { DepthStencilStateDescription desc = new DepthStencilStateDescription(); desc.DepthComparison = MyRender11.UseComplementaryDepthBuffer ? Comparison.Greater : Comparison.Less; desc.DepthWriteMask = DepthWriteMask.All; desc.IsDepthEnabled = true; desc.IsStencilEnabled = false; DepthTestWrite = MyPipelineStates.CreateDepthStencil(desc); } { DepthStencilStateDescription desc = new DepthStencilStateDescription(); desc.DepthComparison = MyRender11.UseComplementaryDepthBuffer ? Comparison.Greater : Comparison.Less; desc.DepthWriteMask = DepthWriteMask.Zero; desc.IsDepthEnabled = true; desc.IsStencilEnabled = false; DepthTest = MyPipelineStates.CreateDepthStencil(desc); } { DepthStencilStateDescription desc = new DepthStencilStateDescription(); desc.DepthComparison = MyRender11.UseComplementaryDepthBuffer ? Comparison.Greater : Comparison.Less; desc.DepthWriteMask = DepthWriteMask.Zero; desc.IsDepthEnabled = false; desc.IsStencilEnabled = false; IgnoreDepthStencil = MyPipelineStates.CreateDepthStencil(desc); } { DepthStencilStateDescription desc = new DepthStencilStateDescription(); desc.DepthComparison = MyRender11.UseComplementaryDepthBuffer ? Comparison.Greater : Comparison.Less; desc.DepthWriteMask = DepthWriteMask.All; desc.IsDepthEnabled = true; desc.IsStencilEnabled = true; desc.StencilReadMask = 0xFF; desc.StencilWriteMask = 0xFF; desc.BackFace.Comparison = Comparison.Always; desc.BackFace.DepthFailOperation = StencilOperation.Keep; desc.BackFace.FailOperation = StencilOperation.Replace; desc.BackFace.PassOperation = StencilOperation.Replace; desc.FrontFace = desc.BackFace; WriteDepthAndStencil = MyPipelineStates.CreateDepthStencil(desc); } { DepthStencilStateDescription desc = new DepthStencilStateDescription(); desc.IsDepthEnabled = false; desc.IsStencilEnabled = true; desc.StencilReadMask = 0xFF; desc.StencilWriteMask = 0x80; desc.BackFace.Comparison = Comparison.Always; desc.BackFace.DepthFailOperation = StencilOperation.Replace; desc.BackFace.FailOperation = StencilOperation.Replace; desc.BackFace.PassOperation = StencilOperation.Replace; desc.FrontFace = desc.BackFace; MarkEdgeInStencil = MyPipelineStates.CreateDepthStencil(desc); } { DepthStencilStateDescription desc = new DepthStencilStateDescription(); desc.IsDepthEnabled = true; desc.DepthComparison = Comparison.Equal; desc.DepthWriteMask = DepthWriteMask.Zero; desc.IsStencilEnabled = true; desc.StencilReadMask = 0x00; desc.StencilWriteMask = 0x40; desc.BackFace.Comparison = Comparison.Always; desc.BackFace.DepthFailOperation = StencilOperation.Keep; desc.BackFace.FailOperation = StencilOperation.Replace; desc.BackFace.PassOperation = StencilOperation.Replace; desc.FrontFace = desc.BackFace; OutlineMesh = MyPipelineStates.CreateDepthStencil(desc); } { DepthStencilStateDescription desc = new DepthStencilStateDescription(); desc.IsDepthEnabled = false; desc.IsStencilEnabled = true; desc.StencilReadMask = 0x40; desc.StencilWriteMask = 0x0; desc.BackFace.Comparison = Comparison.NotEqual; desc.BackFace.DepthFailOperation = StencilOperation.Keep; desc.BackFace.FailOperation = StencilOperation.Keep; desc.BackFace.PassOperation = StencilOperation.Keep; desc.FrontFace = desc.BackFace; TestOutlineMeshStencil = MyPipelineStates.CreateDepthStencil(desc); } { DepthStencilStateDescription desc = new DepthStencilStateDescription(); desc.IsDepthEnabled = false; desc.IsStencilEnabled = true; desc.StencilReadMask = 0x40; desc.StencilWriteMask = 0x0; desc.BackFace.Comparison = Comparison.Equal; desc.BackFace.DepthFailOperation = StencilOperation.Keep; desc.BackFace.FailOperation = StencilOperation.Keep; desc.BackFace.PassOperation = StencilOperation.Keep; desc.FrontFace = desc.BackFace; TestHighlightMeshStencil = MyPipelineStates.CreateDepthStencil(desc); } { DepthStencilStateDescription desc = new DepthStencilStateDescription(); desc.IsDepthEnabled = false; desc.IsStencilEnabled = true; desc.StencilReadMask = 0xFF; desc.StencilWriteMask = 0x0; desc.BackFace.Comparison = Comparison.NotEqual; desc.BackFace.DepthFailOperation = StencilOperation.Keep; desc.BackFace.FailOperation = StencilOperation.Keep; desc.BackFace.PassOperation = StencilOperation.Keep; desc.FrontFace = desc.BackFace; DiscardTestStencil = MyPipelineStates.CreateDepthStencil(desc); } { DepthStencilStateDescription desc = new DepthStencilStateDescription(); desc.IsDepthEnabled = false; desc.IsStencilEnabled = true; desc.StencilReadMask = 0x80; desc.StencilWriteMask = 0x00; desc.BackFace.Comparison = Comparison.Equal; desc.BackFace.DepthFailOperation = StencilOperation.Keep; desc.BackFace.FailOperation = StencilOperation.Keep; desc.BackFace.PassOperation = StencilOperation.Keep; desc.FrontFace = desc.BackFace; TestEdgeStencil = MyPipelineStates.CreateDepthStencil(desc); } { DepthStencilStateDescription desc = new DepthStencilStateDescription(); desc.DepthComparison = MyRender11.UseComplementaryDepthBuffer ? Comparison.Greater : Comparison.Less; desc.DepthWriteMask = DepthWriteMask.Zero; desc.IsDepthEnabled = true; desc.IsStencilEnabled = true; desc.StencilReadMask = 0x80; desc.StencilWriteMask = 0x00; desc.BackFace.Comparison = Comparison.Equal; desc.BackFace.DepthFailOperation = StencilOperation.Keep; desc.BackFace.FailOperation = StencilOperation.Keep; desc.BackFace.PassOperation = StencilOperation.Keep; desc.FrontFace = desc.BackFace; TestDepthAndEdgeStencil = MyPipelineStates.CreateDepthStencil(desc); } MarkIfInsideCascade = new DepthStencilId[MyRender11.Settings.ShadowCascadeCount]; { DepthStencilStateDescription desc = new DepthStencilStateDescription(); desc.IsDepthEnabled = true; desc.DepthComparison = MyRender11.UseComplementaryDepthBuffer ? Comparison.Less : Comparison.Greater; desc.DepthWriteMask = DepthWriteMask.Zero; desc.IsStencilEnabled = true; desc.StencilReadMask = 0x00; desc.BackFace.Comparison = Comparison.Always; desc.BackFace.DepthFailOperation = StencilOperation.Keep; desc.BackFace.FailOperation = StencilOperation.Keep; desc.BackFace.PassOperation = StencilOperation.Replace; desc.FrontFace = desc.BackFace; for (int cascadeIndex = 0; cascadeIndex < MarkIfInsideCascade.Length; ++cascadeIndex) { desc.StencilWriteMask = (byte)(0x01 << cascadeIndex); MarkIfInsideCascade[cascadeIndex] = MyPipelineStates.CreateDepthStencil(desc); } } }
static void InitializeBlendStates() { { BlendStateDescription desc = new BlendStateDescription(); desc.RenderTarget[0].IsBlendEnabled = true; desc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All; desc.RenderTarget[0].BlendOperation = BlendOperation.Add; desc.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add; desc.RenderTarget[0].DestinationBlend = BlendOption.InverseSourceAlpha; desc.RenderTarget[0].DestinationAlphaBlend = BlendOption.InverseSourceAlpha; desc.RenderTarget[0].SourceBlend = BlendOption.SourceAlpha; desc.RenderTarget[0].SourceAlphaBlend = BlendOption.SourceAlpha; BlendGui = MyPipelineStates.CreateBlendState(desc); } { BlendStateDescription desc = new BlendStateDescription(); desc.RenderTarget[0].IsBlendEnabled = true; desc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All; desc.RenderTarget[0].BlendOperation = BlendOperation.Add; desc.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add; desc.RenderTarget[0].DestinationBlend = BlendOption.One; desc.RenderTarget[0].DestinationAlphaBlend = BlendOption.One; desc.RenderTarget[0].SourceBlend = BlendOption.One; desc.RenderTarget[0].SourceAlphaBlend = BlendOption.One; BlendAdditive = MyPipelineStates.CreateBlendState(desc); } { BlendStateDescription desc = new BlendStateDescription(); desc.RenderTarget[0].IsBlendEnabled = true; desc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All; desc.RenderTarget[0].BlendOperation = BlendOperation.Add; desc.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add; desc.RenderTarget[0].DestinationBlend = BlendOption.SourceAlpha; desc.RenderTarget[0].DestinationAlphaBlend = BlendOption.One; desc.RenderTarget[0].SourceBlend = BlendOption.One; desc.RenderTarget[0].SourceAlphaBlend = BlendOption.One; BlendAtmosphere = MyPipelineStates.CreateBlendState(desc); } { BlendStateDescription desc = new BlendStateDescription(); desc.RenderTarget[0].IsBlendEnabled = true; desc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All; desc.RenderTarget[0].BlendOperation = BlendOperation.Add; desc.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add; desc.RenderTarget[0].DestinationBlend = BlendOption.InverseSourceAlpha; desc.RenderTarget[0].DestinationAlphaBlend = BlendOption.InverseSourceAlpha; desc.RenderTarget[0].SourceBlend = BlendOption.SourceAlpha; desc.RenderTarget[0].SourceAlphaBlend = BlendOption.SourceAlpha; BlendTransparent = MyPipelineStates.CreateBlendState(desc); } { BlendStateDescription desc = new BlendStateDescription(); desc.RenderTarget[0].IsBlendEnabled = true; desc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All; desc.RenderTarget[0].BlendOperation = BlendOperation.Add; desc.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add; desc.RenderTarget[0].DestinationBlend = BlendOption.InverseSourceAlpha; desc.RenderTarget[0].DestinationAlphaBlend = BlendOption.InverseSourceAlpha; desc.RenderTarget[0].SourceBlend = BlendOption.One; desc.RenderTarget[0].SourceAlphaBlend = BlendOption.One; BlendAlphaPremult = MyPipelineStates.CreateBlendState(desc); } { BlendStateDescription desc = new BlendStateDescription(); desc.RenderTarget[0].IsBlendEnabled = true; desc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All; desc.RenderTarget[0].BlendOperation = BlendOperation.Add; desc.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add; desc.RenderTarget[0].DestinationBlend = BlendOption.SourceColor; desc.RenderTarget[0].DestinationAlphaBlend = BlendOption.InverseSourceAlpha; desc.RenderTarget[0].SourceBlend = BlendOption.Zero; desc.RenderTarget[0].SourceAlphaBlend = BlendOption.One; BlendOutscatter = MyPipelineStates.CreateBlendState(desc); } { BlendStateDescription desc = new BlendStateDescription(); desc.RenderTarget[0].IsBlendEnabled = true; desc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All; desc.RenderTarget[0].BlendOperation = BlendOperation.Add; desc.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add; desc.RenderTarget[0].DestinationBlend = BlendOption.SourceAlpha; desc.RenderTarget[0].DestinationAlphaBlend = BlendOption.SourceAlpha; desc.RenderTarget[0].SourceBlend = BlendOption.InverseSourceAlpha; desc.RenderTarget[0].SourceAlphaBlend = BlendOption.InverseSourceAlpha; BlendInvTransparent = MyPipelineStates.CreateBlendState(desc); } { BlendStateDescription desc = new BlendStateDescription(); // color desc.RenderTarget[0].IsBlendEnabled = true; desc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All; desc.RenderTarget[0].BlendOperation = BlendOperation.Add; desc.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add; desc.RenderTarget[0].DestinationBlend = BlendOption.InverseSecondarySourceAlpha; desc.RenderTarget[0].DestinationAlphaBlend = BlendOption.Zero; desc.RenderTarget[0].SourceBlend = BlendOption.SecondarySourceAlpha; desc.RenderTarget[0].SourceAlphaBlend = BlendOption.One; BlendDecalColor = MyPipelineStates.CreateBlendState(desc); } { BlendStateDescription desc = new BlendStateDescription(); desc.IndependentBlendEnable = true; // normal desc.RenderTarget[1].IsBlendEnabled = true; desc.RenderTarget[1].RenderTargetWriteMask = ColorWriteMaskFlags.All; desc.RenderTarget[1].BlendOperation = BlendOperation.Add; desc.RenderTarget[1].AlphaBlendOperation = BlendOperation.Add; desc.RenderTarget[1].DestinationBlend = BlendOption.Zero; desc.RenderTarget[1].DestinationAlphaBlend = BlendOption.Zero; desc.RenderTarget[1].SourceBlend = BlendOption.One; desc.RenderTarget[1].SourceAlphaBlend = BlendOption.One; // ao desc.RenderTarget[2].IsBlendEnabled = true; desc.RenderTarget[2].RenderTargetWriteMask = ColorWriteMaskFlags.Red; desc.RenderTarget[2].BlendOperation = BlendOperation.Minimum; desc.RenderTarget[2].AlphaBlendOperation = BlendOperation.Minimum; desc.RenderTarget[2].DestinationBlend = BlendOption.One; desc.RenderTarget[2].DestinationAlphaBlend = BlendOption.One; desc.RenderTarget[2].SourceBlend = BlendOption.InverseBlendFactor; desc.RenderTarget[2].SourceAlphaBlend = BlendOption.InverseBlendFactor; BlendDecalNormal = MyPipelineStates.CreateBlendState(desc); } { BlendStateDescription desc = new BlendStateDescription(); desc.IndependentBlendEnable = true; // color // NOTE: We skip metal as we can't use dual-source alpha when using multiple targets desc.RenderTarget[0].IsBlendEnabled = true; desc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.Red | ColorWriteMaskFlags.Green | ColorWriteMaskFlags.Blue; desc.RenderTarget[0].BlendOperation = BlendOperation.Add; desc.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add; desc.RenderTarget[0].DestinationBlend = BlendOption.InverseSourceAlpha; desc.RenderTarget[0].DestinationAlphaBlend = BlendOption.One; desc.RenderTarget[0].SourceBlend = BlendOption.SourceAlpha; desc.RenderTarget[0].SourceAlphaBlend = BlendOption.Zero; // normal desc.RenderTarget[1].IsBlendEnabled = true; desc.RenderTarget[1].RenderTargetWriteMask = ColorWriteMaskFlags.All; desc.RenderTarget[1].BlendOperation = BlendOperation.Add; desc.RenderTarget[1].AlphaBlendOperation = BlendOperation.Add; desc.RenderTarget[1].DestinationBlend = BlendOption.Zero; desc.RenderTarget[1].DestinationAlphaBlend = BlendOption.Zero; desc.RenderTarget[1].SourceBlend = BlendOption.One; desc.RenderTarget[1].SourceAlphaBlend = BlendOption.One; // ao desc.RenderTarget[2].IsBlendEnabled = true; desc.RenderTarget[2].RenderTargetWriteMask = ColorWriteMaskFlags.Red; desc.RenderTarget[2].BlendOperation = BlendOperation.Minimum; desc.RenderTarget[2].AlphaBlendOperation = BlendOperation.Minimum; desc.RenderTarget[2].DestinationBlend = BlendOption.One; desc.RenderTarget[2].DestinationAlphaBlend = BlendOption.One; desc.RenderTarget[2].SourceBlend = BlendOption.InverseBlendFactor; desc.RenderTarget[2].SourceAlphaBlend = BlendOption.InverseBlendFactor; BlendDecalNormalColor = MyPipelineStates.CreateBlendState(desc); } { BlendStateDescription desc = new BlendStateDescription(); desc.IndependentBlendEnable = true; // accumulation target desc.RenderTarget[0].IsBlendEnabled = true; desc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All; desc.RenderTarget[0].BlendOperation = BlendOperation.Add; desc.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add; desc.RenderTarget[0].DestinationBlend = BlendOption.One; desc.RenderTarget[0].DestinationAlphaBlend = BlendOption.One; desc.RenderTarget[0].SourceBlend = BlendOption.One; desc.RenderTarget[0].SourceAlphaBlend = BlendOption.One; // coverage target desc.RenderTarget[1].IsBlendEnabled = true; desc.RenderTarget[1].RenderTargetWriteMask = ColorWriteMaskFlags.All; desc.RenderTarget[1].BlendOperation = BlendOperation.Add; desc.RenderTarget[1].AlphaBlendOperation = BlendOperation.Add; desc.RenderTarget[1].DestinationBlend = BlendOption.InverseSourceAlpha; desc.RenderTarget[1].DestinationAlphaBlend = BlendOption.InverseSourceAlpha; desc.RenderTarget[1].SourceBlend = BlendOption.Zero; desc.RenderTarget[1].SourceAlphaBlend = BlendOption.Zero; BlendWeightedTransparency = MyPipelineStates.CreateBlendState(desc); } }
internal static void Init() { // Bits in stencil buffer: 76543210 // bits 3-0 used in CSM // bit 4 used for stereo rendering mask // bit 6 used for outlines { DepthStencilStateDescription desc = new DepthStencilStateDescription(); desc.DepthComparison = MyRender11.UseComplementaryDepthBuffer ? Comparison.Greater : Comparison.Less; desc.DepthWriteMask = DepthWriteMask.All; desc.IsDepthEnabled = true; desc.IsStencilEnabled = false; DepthTestWrite = MyPipelineStates.CreateDepthStencil(desc); } { DepthStencilStateDescription desc = new DepthStencilStateDescription(); desc.DepthComparison = MyRender11.UseComplementaryDepthBuffer ? Comparison.Greater : Comparison.Less; desc.DepthWriteMask = DepthWriteMask.Zero; desc.IsDepthEnabled = true; desc.IsStencilEnabled = false; DepthTest = MyPipelineStates.CreateDepthStencil(desc); } { DepthStencilStateDescription desc = new DepthStencilStateDescription(); desc.DepthComparison = MyRender11.UseComplementaryDepthBuffer ? Comparison.Greater : Comparison.Less; desc.DepthWriteMask = DepthWriteMask.Zero; desc.IsDepthEnabled = false; desc.IsStencilEnabled = false; IgnoreDepthStencil = MyPipelineStates.CreateDepthStencil(desc); } { DepthStencilStateDescription desc = new DepthStencilStateDescription(); desc.DepthComparison = MyRender11.UseComplementaryDepthBuffer ? Comparison.Greater : Comparison.Less; desc.DepthWriteMask = DepthWriteMask.All; desc.IsDepthEnabled = true; desc.IsStencilEnabled = true; desc.StencilReadMask = 0xFF; desc.StencilWriteMask = 0xFF; desc.BackFace.Comparison = Comparison.Always; desc.BackFace.DepthFailOperation = StencilOperation.Keep; desc.BackFace.FailOperation = StencilOperation.Replace; desc.BackFace.PassOperation = StencilOperation.Replace; desc.FrontFace = desc.BackFace; WriteDepthAndStencil = MyPipelineStates.CreateDepthStencil(desc); } { DepthStencilStateDescription desc = new DepthStencilStateDescription(); desc.IsDepthEnabled = false; desc.IsStencilEnabled = true; desc.StencilReadMask = 0xFF; desc.StencilWriteMask = 0x80; desc.BackFace.Comparison = Comparison.Always; desc.BackFace.DepthFailOperation = StencilOperation.Replace; desc.BackFace.FailOperation = StencilOperation.Replace; desc.BackFace.PassOperation = StencilOperation.Replace; desc.FrontFace = desc.BackFace; MarkEdgeInStencil = MyPipelineStates.CreateDepthStencil(desc); } { DepthStencilStateDescription desc = new DepthStencilStateDescription(); desc.IsDepthEnabled = true; desc.DepthComparison = Comparison.Equal; desc.DepthWriteMask = DepthWriteMask.Zero; desc.IsStencilEnabled = true; desc.StencilReadMask = 0x00; desc.StencilWriteMask = 0x40; desc.BackFace.Comparison = Comparison.Always; desc.BackFace.DepthFailOperation = StencilOperation.Keep; desc.BackFace.FailOperation = StencilOperation.Replace; desc.BackFace.PassOperation = StencilOperation.Replace; desc.FrontFace = desc.BackFace; OutlineMesh = MyPipelineStates.CreateDepthStencil(desc); } { DepthStencilStateDescription desc = new DepthStencilStateDescription(); desc.IsDepthEnabled = false; desc.IsStencilEnabled = true; desc.StencilReadMask = 0x40; desc.StencilWriteMask = 0x0; desc.BackFace.Comparison = Comparison.NotEqual; desc.BackFace.DepthFailOperation = StencilOperation.Keep; desc.BackFace.FailOperation = StencilOperation.Keep; desc.BackFace.PassOperation = StencilOperation.Keep; desc.FrontFace = desc.BackFace; TestOutlineMeshStencil = MyPipelineStates.CreateDepthStencil(desc); } { DepthStencilStateDescription desc = new DepthStencilStateDescription(); desc.IsDepthEnabled = false; desc.IsStencilEnabled = true; desc.StencilReadMask = 0x40; desc.StencilWriteMask = 0x0; desc.BackFace.Comparison = Comparison.Equal; desc.BackFace.DepthFailOperation = StencilOperation.Keep; desc.BackFace.FailOperation = StencilOperation.Keep; desc.BackFace.PassOperation = StencilOperation.Keep; desc.FrontFace = desc.BackFace; TestHighlightMeshStencil = MyPipelineStates.CreateDepthStencil(desc); } { DepthStencilStateDescription desc = new DepthStencilStateDescription(); desc.IsDepthEnabled = false; desc.IsStencilEnabled = true; desc.StencilReadMask = 0x80; desc.StencilWriteMask = 0x00; desc.BackFace.Comparison = Comparison.Equal; desc.BackFace.DepthFailOperation = StencilOperation.Keep; desc.BackFace.FailOperation = StencilOperation.Keep; desc.BackFace.PassOperation = StencilOperation.Keep; desc.FrontFace = desc.BackFace; TestEdgeStencil = MyPipelineStates.CreateDepthStencil(desc); } { DepthStencilStateDescription desc = new DepthStencilStateDescription(); desc.DepthComparison = MyRender11.UseComplementaryDepthBuffer ? Comparison.Greater : Comparison.Less; desc.DepthWriteMask = DepthWriteMask.Zero; desc.IsDepthEnabled = true; desc.IsStencilEnabled = true; desc.StencilReadMask = 0x80; desc.StencilWriteMask = 0x00; desc.BackFace.Comparison = Comparison.Equal; desc.BackFace.DepthFailOperation = StencilOperation.Keep; desc.BackFace.FailOperation = StencilOperation.Keep; desc.BackFace.PassOperation = StencilOperation.Keep; desc.FrontFace = desc.BackFace; TestDepthAndEdgeStencil = MyPipelineStates.CreateDepthStencil(desc); } MarkIfInsideCascade = new DepthStencilId[8]; { DepthStencilStateDescription desc = new DepthStencilStateDescription(); desc.IsDepthEnabled = true; desc.DepthComparison = MyRender11.UseComplementaryDepthBuffer ? Comparison.Less : Comparison.Greater; desc.DepthWriteMask = DepthWriteMask.Zero; for (int cascadeIndex = 0; cascadeIndex < MarkIfInsideCascade.Length; ++cascadeIndex) { desc.IsStencilEnabled = true; desc.StencilReadMask = 0xF; desc.StencilWriteMask = 0xF; desc.BackFace.Comparison = cascadeIndex == 0 ? Comparison.Always : Comparison.Greater; desc.BackFace.DepthFailOperation = StencilOperation.Keep; desc.BackFace.FailOperation = StencilOperation.Keep; desc.BackFace.PassOperation = StencilOperation.Replace; desc.FrontFace = desc.BackFace; MarkIfInsideCascade[cascadeIndex] = MyPipelineStates.CreateDepthStencil(desc); } } { DepthStencilStateDescription desc = new DepthStencilStateDescription(); desc.DepthComparison = MyRender11.UseComplementaryDepthBuffer ? Comparison.Greater : Comparison.Less; desc.DepthWriteMask = DepthWriteMask.All; desc.IsDepthEnabled = true; desc.IsStencilEnabled = true; desc.StencilWriteMask = GetStereoMask(); desc.StencilReadMask = GetStereoMask(); desc.BackFace.Comparison = Comparison.GreaterEqual; desc.BackFace.DepthFailOperation = StencilOperation.Keep; desc.BackFace.FailOperation = StencilOperation.Keep; desc.BackFace.PassOperation = StencilOperation.Replace; desc.FrontFace = desc.BackFace; StereoDefaultDepthState = MyPipelineStates.CreateDepthStencil(desc); } { DepthStencilStateDescription desc = new DepthStencilStateDescription(); desc.DepthComparison = MyRender11.UseComplementaryDepthBuffer ? Comparison.Greater : Comparison.Less; desc.DepthWriteMask = DepthWriteMask.Zero; desc.IsDepthEnabled = false; desc.IsStencilEnabled = true; desc.StencilWriteMask = GetStereoMask(); desc.StencilReadMask = GetStereoMask(); desc.BackFace.Comparison = Comparison.Always; desc.BackFace.DepthFailOperation = StencilOperation.Replace; desc.BackFace.FailOperation = StencilOperation.Replace; desc.BackFace.PassOperation = StencilOperation.Replace; desc.FrontFace = desc.BackFace; StereoStereoStencilMask = MyPipelineStates.CreateDepthStencil(desc); } { DepthStencilStateDescription desc = new DepthStencilStateDescription(); desc.DepthComparison = MyRender11.UseComplementaryDepthBuffer ? Comparison.Greater : Comparison.Less; desc.DepthWriteMask = DepthWriteMask.All; desc.IsDepthEnabled = true; desc.IsStencilEnabled = true; desc.StencilWriteMask = GetStereoMask(); desc.StencilReadMask = GetStereoMask(); desc.BackFace.Comparison = Comparison.GreaterEqual; desc.BackFace.DepthFailOperation = StencilOperation.Keep; desc.BackFace.FailOperation = StencilOperation.Keep; desc.BackFace.PassOperation = StencilOperation.Replace; desc.FrontFace = desc.BackFace; StereoDepthTestWrite = MyPipelineStates.CreateDepthStencil(desc); } { DepthStencilStateDescription desc = new DepthStencilStateDescription(); desc.DepthComparison = MyRender11.UseComplementaryDepthBuffer ? Comparison.Greater : Comparison.Less; desc.DepthWriteMask = DepthWriteMask.Zero; desc.IsDepthEnabled = false; desc.IsStencilEnabled = true; desc.StencilWriteMask = GetStereoMask(); desc.StencilReadMask = GetStereoMask(); desc.BackFace.Comparison = Comparison.GreaterEqual; desc.BackFace.DepthFailOperation = StencilOperation.Keep; desc.BackFace.FailOperation = StencilOperation.Keep; desc.BackFace.PassOperation = StencilOperation.Replace; desc.FrontFace = desc.BackFace; StereoIgnoreDepthStencil = MyPipelineStates.CreateDepthStencil(desc); } }