private ResourceRef <Material> CreateMaterial(RenderingDevice device) { var blendState = new BlendSpec { blendEnable = true, srcBlend = BlendOperand.SrcAlpha, destBlend = BlendOperand.InvSrcAlpha }; var depthState = new DepthStencilSpec(); depthState.depthEnable = false; depthState.depthWrite = false; var rasterizerState = new RasterizerSpec(); var vs = _device.GetShaders().LoadVertexShader("diffuse_only_vs"); var ps = _device.GetShaders().LoadPixelShader("diffuse_only_ps"); return(device.CreateMaterial( blendState, depthState, rasterizerState, Array.Empty <MaterialSamplerSpec>(), vs, ps).Ref()); }
private static ResourceRef <Material> CreateGaussBlurMaterial(RenderingDevice device, RenderTargetTexture texture, bool horizontal) { var samplerState = new SamplerSpec(); samplerState.addressU = TextureAddress.Clamp; samplerState.addressV = TextureAddress.Clamp; samplerState.magFilter = TextureFilterType.Linear; samplerState.minFilter = TextureFilterType.Linear; samplerState.mipFilter = TextureFilterType.Linear; var rasterizerState = new RasterizerSpec(); rasterizerState.cullMode = CullMode.None; var depthStencilState = new DepthStencilSpec(); depthStencilState.depthEnable = false; var vs = device.GetShaders().LoadVertexShader("gaussian_blur_vs"); var horDefines = new Dictionary <string, string>(); if (horizontal) { horDefines["HOR"] = "1"; } var ps = device.GetShaders().LoadPixelShader("gaussian_blur_ps", horDefines); var samplers = new MaterialSamplerSpec[] { new (new ResourceRef <ITexture>(texture), samplerState) }; return(device.CreateMaterial(null, depthStencilState, rasterizerState, samplers, vs, ps).Ref()); }
public RasterizerState(RasterizerSpec spec, SharpDX.Direct3D11.RasterizerState state, SharpDX.Direct3D11.RasterizerState multiSamplingState) { Spec = spec; State = state; MultiSamplingState = multiSamplingState; }
private ResourceRef <Material> ParseMaterial(JsonElement root) { if (!root.TryGetProperty("vertexShader", out var vertexShaderEl)) { throw new InvalidMaterialException(_path, "A vertexShader is required."); } var vertexShader = _device.GetShaders().LoadVertexShader(vertexShaderEl.GetString()); if (!root.TryGetProperty("fragmentShader", out var fragmentShaderEl)) { throw new InvalidMaterialException(_path, "A fragmentShader is required."); } var fragmentShader = _device.GetShaders().LoadPixelShader(fragmentShaderEl.GetString()); var blendState = new BlendSpec(); if (root.TryGetProperty("blend", out var blendEl)) { ParseBlendSpec(blendEl, blendState); } var depthStencil = new DepthStencilSpec(); if (root.TryGetProperty("depthStencil", out var depthStencilEl)) { ParseDepthStencil(depthStencilEl, depthStencil); } var rasterizer = new RasterizerSpec(); if (root.TryGetProperty("rasterizer", out var rasterizerEl)) { ParseRasterizer(rasterizerEl, rasterizer); } var samplers = new List <MaterialSamplerSpec>(); if (root.TryGetProperty("samplers", out var samplersEl)) { foreach (var samplerEl in samplersEl.EnumerateArray()) { var samplerState = new SamplerSpec(); ParseSampler(samplerEl, samplerState, out var texture); samplers.Add(new MaterialSamplerSpec(texture, samplerState)); } } return(_device.CreateMaterial( blendState, depthStencil, rasterizer, samplers.ToArray(), vertexShader, fragmentShader ).Ref()); }
private static ResourceRef <Material> CreateGeometryShadowMaterial(RenderingDevice device) { BlendSpec blendState = new BlendSpec(); blendState.blendEnable = true; blendState.srcBlend = BlendOperand.SrcAlpha; blendState.destBlend = BlendOperand.InvSrcAlpha; RasterizerSpec rasterizerState = new RasterizerSpec(); rasterizerState.cullMode = CullMode.None; DepthStencilSpec depthStencilState = new DepthStencilSpec(); depthStencilState.depthWrite = false; using var vs = device.GetShaders().LoadVertexShader("shadow_geom_vs"); using var ps = device.GetShaders().LoadPixelShader("diffuse_only_ps"); return(device.CreateMaterial(blendState, depthStencilState, rasterizerState, null, vs, ps).Ref()); }
private Material CreatePieFillMaterial(RenderingDevice device) { BlendSpec blendSpec = new BlendSpec(); blendSpec.blendEnable = true; blendSpec.srcBlend = BlendOperand.SrcAlpha; blendSpec.destBlend = BlendOperand.InvSrcAlpha; DepthStencilSpec depthStencilSpec = new DepthStencilSpec(); depthStencilSpec.depthEnable = false; RasterizerSpec rasterizerSpec = new RasterizerSpec(); rasterizerSpec.cullMode = CullMode.None; using var vertexShader = _device.GetShaders().LoadVertexShader("gui_vs"); using var pixelShader = _device.GetShaders().LoadPixelShader("diffuse_only_ps"); return(_device.CreateMaterial(blendSpec, depthStencilSpec, rasterizerSpec, null, vertexShader, pixelShader)); }
private void CreateMaterial() { using var ps = _device.GetShaders().LoadPixelShader("fogofwar_ps"); var blendState = new BlendSpec(); blendState.blendEnable = true; blendState.srcBlend = BlendOperand.SrcAlpha; blendState.destBlend = BlendOperand.InvSrcAlpha; DepthStencilSpec depthStencilState = new DepthStencilSpec(); depthStencilState.depthEnable = false; RasterizerSpec rasterizerState = new RasterizerSpec(); SamplerSpec samplerState = new SamplerSpec(); samplerState.addressU = TextureAddress.Clamp; samplerState.addressV = TextureAddress.Clamp; samplerState.magFilter = TextureFilterType.Linear; samplerState.minFilter = TextureFilterType.Linear; MaterialSamplerSpec[] samplers = { new(new ResourceRef <ITexture>(_blurredFogTexture.Resource), samplerState) };
private Material CreateQuadMaterial() { var blendState = new BlendSpec { blendEnable = true, srcBlend = BlendOperand.SrcAlpha, destBlend = BlendOperand.InvSrcAlpha }; var depthState = new DepthStencilSpec(); depthState.depthEnable = true; depthState.depthWrite = false; var rasterizerState = new RasterizerSpec(); rasterizerState.cullMode = CullMode.None; var vsDefines = new Dictionary <string, string> { { "TEXTURE_STAGES", "1" } }; var vs = _device.GetShaders().LoadVertexShader("mdf_vs", vsDefines); var ps = _device.GetShaders().LoadPixelShader("textured_simple_ps"); var samplerState = new SamplerSpec(); samplerState.addressU = TextureAddress.Clamp; samplerState.addressV = TextureAddress.Clamp; samplerState.minFilter = TextureFilterType.Linear; samplerState.magFilter = TextureFilterType.Linear; samplerState.mipFilter = TextureFilterType.Linear; var samplers = new[] { new MaterialSamplerSpec(new ResourceRef <ITexture>(null), samplerState) }; return(_device.CreateMaterial( blendState, depthState, rasterizerState, samplers, vs, ps)); }
public static Material CreateMaterial(RenderingDevice device, PartSysEmitter emitter, bool pointSprites) { var blendState = new BlendSpec(); blendState.blendEnable = true; switch (emitter.GetSpec().GetBlendMode()) { case PartSysBlendMode.Add: blendState.srcBlend = BlendOperand.SrcAlpha; blendState.destBlend = BlendOperand.One; break; case PartSysBlendMode.Subtract: blendState.srcBlend = BlendOperand.Zero; blendState.destBlend = BlendOperand.InvSrcAlpha; break; case PartSysBlendMode.Blend: blendState.srcBlend = BlendOperand.SrcAlpha; blendState.destBlend = BlendOperand.InvSrcAlpha; break; case PartSysBlendMode.Multiply: blendState.srcBlend = BlendOperand.Zero; blendState.destBlend = BlendOperand.SrcColor; break; default: break; } // Particles respect the depth buffer, but do not modify it DepthStencilSpec depthStencilState = new DepthStencilSpec(); depthStencilState.depthEnable = true; depthStencilState.depthWrite = false; RasterizerSpec rasterizerState = new RasterizerSpec(); rasterizerState.cullMode = CullMode.None; var samplers = new List <MaterialSamplerSpec>(); var shaderName = "diffuse_only_ps"; var textureName = emitter.GetSpec().GetTextureName(); if (textureName.Length > 0) { var samplerState = new SamplerSpec { addressU = TextureAddress.Clamp, addressV = TextureAddress.Clamp, minFilter = TextureFilterType.Linear, magFilter = TextureFilterType.Linear, mipFilter = TextureFilterType.Linear }; var texture = device.GetTextures().Resolve(textureName, true); samplers.Add(new MaterialSamplerSpec(texture, samplerState)); shaderName = "textured_simple_ps"; } using var pixelShader = device.GetShaders().LoadPixelShader(shaderName); var vsName = pointSprites ? "particles_points_vs" : "particles_quads_vs"; using var vertexShader = device.GetShaders().LoadVertexShader(vsName); return(device.CreateMaterial(blendState, depthStencilState, rasterizerState, samplers.ToArray(), vertexShader, pixelShader)); }
protected bool Equals(RasterizerSpec other) { return(wireframe == other.wireframe && cullMode == other.cullMode && scissor == other.scissor); }