protected override void InitializeService() { // Listen to changes in light count sceneManager.LightCountSet += new SceneManager.LightCountSetDelegate(SetLightCount); ShadowBlendState = BlendState.Default; ShadowFaceCullState = FaceCullState.Default; ShadowDepthState = DepthState.Default; quadRenderer = new QuadRenderer(renderer); visualizeShadowMap = renderer.Programs["VisualizeShadowMap"]; if (example.Renderer.Configuration.hardwareShadowPCF) { materialManager.MakeMaterial("Shadow", "ShadowCaster2"); } else { materialManager.MakeMaterial("Shadow", "ShadowCaster"); } { var m = materialManager.MakeMaterial("VisualizeShadowMap"); m.DepthState = DepthState.Disabled; m.FaceCullState = FaceCullState.Disabled; } renderer.Resize += new EventHandler <EventArgs>(renderer_Resize); }
public static void Set(DepthState depthState) { if (Current != depthState) { Graphics.State.OnStateChanging?.Invoke(); Graphics.SetDepth(depthState); Current = depthState; Graphics.State.OnStateChanged?.Invoke(); } }
internal override void SetDepth(DepthState depthState) { if (depthState.Enabled) { GL.Enable(EnableCap.DepthTest); } else { GL.Disable(EnableCap.DepthTest); } GL.DepthFunc(depthState.DepthFunction.ToOpenGL()); }
internal override void SetDepth(DepthState depthState) { if (depthState.Enabled) { GL.enable(DEPTH_TEST); } else { GL.disable(DEPTH_TEST); } GL.depthFunc(depthState.DepthFunction.ToWebGL2()); }
public void Begin() { // Save old state _oldDepthState = _device.DepthState; _oldFaceCullingEnabled = _device.FaceCullingEnabled; _oldBlendState = _device.BlendState; // Set new state _device.DepthState = DepthState.None; _device.FaceCullingEnabled = false; _device.BlendState = BlendState.AlphaBlend; _batch.Begin(); }
private void OnApplyButtonClicked() { ConfigureDepth(_enableDepthToggle.isOn); if (_depthMapToggle.isOn) { _depthState = DepthState.DepthMap; _debugVisualizer.SetActive(true); } else { _debugVisualizer.SetActive(false); } _planeDiscoveryGuide.EnablePlaneDiscoveryGuide(true); }
private void _OnApplyButtonClicked() { _ConfigureDepth(m_EnableDepthToggle.isOn); if (m_DepthMapToggle.isOn) { m_DepthState = DepthState.DepthMap; m_DebugVisualizer.SetActive(true); } else { m_DebugVisualizer.SetActive(false); } m_MenuWindow.SetActive(false); m_PlaneDiscoveryGuide.EnablePlaneDiscoveryGuide(true); }
public bool Compatible(DepthState other) { if (Enabled != other.Enabled) { return(false); } if (EdramBase != other.EdramBase) { return(false); } if (Format != other.Format) { return(false); } return(true); }
public void Begin(Matrix3x2?transform, TextureFiltering textureFiltering) { // Save old state _oldDepthState = _device.DepthState; _oldFaceCullingEnabled = _device.FaceCullingEnabled; _oldBlendState = _device.BlendState; _oldScissorEnabled = _device.ScissorTestEnabled; // Set new state _device.DepthState = DepthState.None; _device.FaceCullingEnabled = false; _device.BlendState = BlendState.AlphaBlend; _device.ScissorTestEnabled = true; _batch.Begin(); _beginCalled = true; _transform = transform; _filtering = textureFiltering; }
/// <summary> /// Show Depth Card window when first asset placed and device supports depth. /// </summary> public void ConfigureDepthBeforePlacingFirstAsset() { if (!_depthConfigured) { // Session might not be initialized when GameOject is inializing. // Hence, it would be better NOT to call `IsDepthModeSupported` in start(). if (Session.IsDepthModeSupported(DepthMode.Automatic)) { _depthState = DepthState.DepthDisabled; _menuText.text = "Your device supports depth."; _depthCardWindow.SetActive(true); _planeDiscoveryGuide.EnablePlaneDiscoveryGuide(false); } else { _depthState = DepthState.DepthNotAvailable; _menuText.text = "Your device doesn't support depth."; } _depthConfigured = true; } }
public bool Equals(GLCmdBufferPipelineItem other) { // if (!Pipeline.Equals (other.Pipeline)) // return false; // // if (!Pass.Equals (other.Pass)) // return false; if (!Flags.Equals(other.Flags)) { return(false); } if (!DepthState.Equals(other.DepthState)) { return(false); } if (!StencilState.Equals(other.StencilState)) { return(false); } // if (!Rasterization.Equals (other.Rasterization)) // return false; if (!ColorBlendEnums.Equals(other.ColorBlendEnums)) { return(false); } if (!ClearValues.Equals(other.ClearValues)) { return(false); } return(true); }
public void Render() { Framebuffer.Execute(); Viewport.Execute(); BlendState.Execute(); FaceCullState.Execute(); MaskState.Execute(); DepthState.Execute(); StencilState.Execute(); Clear.Execute(); camera.UpdateFrame(); camera.UpdateViewport(Viewport.Viewport); foreach (var item in renderItems) { #if false if (item.Model.Frame != frame) { camera.UpdateModelFrame(frame); } #endif //item.Batch.Mesh.ApplyAttributes( } }
/// <summary> /// Callback event when the depth menu button is clicked. /// </summary> public void OnMenuButtonClicked() { if (!_depthConfigured) { // Session might not be initialized when GameOject is inializing. // Hence, it would be better NOT to call `IsDepthModeSupported` in start(). if (Session.IsDepthModeSupported(DepthMode.Automatic)) { _depthState = DepthState.DepthDisabled; _menuText.text = "Your device supports depth."; } else { ConfigureDepth(false); _depthState = DepthState.DepthNotAvailable; _menuText.text = "Your device doesn't support depth."; } _depthConfigured = true; ApplyDepthState(); } _planeDiscoveryGuide.EnablePlaneDiscoveryGuide(false); }
private void _OnMenuButtonClicked() { if (!m_DepthConfigured) { // Session might not be initialized when GameOject is inializing. // Hence, it would be better NOT to call `IsDepthModeSupported` in start(). if (Session.IsDepthModeSupported(DepthMode.Automatic)) { m_DepthState = DepthState.DepthDisabled; m_MenuText.text = "Your device supports depth."; } else { _ConfigureDepth(false); m_DepthState = DepthState.DepthNotAvailable; m_MenuText.text = "Your device doesn't support depth."; } _ResetToggle(); } m_MenuWindow.SetActive(true); m_PlaneDiscoveryGuide.EnablePlaneDiscoveryGuide(false); }
public void SetDepthState(DepthState state) { depthState = state; depthStateDirty = true; }
public static void Initialize(GxContext context) { gGraphics = System.Drawing.Graphics.FromImage(Bitmap); gSampler = new Sampler(context) { AddressU = SharpDX.Direct3D11.TextureAddressMode.Wrap, AddressV = SharpDX.Direct3D11.TextureAddressMode.Wrap, AddressW = SharpDX.Direct3D11.TextureAddressMode.Clamp, Filter = Filter.MinMagMipLinear }; gSampler2D = new Sampler(context) { AddressU = SharpDX.Direct3D11.TextureAddressMode.Wrap, AddressV = SharpDX.Direct3D11.TextureAddressMode.Wrap, AddressW = SharpDX.Direct3D11.TextureAddressMode.Clamp, Filter = Filter.MinMagMipPoint }; gBlendState = new Graphics.BlendState(context) { BlendEnabled = true, SourceBlend = BlendOption.SourceAlpha, DestinationBlend = BlendOption.InverseSourceAlpha, SourceAlphaBlend = BlendOption.SourceAlpha, DestinationAlphaBlend = BlendOption.InverseSourceAlpha }; gRasterState = new RasterState(context) { CullEnabled = false }; gDepthState = new DepthState(context) { DepthEnabled = true, DepthWriteEnabled = false }; gNoDepthState = new DepthState(context) { DepthEnabled = false, DepthWriteEnabled = false }; gVertexBuffer = new VertexBuffer(context); gMesh = new Mesh(context) { Stride = IO.SizeCache <WorldTextVertex> .Size }; gMesh.DepthState.Dispose(); gMesh.BlendState.Dispose(); gMesh.IndexBuffer.Dispose(); gMesh.VertexBuffer.Dispose(); gMesh.RasterizerState = gRasterState; gMesh.BlendState = gBlendState; gMesh.VertexBuffer = gVertexBuffer; gMesh.DepthState = gDepthState; gMesh.AddElement("POSITION", 0, 3); gMesh.AddElement("TEXCOORD", 0, 2); gWorldTextShader = new ShaderProgram(context); gWorldTextShader.SetVertexShader(Resources.Shaders.WorldTextVertex); gWorldTextShader.SetPixelShader(Resources.Shaders.WorldTextPixel); gWorldTextShader2D = new ShaderProgram(context); gWorldTextShader2D.SetVertexShader(Resources.Shaders.WorldTextVertexOrtho); gWorldTextShader2D.SetPixelShader(Resources.Shaders.WorldTextPixel); gMesh.Program = gWorldTextShader; gMesh.InitLayout(gWorldTextShader); gPerDrawCallBuffer = new ConstantBuffer(context); gPerDrawCallBuffer.UpdateData(new PerDrawCallBuffer { matTransform = Matrix.Identity }); }
protected override void InitializeService() { models = new HashSet<Model>(); polygonIds = new HashSet<uint>(); readonlyModels = new ReadOnlyHashSet<Model>(models); //selectionMesh = new GeometryMesh(); silhouetteHidden = new Material("silhouetteHidden", renderer.Programs["FatTriangle"], renderer.MaterialUB); silhouetteVisible = new Material("silhouetteVisible", renderer.Programs["FatTriangle"], renderer.MaterialUB); edgeLinesSelected = new Material("edgeLinesSelected", renderer.Programs["WideLineUniformColor"], renderer.MaterialUB); edgeLinesHidden = new Material("edgeLinesHidden", renderer.Programs["WideLineUniformColor"], renderer.MaterialUB); cornerPoints = new Material("cornerPoints", renderer.Programs["ColorFill"], renderer.MaterialUB); polygonCentroids = new Material("polygonCentroids", renderer.Programs["ColorFill"], renderer.MaterialUB); stencilMaskWrite = new Material("stencilMaskWrite", renderer.Programs["ColorFill"], renderer.MaterialUB); if(RenderStack.Graphics.Configuration.canUseGeometryShaders == false) { silhouetteHidden.MeshMode = MeshMode.EdgeLines; silhouetteVisible.MeshMode = MeshMode.EdgeLines; } var greaterDepthState = new DepthState(); greaterDepthState.Enabled = true; greaterDepthState.Function = DepthFunction.Greater; float lineWidth = 2.0f; edgeLinesSelected.MeshMode = MeshMode.EdgeLines; edgeLinesSelected.Floats("line_width").Set(lineWidth, lineWidth * lineWidth * 0.25f); edgeLinesSelected.Floats("line_color").Set(0.0f, 0.0f, 1.0f, 1.0f); edgeLinesSelected.Sync(); lineWidth = 1.0f; edgeLinesHidden.MeshMode = MeshMode.EdgeLines; edgeLinesHidden.DepthState = greaterDepthState; edgeLinesHidden.MaskState = new MaskState(); edgeLinesHidden.MaskState.Red = true; edgeLinesHidden.MaskState.Green = true; edgeLinesHidden.MaskState.Blue = true; edgeLinesHidden.MaskState.Alpha = true; edgeLinesHidden.MaskState.Depth = false; edgeLinesHidden.Floats("line_width").Set(lineWidth, lineWidth * lineWidth * 0.25f); edgeLinesHidden.Floats("line_color").Set(0.0f, 0.0f, 0.5f, 1.0f); edgeLinesHidden.Sync(); lineWidth = 6.0f; silhouetteHidden.DepthState = greaterDepthState; silhouetteHidden.MaskState = new MaskState(); silhouetteHidden.MaskState.Depth = false; silhouetteHidden.Floats("line_width").Set(lineWidth, lineWidth * lineWidth * 0.25f); silhouetteHidden.Floats("line_color").Set(0.4f, 0.6f, 0.8f, 1.0f); // StencilState to fail if stencil != 0, no writes silhouetteHidden.StencilState = new StencilState(); silhouetteHidden.StencilState.Enabled = true; silhouetteHidden.StencilState.Front.Function = StencilFunction.Equal; silhouetteHidden.StencilState.Front.Reference = 0; silhouetteHidden.StencilState.Front.TestMask = 0xffff; silhouetteHidden.StencilState.Front.WriteMask = 0xffff; silhouetteHidden.StencilState.Front.StencilFailOp = StencilOp.Keep; silhouetteHidden.StencilState.Front.ZFailOp = StencilOp.Keep; silhouetteHidden.StencilState.Front.ZPassOp = StencilOp.Keep; silhouetteHidden.Sync(); silhouetteVisible.MaskState = silhouetteHidden.MaskState; silhouetteVisible.StencilState = silhouetteHidden.StencilState; lineWidth = 6.0f; silhouetteVisible.Floats("line_width").Set(lineWidth, lineWidth * lineWidth * 0.25f); silhouetteVisible.Floats("line_color").Set(0.9f, 0.9f, 1.0f, 1.0f); silhouetteVisible.Sync(); cornerPoints.Floats("point_color").Set(1.0f, 0.0f, 0.0f, 1.0f); cornerPoints.Sync(); polygonCentroids.Floats("point_color").Set(0.5f, 0.0f, 1.0f, 1.0f); polygonCentroids.Sync(); // No depth test; Do not write to color or depth; Only write to stencil stencilMaskWrite.DepthState = DepthState.Disabled; stencilMaskWrite.MaskState = new MaskState(); stencilMaskWrite.MaskState.Red = false; stencilMaskWrite.MaskState.Green = false; stencilMaskWrite.MaskState.Blue = false; stencilMaskWrite.MaskState.Alpha = false; stencilMaskWrite.MaskState.Depth = false; // StencilState to write 1 to stencil, always stencilMaskWrite.StencilState = new StencilState(); stencilMaskWrite.StencilState.Enabled = true; stencilMaskWrite.StencilState.Front.StencilFailOp = StencilOp.Replace; stencilMaskWrite.StencilState.Front.ZFailOp = StencilOp.Replace; stencilMaskWrite.StencilState.Front.ZPassOp = StencilOp.Replace; stencilMaskWrite.StencilState.Front.Function = StencilFunction.Always; stencilMaskWrite.StencilState.Front.Reference = 1; stencilMaskWrite.StencilState.Front.TestMask = 0xffff; stencilMaskWrite.StencilState.Front.WriteMask = 0xffff; sphereMesh = new GeometryMesh( new RenderStack.Geometry.Shapes.Sphere(1.0f, 20, 12), NormalStyle.PointNormals ); }
public bool Equals(DepthState depth) { return(this == depth); }
public static void SetDefault(DepthState depthState) => Default = depthState;
public static void Initialize(GxContext context) { gDepthWriteState = new DepthState(context) { DepthEnabled = true, DepthWriteEnabled = true }; gDepthNoWriteState = new DepthState(context) { DepthEnabled = true, DepthWriteEnabled = false }; gMesh = new Mesh(context) { Stride = IO.SizeCache <M2Vertex> .Size, DepthState = gDepthNoWriteState }; gMesh.BlendState.Dispose(); gMesh.IndexBuffer.Dispose(); gMesh.VertexBuffer.Dispose(); gMesh.BlendState = null; gMesh.IndexBuffer = null; gMesh.VertexBuffer = null; gMesh.AddElement("POSITION", 0, 3); gMesh.AddElement("BLENDWEIGHT", 0, 4, DataType.Byte, true); gMesh.AddElement("BLENDINDEX", 0, 4, DataType.Byte); gMesh.AddElement("NORMAL", 0, 3); gMesh.AddElement("TEXCOORD", 0, 2); gMesh.AddElement("TEXCOORD", 1, 2); // all combinations are set in this one each time gCustomProgram = new ShaderProgram(context); gCustomProgram.SetVertexShader(Resources.Shaders.M2VertexSingle_VS_Diffuse_T1); gCustomProgram.SetPixelShader(Resources.Shaders.M2Pixel_PS_Combiners_Mod); gMesh.Program = gCustomProgram; gNoBlendProgram = new ShaderProgram(context); gNoBlendProgram.SetPixelShader(Resources.Shaders.M2PixelOld); gNoBlendProgram.SetVertexShader(Resources.Shaders.M2VertexSingleOld); gBlendProgram = new ShaderProgram(context); gBlendProgram.SetPixelShader(Resources.Shaders.M2PixelBlendOld); gBlendProgram.SetVertexShader(Resources.Shaders.M2VertexSingleOld); gBlendTestProgram = new ShaderProgram(context); gBlendTestProgram.SetPixelShader(Resources.Shaders.M2PixelBlendAlphaOld); gBlendTestProgram.SetVertexShader(Resources.Shaders.M2VertexSingleOld); g2PassProgram = new ShaderProgram(context); g2PassProgram.SetPixelShader(Resources.Shaders.M2Pixel2PassOld); g2PassProgram.SetVertexShader(Resources.Shaders.M2VertexSingleOld); g3PassProgram = new ShaderProgram(context); g3PassProgram.SetPixelShader(Resources.Shaders.M2Pixel3PassOld); g3PassProgram.SetVertexShader(Resources.Shaders.M2VertexSingleOld); gPerDrawCallBuffer = new ConstantBuffer(context); gPerDrawCallBuffer.UpdateData(new PerDrawCallBuffer() { instanceMat = Matrix.Identity }); gPerPassBuffer = new ConstantBuffer(context); gPerPassBuffer.UpdateData(new PerModelPassBuffer() { uvAnimMatrix1 = Matrix.Identity, uvAnimMatrix2 = Matrix.Identity, uvAnimMatrix3 = Matrix.Identity, uvAnimMatrix4 = Matrix.Identity, modelPassParams = Vector4.Zero }); gSamplerWrapU = new Sampler(context) { AddressU = SharpDX.Direct3D11.TextureAddressMode.Wrap, AddressV = SharpDX.Direct3D11.TextureAddressMode.Clamp, AddressW = SharpDX.Direct3D11.TextureAddressMode.Clamp, Filter = SharpDX.Direct3D11.Filter.Anisotropic, MaximumAnisotropy = 16 }; gSamplerWrapV = new Sampler(context) { AddressU = SharpDX.Direct3D11.TextureAddressMode.Clamp, AddressV = SharpDX.Direct3D11.TextureAddressMode.Wrap, AddressW = SharpDX.Direct3D11.TextureAddressMode.Clamp, Filter = SharpDX.Direct3D11.Filter.Anisotropic, MaximumAnisotropy = 16 }; gSamplerWrapBoth = new Sampler(context) { AddressU = SharpDX.Direct3D11.TextureAddressMode.Wrap, AddressV = SharpDX.Direct3D11.TextureAddressMode.Wrap, AddressW = SharpDX.Direct3D11.TextureAddressMode.Clamp, Filter = SharpDX.Direct3D11.Filter.Anisotropic, MaximumAnisotropy = 16 }; gSamplerClampBoth = new Sampler(context) { AddressU = SharpDX.Direct3D11.TextureAddressMode.Clamp, AddressV = SharpDX.Direct3D11.TextureAddressMode.Clamp, AddressW = SharpDX.Direct3D11.TextureAddressMode.Clamp, Filter = SharpDX.Direct3D11.Filter.Anisotropic, MaximumAnisotropy = 16 }; for (var i = 0; i < BlendStates.Length; ++i) { BlendStates[i] = new BlendState(context); } BlendStates[0] = new BlendState(context) { BlendEnabled = false }; BlendStates[1] = new BlendState(context) { BlendEnabled = true, SourceBlend = SharpDX.Direct3D11.BlendOption.One, DestinationBlend = SharpDX.Direct3D11.BlendOption.Zero, SourceAlphaBlend = SharpDX.Direct3D11.BlendOption.One, DestinationAlphaBlend = SharpDX.Direct3D11.BlendOption.Zero }; BlendStates[2] = new BlendState(context) { BlendEnabled = true, SourceBlend = SharpDX.Direct3D11.BlendOption.SourceAlpha, DestinationBlend = SharpDX.Direct3D11.BlendOption.InverseSourceAlpha, SourceAlphaBlend = SharpDX.Direct3D11.BlendOption.SourceAlpha, DestinationAlphaBlend = SharpDX.Direct3D11.BlendOption.InverseSourceAlpha }; BlendStates[3] = new BlendState(context) { BlendEnabled = true, SourceBlend = SharpDX.Direct3D11.BlendOption.SourceColor, DestinationBlend = SharpDX.Direct3D11.BlendOption.DestinationColor, SourceAlphaBlend = SharpDX.Direct3D11.BlendOption.SourceAlpha, DestinationAlphaBlend = SharpDX.Direct3D11.BlendOption.DestinationAlpha }; BlendStates[4] = new BlendState(context) { BlendEnabled = true, SourceBlend = SharpDX.Direct3D11.BlendOption.SourceAlpha, DestinationBlend = SharpDX.Direct3D11.BlendOption.One, SourceAlphaBlend = SharpDX.Direct3D11.BlendOption.SourceAlpha, DestinationAlphaBlend = SharpDX.Direct3D11.BlendOption.One }; BlendStates[5] = new BlendState(context) { BlendEnabled = true, SourceBlend = SharpDX.Direct3D11.BlendOption.SourceAlpha, DestinationBlend = SharpDX.Direct3D11.BlendOption.InverseSourceAlpha, SourceAlphaBlend = SharpDX.Direct3D11.BlendOption.SourceAlpha, DestinationAlphaBlend = SharpDX.Direct3D11.BlendOption.InverseSourceAlpha }; BlendStates[6] = new BlendState(context) { BlendEnabled = true, SourceBlend = SharpDX.Direct3D11.BlendOption.DestinationColor, DestinationBlend = SharpDX.Direct3D11.BlendOption.SourceColor, SourceAlphaBlend = SharpDX.Direct3D11.BlendOption.DestinationAlpha, DestinationAlphaBlend = SharpDX.Direct3D11.BlendOption.SourceAlpha }; gNoCullState = new RasterState(context) { CullEnabled = false }; gCullState = new RasterState(context) { CullEnabled = true }; }
internal abstract void SetDepth(DepthState depthState);
private void _ConfigureDepth(bool depthEnabled) { (m_Camera.GetComponent(typeof(DepthEffect)) as MonoBehaviour).enabled = depthEnabled; m_DepthConfigured = true; m_DepthState = depthEnabled ? DepthState.DepthEnabled : DepthState.DepthDisabled; }
public GPUStateRenderTargets(GPUStateCapture state) { var regModeControl = state.Reg(GPURegisterName.RB_MODECONTROL); var regSurfaceInfo = state.Reg(GPURegisterName.RB_SURFACE_INFO); var regColor0Info = state.Reg(GPURegisterName.RB_COLOR_INFO); var regColor1Info = state.Reg(GPURegisterName.RB_COLOR1_INFO); var regColor2Info = state.Reg(GPURegisterName.RB_COLOR2_INFO); var regColor3Info = state.Reg(GPURegisterName.RB_COLOR3_INFO); var regColorMask = state.Reg(GPURegisterName.RB_COLOR_MASK); var regDepthInfo = state.Reg(GPURegisterName.RB_DEPTH_INFO); var regDepthControl = state.Reg(GPURegisterName.RB_DEPTHCONTROL); var regStencilRefMask = state.Reg(GPURegisterName.RB_STENCILREFMASK); // read standard stuff MSAA = (GPUMsaaSamples)((regSurfaceInfo >> 16) & 3); SurfacePitch = regSurfaceInfo & 0x3FFF; // reset color/depth state Color = new ColorState[4]; Depth = new DepthState(); // read surface settings var enableMode = (GPUModeControl)(regModeControl & 0x7); if (enableMode == GPUModeControl.ColorDepth) { UInt32[] regColor = { regColor0Info, regColor1Info, regColor2Info, regColor3Info }; for (int rtIndex = 0; rtIndex < 4; ++rtIndex) { var rtInfo = regColor[rtIndex]; // get color mask for this specific render target var writeMask = (regColorMask >> (rtIndex * 4)) & 0xF; if (writeMask != 0) { ColorState colorInfo = new ColorState(); colorInfo.WriteRed = (writeMask & 1) != 0; colorInfo.WriteGreen = (writeMask & 2) != 0; colorInfo.WriteBlue = (writeMask & 4) != 0; colorInfo.WriteAlpha = (writeMask & 8) != 0; colorInfo.Enabled = true; colorInfo.EdramBase = (rtInfo & 0xFFF); // tile address colorInfo.Format = (GPUColorRenderTargetFormat)((rtInfo >> 16) & 0xF); Color[rtIndex] = colorInfo; } } } // depth { var usesDepth = (0 != (regDepthControl & 0x00000002)) || (0 != (regDepthControl & 0x00000004)); var stencilWriteMask = (regStencilRefMask & 0x00FF0000) >> 16; var usesStencil = (0 != (regDepthControl & 0x00000001)) || (stencilWriteMask != 0); if (usesDepth || usesStencil) { DepthState depthState = new DepthState(); depthState.Enabled = true; depthState.EdramBase = (regDepthInfo & 0xFFF); depthState.Format = (GPUDepthRenderTargetFormat)((regDepthInfo >> 16) & 1); Depth = depthState; } } }
private void ConfigureDepth(bool depthEnabled) { (_camera.GetComponent(typeof(DepthEffect)) as MonoBehaviour).enabled = depthEnabled; _depthState = depthEnabled ? DepthState.DepthEnabled : DepthState.DepthDisabled; }
// Main entry point for our scriptable render loop public static void Render(ScriptableRenderContext context, IEnumerable <Camera> cameras) { bool stereoEnabled = XRSettings.isDeviceActive; foreach (Camera camera in cameras) { // Culling ScriptableCullingParameters cullingParams; // Stereo-aware culling parameters are configured to perform a single cull for both eyes if (!CullResults.GetCullingParameters(camera, stereoEnabled, out cullingParams)) { continue; } CullResults cull = new CullResults(); CullResults.Cull(ref cullingParams, context, ref cull); // Setup camera for rendering (sets render target, view/projection matrices and other // per-camera built-in shader variables). // If stereo is enabled, we also configure stereo matrices, viewports, and XR device render targets context.SetupCameraProperties(camera, stereoEnabled); // Draws in-between [Start|Stop]MultiEye are stereo-ized by engine if (stereoEnabled) { context.StartMultiEye(camera); } // clear depth buffer CommandBuffer cmd = new CommandBuffer(); cmd.ClearRenderTarget(true, false, Color.black); context.ExecuteCommandBuffer(cmd); cmd.Release(); // Setup global lighting shader variables SetupLightShaderVariables(cull.visibleLights, context); // Draw skybox context.DrawSkybox(camera); // Setup DrawSettings and FilterSettings ShaderPassName passName = new ShaderPassName("BasicPass"); DrawRendererSettings drawSettings = new DrawRendererSettings(camera, passName); FilterRenderersSettings filterSettings = new FilterRenderersSettings(true); //************************************************************* // Block RenderStateBlock rsb = new RenderStateBlock(RenderStateMask.Depth | RenderStateMask.Blend | RenderStateMask.Raster | RenderStateMask.Stencil); DepthState ds = rsb.depthState;// ds.writeEnabled = true; ds.compareFunction = CompareFunction.LessEqual; rsb.depthState = ds; // BlendState bs = rsb.blendState; // RenderTargetBlendState rs0 = bs.blendState0; // bs.alphaToMask = false; rs0.sourceColorBlendMode = BlendMode.SrcAlpha; rs0.destinationColorBlendMode = BlendMode.One; rs0.colorBlendOperation = BlendOp.Add; rs0.sourceAlphaBlendMode = BlendMode.Zero; rs0.destinationAlphaBlendMode = BlendMode.One; rs0.alphaBlendOperation = BlendOp.Add; rs0.writeMask = ColorWriteMask.All; bs.blendState0 = rs0; // rsb.blendState = bs; // RasterState rs = rsb.rasterState; // rs.cullingMode = CullMode.Off; rs.depthClip = false; rs.offsetFactor = 0; rs.offsetUnits = 0; rsb.rasterState = rs;// StencilState ss = rsb.stencilState;// rsb.stencilReference = 0; ss.compareFunction = CompareFunction.Disabled; ss.compareFunctionBack = CompareFunction.Disabled; ss.compareFunctionFront = CompareFunction.Disabled; ss.failOperation = StencilOp.Keep; ss.failOperationBack = StencilOp.Keep; ss.failOperationFront = StencilOp.Keep; ss.passOperation = StencilOp.Keep; ss.passOperationBack = StencilOp.Keep; ss.passOperationFront = StencilOp.Keep; ss.zFailOperation = StencilOp.Keep; ss.zFailOperationBack = StencilOp.Keep; ss.zFailOperationFront = StencilOp.Keep; ss.readMask = 255; ss.writeMask = 255; ss.enabled = true; rsb.stencilState = ss;// //************************************************************** //mapping RenderStateBlock rsb_opaque = new RenderStateBlock(RenderStateMask.Raster | RenderStateMask.Stencil); rsb_opaque.rasterState = rsb.rasterState; rsb_opaque.stencilState = rsb.stencilState; rsb_opaque.stencilReference = rsb.stencilReference; RenderStateBlock rsb_trans = new RenderStateBlock(RenderStateMask.Blend); rsb_trans.blendState = rsb.blendState; RenderStateBlock rsb_over = new RenderStateBlock(RenderStateMask.Raster | RenderStateMask.Depth | RenderStateMask.Stencil); rsb_over.depthState = rsb.depthState; rsb_over.rasterState = rsb.rasterState; rsb_over.stencilState = rsb.stencilState; rsb_over.stencilReference = rsb.stencilReference; List <RenderStateMapping> rsm = new List <RenderStateMapping> { new RenderStateMapping("Opaque", rsb_opaque), new RenderStateMapping("Transparent", rsb_trans), new RenderStateMapping("Overlay", rsb_over) }; //************************************************************** // Draw opaque objects using BasicPass shader pass filterSettings.layerMask = LayerMask.GetMask("Default"); drawSettings.sorting.flags = SortFlags.CommonOpaque; filterSettings.renderQueueRange = RenderQueueRange.opaque; context.DrawRenderers(cull.visibleRenderers, ref drawSettings, filterSettings); // WITH RENDERSTATEBLOCK OPAQUE filterSettings.layerMask = LayerMask.GetMask("TransparentFX"); drawSettings.sorting.flags = SortFlags.CommonOpaque; filterSettings.renderQueueRange = RenderQueueRange.opaque; context.DrawRenderers(cull.visibleRenderers, ref drawSettings, filterSettings, rsb); // WITH RENDERSTATEMAPPING OPAQUE filterSettings.layerMask = LayerMask.GetMask("Ignore Raycast"); drawSettings.sorting.flags = SortFlags.CommonOpaque; filterSettings.renderQueueRange = RenderQueueRange.opaque; context.DrawRenderers(cull.visibleRenderers, ref drawSettings, filterSettings, rsm); //************************************************************** // Draw transparent objects using BasicPass shader pass filterSettings.layerMask = LayerMask.GetMask("Default"); drawSettings.sorting.flags = SortFlags.CommonTransparent; filterSettings.renderQueueRange = RenderQueueRange.transparent; context.DrawRenderers(cull.visibleRenderers, ref drawSettings, filterSettings); // WITH RENDERSTATEBLOCK TRANSPARENT filterSettings.layerMask = LayerMask.GetMask("TransparentFX"); drawSettings.sorting.flags = SortFlags.CommonTransparent; filterSettings.renderQueueRange = RenderQueueRange.transparent; context.DrawRenderers(cull.visibleRenderers, ref drawSettings, filterSettings, rsb); // WITH RENDERSTATEMAPPING TRANSPARENT filterSettings.layerMask = LayerMask.GetMask("Ignore Raycast"); drawSettings.sorting.flags = SortFlags.CommonTransparent; filterSettings.renderQueueRange = RenderQueueRange.transparent; context.DrawRenderers(cull.visibleRenderers, ref drawSettings, filterSettings, rsm); //************************************************************** if (stereoEnabled) { context.StopMultiEye(camera); // StereoEndRender will reset state on the camera to pre-Stereo settings, // and invoke XR based events/callbacks. context.StereoEndRender(camera); } context.Submit(); } }