public virtual void SetShaderParameters(Device device, DeviceContext deviceContext, MaterialParameters matParams) { if (!previousEditorParams.Equals(matParams.SelectionColour)) { var editorParams = new EditorParameterBuffer() { selectionColour = matParams.SelectionColour }; ConstantBufferFactory.UpdatePixelBuffer(deviceContext, ConstantEditorParamsBuffer, 1, editorParams); previousEditorParams = editorParams.selectionColour; } //experiments with samplers; currently the toolkit doesn't not support any types. /*SamplerStateDescription samplerDesc = new SamplerStateDescription() * { * Filter = Filter.Anisotropic, * AddressU = (material != null) ? (TextureAddressMode)material.Samplers["S000"].SamplerStates[0] : TextureAddressMode.Wrap, * AddressV = (material != null) ? (TextureAddressMode)material.Samplers["S000"].SamplerStates[1] : TextureAddressMode.Wrap, * AddressW = (material != null) ? (TextureAddressMode)material.Samplers["S000"].SamplerStates[2] : TextureAddressMode.Wrap, * MipLodBias = 0, * MaximumAnisotropy = 16, * ComparisonFunction = Comparison.Always, * BorderColor = new Color4(0, 0, 0, 0), * MinimumLod = 0, * MaximumLod = float.MaxValue * }; * * SamplerState = new SamplerState(device, samplerDesc);*/ }
public override bool Init(Device device, InputElement[] elements, string vsFileName, string psFileName, string vsEntryPoint, string psEntryPoint) { if (!base.Init(device, elements, vsFileName, psFileName, vsEntryPoint, psEntryPoint)) { return(false); } ConstantShaderParamBuffer = ConstantBufferFactory.ConstructBuffer <Shader_601151254Params>(device, "ShaderParamBuffer"); return(true); }
public override bool Init(ID3D11Device Dx11Device, ShaderInitParams InitParams) { if (!base.Init(Dx11Device, InitParams)) { return(false); } ConstantExtraParameterBuffer = ConstantBufferFactory.ConstructBuffer <ExtraParameterBuffer>(Dx11Device, "ExtraBuffer"); return(true); }
public override bool Init(Device Dx11Device, ShaderInitParams InitParams) { if (!base.Init(Dx11Device, InitParams)) { return(false); } ConstantShaderParamBuffer = ConstantBufferFactory.ConstructBuffer <Shader_50760736Params>(Dx11Device, "ShaderParamBuffer"); return(true); }
public override bool Init(Device device, InputElement[] elements, string vsFileName, string psFileName, string vsEntryPoint, string psEntryPoint) { if (!base.Init(device, elements, vsFileName, psFileName, vsEntryPoint, psEntryPoint)) { return(false); } ConstantExtraParameterBuffer = ConstantBufferFactory.ConstructBuffer <ExtraParameterBuffer>(device, "ExtraBuffer"); return(true); }
public virtual void SetSceneVariables(ID3D11DeviceContext context, Matrix4x4 WorldMatrix, Camera camera) { Matrix4x4 tMatrix = Matrix4x4.Transpose(WorldMatrix); MatrixBuffer matrixBuffer = new MatrixBuffer() { world = tMatrix, view = camera.ViewMatrixTransposed, projection = camera.ProjectionMatrixTransposed }; ConstantBufferFactory.UpdateVertexBuffer(context, ConstantMatrixBuffer, 0, matrixBuffer); }
public virtual bool Init(Device device, ShaderInitParams InitParams) { // Attempt to construct pixel shader if (InitParams.PixelShaderFile.IsValid()) { ShaderBytecode PixelBytecode = ConstructBytecode(InitParams.PixelShaderFile); OurPixelShader = new PixelShader(device, PixelBytecode); PixelBytecode.Dispose(); } // Attempt to construct vertex shader if (InitParams.VertexShaderFile.IsValid()) { ShaderBytecode VertexBytecode = ConstructBytecode(InitParams.VertexShaderFile); OurVertexShader = new VertexShader(device, VertexBytecode); Layout = new InputLayout(device, ShaderSignature.GetInputSignature(VertexBytecode), InitParams.Elements); VertexBytecode.Dispose(); } // Attempt to construct geometry shader if (InitParams.GeometryShaderFile.IsValid()) { ShaderBytecode GeometryBytecode = ConstructBytecode(InitParams.GeometryShaderFile); OurGeometryShader = new GeometryShader(device, GeometryBytecode); GeometryBytecode.Dispose(); } SamplerStateDescription samplerDesc = new SamplerStateDescription() { Filter = Filter.Anisotropic, AddressU = TextureAddressMode.Wrap, AddressV = TextureAddressMode.Wrap, AddressW = TextureAddressMode.Wrap, MipLodBias = 0, MaximumAnisotropy = 8, ComparisonFunction = Comparison.Always, BorderColor = new Color4(0, 0, 0, 0), MinimumLod = 0, MaximumLod = 0 }; SamplerState = new SamplerState(device, samplerDesc); ConstantCameraBuffer = ConstantBufferFactory.ConstructBuffer <DCameraBuffer>(device, "CameraBuffer"); ConstantLightBuffer = ConstantBufferFactory.ConstructBuffer <LightBuffer>(device, "LightBuffer"); ConstantMatrixBuffer = ConstantBufferFactory.ConstructBuffer <MatrixBuffer>(device, "MatrixBuffer"); ConstantEditorParamsBuffer = ConstantBufferFactory.ConstructBuffer <EditorParameterBuffer>(device, "EditorBuffer"); return(true); }
public virtual bool Init(ID3D11Device device, ShaderInitParams InitParams) { // Attempt to construct pixel shader if (InitParams.PixelShaderFile.IsValid()) { Blob PixelBytecode = ConstructBytecode(InitParams.PixelShaderFile); OurPixelShader = device.CreatePixelShader(PixelBytecode); PixelBytecode.Dispose(); } // Attempt to construct vertex shader if (InitParams.VertexShaderFile.IsValid()) { Blob VertexBytecode = ConstructBytecode(InitParams.VertexShaderFile); OurVertexShader = device.CreateVertexShader(VertexBytecode); Layout = device.CreateInputLayout(InitParams.Elements, VertexBytecode); VertexBytecode.Dispose(); } // Attempt to construct geometry shader if (InitParams.GeometryShaderFile.IsValid()) { Blob GeometryBytecode = ConstructBytecode(InitParams.GeometryShaderFile); OurGeometryShader = device.CreateGeometryShader(GeometryBytecode); GeometryBytecode.Dispose(); } SamplerDescription samplerDesc = new SamplerDescription() { Filter = Filter.Anisotropic, AddressU = TextureAddressMode.Wrap, AddressV = TextureAddressMode.Wrap, AddressW = TextureAddressMode.Wrap, MipLODBias = 0, MaxAnisotropy = 8, ComparisonFunction = ComparisonFunction.Always, BorderColor = new Color4(0, 0, 0, 0), MinLOD = 0, MaxLOD = 0 }; SamplerState = device.CreateSamplerState(samplerDesc); ConstantCameraBuffer = ConstantBufferFactory.ConstructBuffer <DCameraBuffer>(device, "CameraBuffer"); ConstantLightBuffer = ConstantBufferFactory.ConstructBuffer <LightBuffer>(device, "LightBuffer"); ConstantMatrixBuffer = ConstantBufferFactory.ConstructBuffer <MatrixBuffer>(device, "MatrixBuffer"); ConstantEditorParamsBuffer = ConstantBufferFactory.ConstructBuffer <EditorParameterBuffer>(device, "EditorBuffer"); return(true); }
public override void SetShaderParameters(Device device, DeviceContext context, MaterialParameters matParams) { base.SetShaderParameters(device, context, matParams); int previousHasTangentSpace = extraParams.hasTangentSpace; var material = matParams.MaterialData; if (material == null) { ShaderResourceView texture = RenderStorageSingleton.Instance.TextureCache[0]; context.PixelShader.SetShaderResource(0, texture); } else { HashName TextureFile = material.GetTextureByID("S000"); ShaderResourceView texture = null; if (TextureFile != null) { texture = RenderStorageSingleton.Instance.TextureCache[TextureFile.Hash]; } else { texture = RenderStorageSingleton.Instance.TextureCache[0]; } context.PixelShader.SetShaderResource(0, texture); TextureFile = material.GetTextureByID("S001"); if (TextureFile != null) { texture = RenderStorageSingleton.Instance.TextureCache[TextureFile.Hash]; extraParams.hasTangentSpace = 1; } else { texture = RenderStorageSingleton.Instance.TextureCache[1]; extraParams.hasTangentSpace = 0; } context.PixelShader.SetShaderResource(1, texture); } if (previousRenderType != extraParams.hasTangentSpace) { ConstantBufferFactory.UpdatePixelBuffer(context, ConstantExtraParameterBuffer, 2, extraParams); } }
public virtual void SetSceneVariables(DeviceContext context, Matrix WorldMatrix, Camera camera) { Matrix tMatrix = WorldMatrix; Matrix vMatrix = camera.ViewMatrix; Matrix cMatrix = camera.ProjectionMatrix; vMatrix.Transpose(); cMatrix.Transpose(); tMatrix.Transpose(); MatrixBuffer matrixBuffer = new MatrixBuffer() { world = tMatrix, view = vMatrix, projection = cMatrix }; ConstantBufferFactory.UpdateVertexBuffer(context, ConstantMatrixBuffer, 0, matrixBuffer); }
public virtual bool Init(Device device, InputElement[] elements, string vsFileName, string psFileName, string vsEntryPoint, string psEntryPoint) { ShaderBytecode pixelShaderByteCode; ShaderBytecode vertexShaderByteCode; vsFileName = ToolkitSettings.ShaderPath + vsFileName; psFileName = ToolkitSettings.ShaderPath + psFileName; pixelShaderByteCode = ShaderBytecode.CompileFromFile(psFileName, psEntryPoint, "ps_4_0", ShaderFlags.None, EffectFlags.None); vertexShaderByteCode = ShaderBytecode.CompileFromFile(vsFileName, vsEntryPoint, "vs_4_0", ShaderFlags.None, EffectFlags.None); PixelShader = new PixelShader(device, pixelShaderByteCode); VertexShader = new VertexShader(device, vertexShaderByteCode); Layout = new InputLayout(device, ShaderSignature.GetInputSignature(vertexShaderByteCode), elements); SamplerStateDescription samplerDesc = new SamplerStateDescription() { Filter = Filter.Anisotropic, AddressU = TextureAddressMode.Wrap, AddressV = TextureAddressMode.Wrap, AddressW = TextureAddressMode.Wrap, MipLodBias = 0, MaximumAnisotropy = 16, ComparisonFunction = Comparison.Always, BorderColor = new Color4(0, 0, 0, 0), MinimumLod = 0, MaximumLod = float.MaxValue }; SamplerState = new SamplerState(device, samplerDesc); ConstantCameraBuffer = ConstantBufferFactory.ConstructBuffer <DCameraBuffer>(device, "CameraBuffer"); ConstantLightBuffer = ConstantBufferFactory.ConstructBuffer <LightBuffer>(device, "LightBuffer"); ConstantMatrixBuffer = ConstantBufferFactory.ConstructBuffer <MatrixBuffer>(device, "MatrixBuffer"); ConstantEditorParamsBuffer = ConstantBufferFactory.ConstructBuffer <EditorParameterBuffer>(device, "EditorBuffer"); pixelShaderByteCode.Dispose(); vertexShaderByteCode.Dispose(); return(true); }
public virtual void InitCBuffersFrame(DeviceContext context, Camera camera, WorldSettings settings) { var cameraBuffer = new DCameraBuffer() { cameraPosition = camera.Position, padding = 0.0f }; ConstantBufferFactory.UpdateVertexBuffer(context, ConstantCameraBuffer, 1, cameraBuffer); if (previousLighting == null || !previousLighting.Equals(settings.Lighting)) { LightBuffer lightbuffer = new LightBuffer() { ambientColor = settings.Lighting.AmbientColor, diffuseColor = settings.Lighting.DiffuseColour, LightDirection = settings.Lighting.Direction, specularColor = settings.Lighting.SpecularColor, specularPower = settings.Lighting.SpecularPower }; previousLighting = settings.Lighting; ConstantBufferFactory.UpdatePixelBuffer(context, ConstantLightBuffer, 0, lightbuffer); } }
public override void SetSceneVariables(DeviceContext deviceContext, Matrix WorldMatrix, Camera camera) { base.SetSceneVariables(deviceContext, WorldMatrix, camera); ConstantBufferFactory.UpdatePixelBuffer(deviceContext, ConstantShaderParamBuffer, 2, ShaderParams); }