private static Material CreateMaterial(RenderingDevice device) { var blendState = new BlendSpec { blendEnable = true, srcBlend = BlendOperand.SrcAlpha, destBlend = BlendOperand.InvSrcAlpha }; var depthStencilState = new DepthStencilSpec(); depthStencilState.depthEnable = false; var vertexShader = device.GetShaders().LoadVertexShader("font_vs"); var pixelShader = device.GetShaders().LoadPixelShader("textured_simple_ps"); return(device.CreateMaterial( blendState, depthStencilState, null, null, vertexShader, pixelShader )); }
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 Material CreateMaterial(RenderingDevice device, string pixelShaderName, bool forLine = false, bool blending = true) { BlendSpec blendSpec = new BlendSpec(); blendSpec.blendEnable = blending; blendSpec.srcBlend = BlendOperand.SrcAlpha; blendSpec.destBlend = BlendOperand.InvSrcAlpha; DepthStencilSpec depthStencilSpec = new DepthStencilSpec(); depthStencilSpec.depthEnable = false; var vsDefines = new Dictionary <string, string>(); if (forLine) { vsDefines["DRAW_LINES"] = "1"; } using var vertexShader = device.GetShaders().LoadVertexShader("gui_vs", vsDefines); using var pixelShader = device.GetShaders().LoadPixelShader(pixelShaderName); return(device.CreateMaterial(blendSpec, depthStencilSpec, null, null, vertexShader.Resource, pixelShader.Resource)); }
public bool Equals(BlendSpec other) { return(blendEnable == other.blendEnable && srcBlend == other.srcBlend && destBlend == other.destBlend && srcAlphaBlend == other.srcAlphaBlend && destAlphaBlend == other.destAlphaBlend && writeRed == other.writeRed && writeGreen == other.writeGreen && writeBlue == other.writeBlue && writeAlpha == other.writeAlpha); }
private Material CreateLineMaterial(bool occludedOnly) { var blendState = new BlendSpec(); blendState.blendEnable = true; blendState.srcBlend = BlendOperand.SrcAlpha; blendState.destBlend = BlendOperand.InvSrcAlpha; var depthState = new DepthStencilSpec(); depthState.depthEnable = true; depthState.depthWrite = false; if (occludedOnly) { depthState.depthFunc = ComparisonFunc.GreaterEqual; } using var vs = _device.GetShaders().LoadVertexShader("line_vs"); using var ps = _device.GetShaders().LoadPixelShader("diffuse_only_ps"); return(_device.CreateMaterial( blendState, depthState, null, null, vs.Resource, ps.Resource )); }
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 Material CreateOutlineMaterial(RenderingDevice device) { BlendSpec blendSpec = new BlendSpec(); blendSpec.blendEnable = true; blendSpec.srcBlend = BlendOperand.SrcAlpha; blendSpec.destBlend = BlendOperand.InvSrcAlpha; DepthStencilSpec depthStencilSpec = new DepthStencilSpec(); depthStencilSpec.depthEnable = false; using var vertexShader = device.GetShaders().LoadVertexShader("line_vs"); using var pixelShader = device.GetShaders().LoadPixelShader("diffuse_only_ps"); return(device.CreateMaterial(blendSpec, depthStencilSpec, null, null, vertexShader, pixelShader)); }
private static ResourceRef <Material> CreateShadowMapMaterial(RenderingDevice device) { DepthStencilSpec depthStencilState = new DepthStencilSpec(); depthStencilState.depthEnable = false; using var vs = device.GetShaders().LoadVertexShader("shadowmap_geom_vs"); using var ps = device.GetShaders().LoadPixelShader("diffuse_only_ps"); BlendSpec blendSpec = new BlendSpec(); blendSpec.blendEnable = true; blendSpec.destBlend = BlendOperand.Zero; blendSpec.srcBlend = BlendOperand.SrcAlpha; blendSpec.destAlphaBlend = BlendOperand.Zero; blendSpec.srcAlphaBlend = BlendOperand.One; return(device.CreateMaterial(blendSpec, depthStencilState, null, null, vs, ps).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)); }