private void ReadCanvasKind(YamlMappingNode mapping) { var source = ""; if (mapping.TryGetNode("light_mode", out var node)) { switch (node.AsString()) { case "normal": break; case "unshaded": source += "light_mode unshaded;\n"; break; default: throw new InvalidOperationException($"Invalid light mode: '{node.AsString()}'"); } } if (mapping.TryGetNode("blend_mode", out node)) { switch (node.AsString()) { case "mix": source += "blend_mode mix;\n"; break; case "add": source += "blend_mode add;\n"; break; case "subtract": source += "blend_mode subtract;\n"; break; case "multiply": source += "blend_mode multiply;\n"; break; default: throw new InvalidOperationException($"Invalid blend mode: '{node.AsString()}'"); } } source += "void fragment() {\n COLOR = zTexture(UV);\n}"; var preset = ShaderParser.Parse(source, _resourceCache); CompiledCanvasShader = _clyde.LoadShader(preset, $"canvas_preset_{ID}"); }
void ISerializationHooks.AfterDeserialization() { switch (_rawKind) { case "source": Kind = ShaderKind.Source; if (path == null) { throw new InvalidOperationException(); } Source = IoCManager.Resolve <IResourceCache>().GetResource <ShaderSourceResource>(path); if (paramMapping != null) { ShaderParams = new Dictionary <string, object>(); foreach (var item in paramMapping !) { var name = item.Key; if (!Source.ParsedShader.Uniforms.TryGetValue(name, out var uniformDefinition)) { Logger.ErrorS("shader", "Shader param '{0}' does not exist on shader '{1}'", name, path); continue; } var value = _parseUniformValue(item.Value, uniformDefinition.Type.Type); ShaderParams.Add(name, value); } } break; case "canvas": Kind = ShaderKind.Canvas; var source = ""; if (rawMode != null) { switch (rawMode) { case "normal": break; case "unshaded": source += "light_mode unshaded;\n"; break; default: throw new InvalidOperationException($"Invalid light mode: '{rawMode}'"); } } if (rawBlendMode != null) { switch (rawBlendMode) { case "mix": source += "blend_mode mix;\n"; break; case "add": source += "blend_mode add;\n"; break; case "subtract": source += "blend_mode subtract;\n"; break; case "multiply": source += "blend_mode multiply;\n"; break; default: throw new InvalidOperationException($"Invalid blend mode: '{rawBlendMode}'"); } } source += "void fragment() {\n COLOR = zTexture(UV);\n}"; var preset = ShaderParser.Parse(source, _resourceCache); CompiledCanvasShader = IoCManager.Resolve <IClydeInternal>().LoadShader(preset, $"canvas_preset_{ID}"); break; default: throw new InvalidOperationException($"Invalid shader kind: '{_rawKind}'"); } if (StencilDataHolder != null) { _stencilEnabled = true; } }