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 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 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); }