public void ShutDown() { SwapChain?.SetFullscreenState(false, null); AlphaEnableBlendingState?.Dispose(); AlphaEnableBlendingState = null; AlphaDisableBlendingState?.Dispose(); AlphaDisableBlendingState = null; DepthDisabledStencilState?.Dispose(); DepthDisabledStencilState = null; RasterState?.Dispose(); RasterState = null; RasterStateNoCulling?.Dispose(); RasterStateNoCulling = null; RasterStateWirefram?.Dispose(); RasterStateWirefram = null; DepthStencilView?.Dispose(); DepthStencilView = null; DepthStencilState?.Dispose(); DepthStencilState = null; DepthStencilBuffer?.Dispose(); DepthStencilBuffer = null; RenderTargetView?.Dispose(); RenderTargetView = null; DeviceContext?.Dispose(); DeviceContext = null; Device?.Dispose(); Device = null; SwapChain?.Dispose(); SwapChain = null; }
public void ShutDown() { // Before shutting down set to windowed mode or when you release the swap chain it will throw an exception. SwapChain?.SetFullscreenState(false, null); // Dispose of all objects. DepthDisabledStencilState?.Dispose(); DepthDisabledStencilState = null; RasterState?.Dispose(); RasterState = null; DepthStencilView?.Dispose(); DepthStencilView = null; DepthStencilState?.Dispose(); DepthStencilState = null; DepthStencilBuffer?.Dispose(); DepthStencilBuffer = null; RenderTargetView?.Dispose(); RenderTargetView = null; DeviceContext?.Dispose(); DeviceContext = null; Device?.Dispose(); Device = null; SwapChain?.Dispose(); SwapChain = null; }
public static void Initialize(GxContext context) { gNoBlendState = new BlendState(context) { BlendEnabled = false }; gAlphaBlendState = new BlendState(context) { BlendEnabled = true }; gNoCullState = new RasterState(context) { CullEnabled = false }; gCullState = new RasterState(context) { CullEnabled = true }; Sampler = new Sampler(context); InstanceBuffer = new ConstantBuffer(context); InstanceBuffer.UpdateData(Matrix.Identity); // preallocate space so the underlying buffer wont change anymore Mesh = new Mesh(context) { DepthState = { DepthEnabled = true }, Stride = IO.SizeCache <IO.Files.Models.WmoVertex> .Size }; Mesh.AddElement("POSITION", 0, 3); Mesh.AddElement("NORMAL", 0, 3); Mesh.AddElement("TEXCOORD", 0, 2); Mesh.AddElement("COLOR", 0, 4, DataType.Byte, true); gNoBlendProgram = new ShaderProgram(context); gNoBlendProgram.SetVertexShader(Resources.Shaders.WmoVertex); gNoBlendProgram.SetPixelShader(Resources.Shaders.WmoPixel); gBlendProgram = new ShaderProgram(context); gBlendProgram.SetVertexShader(Resources.Shaders.WmoVertex); gBlendProgram.SetPixelShader(Resources.Shaders.WmoPixelBlend); gIndoorNoBlendProgram = new ShaderProgram(context); gIndoorNoBlendProgram.SetVertexShader(Resources.Shaders.WmoVertex); gIndoorNoBlendProgram.SetPixelShader(Resources.Shaders.WmoPixelIndoor); gIndoorBlendProgram = new ShaderProgram(context); gIndoorBlendProgram.SetVertexShader(Resources.Shaders.WmoVertex); gIndoorBlendProgram.SetPixelShader(Resources.Shaders.WmoPixelBlendIndoor); Mesh.Program = gNoBlendProgram; Mesh.InitLayout(gNoBlendProgram); }
public void Shutdown() { // Before shutting down set to windowed mode or when you release the swap chain it will throw an exception. if (SwapChain != null) { SwapChain.SetFullscreenState(false, null); } if (DepthDisabledStencilState != null) { DepthDisabledStencilState.Dispose(); DepthDisabledStencilState = null; } if (RasterState != null) { RasterState.Dispose(); RasterState = null; } if (DepthStencilView != null) { DepthStencilView.Dispose(); DepthStencilView = null; } if (DepthStencilState != null) { DepthStencilState.Dispose(); DepthStencilState = null; } if (DepthStencilBuffer != null) { DepthStencilBuffer.Dispose(); DepthStencilBuffer = null; } if (RenderTargetView != null) { RenderTargetView.Dispose(); RenderTargetView = null; } if (Device != null) { Device.Dispose(); Device = null; } if (SwapChain != null) { SwapChain.Dispose(); SwapChain = null; } }
public void ShutDown() { SwapChain?.SetFullscreenState(false, null); RasterState?.Dispose(); RasterState = null; DepthStencilView?.Dispose(); DepthStencilView = null; DepthStencilState?.Dispose(); DepthStencilState = null; DepthStencilBuffer?.Dispose(); DepthStencilBuffer = null; RenderTargetView?.Dispose(); RenderTargetView = null; DeviceContext?.Dispose(); DeviceContext = null; Device?.Dispose(); Device = null; SwapChain?.Dispose(); SwapChain = null; }
public void ShutDown() { // Before shutting down set to windowed mode or when you release the swap chain it will throw an exception. SwapChain?.SetFullscreenState(false, null); RasterState?.Dispose(); RasterState = null; depthStencilState?.Dispose(); depthStencilState = null; DepthStencilBuffer?.Dispose(); DepthStencilBuffer = null; _depthStencilView?.Dispose(); _depthStencilView = null; _renderTargetView?.Dispose(); _renderTargetView = null; DeviceContext?.Dispose(); Device?.Dispose(); SwapChain?.Dispose(); AlphaEnableBlendingState?.Dispose(); AlphaEnableBlendingState = null; AlphaDisableBlendingState?.Dispose(); AlphaDisableBlendingState = null; DepthDisabledStencilState?.Dispose(); DepthDisabledStencilState = null; //DepthStencilView?.Dispose(); //DepthStencilView = null; DepthStencilState?.Dispose(); DepthStencilState = null; DepthStencilBuffer?.Dispose(); DepthStencilBuffer = null; if (main_thread_update != null) { //main_thread_update.Suspend(); main_thread_update = null; } ShutDownGraphics(); }
public static void Initialize(GxContext context) { gMesh = new Mesh(context) { Stride = IO.SizeCache <M2Vertex> .Size, InstanceStride = IO.SizeCache <PerInstanceBuffer> .Size, DepthState = { DepthEnabled = true, DepthWriteEnabled = true } }; 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); gMesh.AddElement("TEXCOORD", 2, 4, DataType.Float, false, 1, true); gMesh.AddElement("TEXCOORD", 3, 4, DataType.Float, false, 1, true); gMesh.AddElement("TEXCOORD", 4, 4, DataType.Float, false, 1, true); gMesh.AddElement("TEXCOORD", 5, 4, DataType.Float, false, 1, true); gMesh.AddElement("COLOR", 0, 4, DataType.Float, false, 1, true); // all combinations are set in this one each time gCustomProgram = new ShaderProgram(context); gCustomProgram.SetVertexShader(Resources.Shaders.M2VertexInstanced_VS_Diffuse_T1); gCustomProgram.SetPixelShader(Resources.Shaders.M2Pixel_PS_Combiners_Opaque); gMesh.Program = gCustomProgram; // Old versions for temporary WOTLK compatibility.. can we figure out how to map these to the actual types?? gNoBlendProgram = new ShaderProgram(context); gNoBlendProgram.SetVertexShader(Resources.Shaders.M2VertexInstancedOld); gNoBlendProgram.SetPixelShader(Resources.Shaders.M2PixelOld); gMaskBlendProgram = new ShaderProgram(context); gMaskBlendProgram.SetVertexShader(Resources.Shaders.M2VertexInstancedOld); gMaskBlendProgram.SetPixelShader(Resources.Shaders.M2PixelBlendAlphaOld); 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 }; gNoCullState = new RasterState(context) { CullEnabled = false }; gCullState = new RasterState(context) { CullEnabled = true }; }
public static void Initialize(GxContext context) { Mesh = new Mesh(context) { Stride = IO.SizeCache <M2Vertex> .Size, DepthState = { DepthEnabled = true } }; Mesh.BlendState.Dispose(); Mesh.IndexBuffer.Dispose(); Mesh.VertexBuffer.Dispose(); Mesh.AddElement("POSITION", 0, 3); Mesh.AddElement("BLENDWEIGHT", 0, 4, DataType.Byte, true); Mesh.AddElement("BLENDINDEX", 0, 4, DataType.Byte); Mesh.AddElement("NORMAL", 0, 3); Mesh.AddElement("TEXCOORD", 0, 2); Mesh.AddElement("TEXCOORD", 1, 2); var program = new ShaderProgram(context); program.SetVertexShader(Resources.Shaders.M2VertexPortrait); program.SetPixelShader(Resources.Shaders.M2PixelPortrait); Mesh.Program = program; Sampler = new Sampler(context) { AddressMode = SharpDX.Direct3D11.TextureAddressMode.Wrap, Filter = SharpDX.Direct3D11.Filter.MinMagMipLinear }; 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 }; gNoBlendProgram = program; gBlendProgram = new ShaderProgram(context); gBlendProgram.SetPixelShader(Resources.Shaders.M2PixelPortraitBlend); gBlendProgram.SetVertexShader(Resources.Shaders.M2VertexPortrait); gNoCullState = new RasterState(context) { CullEnabled = false }; gCullState = new RasterState(context) { CullEnabled = true }; }
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 }; }
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 }); }
// 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(); } }