/// <summary> /// Converts a <see cref="Color3F"/> to an OpenTK <see cref="Vector3"/> as R,G,B,A. /// </summary> /// <param name="color">The <see cref="Color4F"/>.</param> /// <returns>The OpenTK <see cref="Vector4"/> as R,G,B,A.</returns> public static Vector4 ToOpenTK(this Color4F color) { return(new Vector4(color.R, color.G, color.B, color.A)); }
Material ParseMaterial(XmlReader xml, ResourceLocation dest, string srcPath) { float opacity = 1; Material mat = new Material(null); int depth = xml.Depth; Color4F diffuse = new Color4F(); Color4F ambient = new Color4F(); Color4F specular = new Color4F(); Color4F emissive = new Color4F(); while (xml.Read() && xml.Depth > depth) { if (xml.IsStartElement() && !xml.IsEmptyElement) { switch (xml.Name) { case "Diffuse": diffuse = ParseColor(xml.ReadString()); break; case "Ambient": ambient = ParseColor(xml.ReadString()); break; case "Specular": specular = ParseColor(xml.ReadString()); break; case "Emissive": emissive = ParseColor(xml.ReadString()); break; case "Opacity": opacity = float.Parse(xml.ReadString()) / 100f; break; case "Power": mat.Power = float.Parse(xml.ReadString()); break; case "DiffuseMap": string texFile = xml.ReadString(); string texFileName = Path.GetFileNameWithoutExtension(texFile) + ".tex"; mat.SetTextureFile(0, texFileName); FileLocation fl = dest as FileLocation; if (fl != null) { string dstTex = Path.Combine(Path.GetDirectoryName(fl.Path), texFileName); if (!File.Exists(dstTex) && File.Exists(texFile)) { TextureConverter conv = new TextureConverter(); conv.Convert(fl, new DevFileLocation(dstTex)); //File.Copy(Path.Combine(srcPath, texFile), dstTex, false); } } break; } } } mat.IsTransparent = opacity < 1; ambient.Alpha = opacity; diffuse.Alpha = opacity; emissive.Alpha = opacity; specular.Alpha = opacity; mat.Ambient = ambient; mat.Diffuse = diffuse; mat.Emissive = emissive; mat.Specular = specular; return mat; }
public float Brightness = 2.0f; // TODO: Controllable! public GlowstickEntity(Region tregion, int color) // TODO: Int -> Actual Color4F? : base(tregion, false) { System.Drawing.Color col = System.Drawing.Color.FromArgb(color); GColor = Color4F.FromArgb(col.R, col.G, col.B, col.A); }
Material ParseMaterial(XmlReader xml, ResourceLocation dest, string srcPath) { float opacity = 1; Material mat = new Material(null); int depth = xml.Depth; Color4F diffuse = new Color4F(); Color4F ambient = new Color4F(); Color4F specular = new Color4F(); Color4F emissive = new Color4F(); while (xml.Read() && xml.Depth > depth) { if (xml.IsStartElement() && !xml.IsEmptyElement) { switch (xml.Name) { case "Diffuse": diffuse = ParseColor(xml.ReadString()); break; case "Ambient": ambient = ParseColor(xml.ReadString()); break; case "Specular": specular = ParseColor(xml.ReadString()); break; case "Emissive": emissive = ParseColor(xml.ReadString()); break; case "Opacity": opacity = float.Parse(xml.ReadString()) / 100f; break; case "Power": mat.Power = float.Parse(xml.ReadString()); break; case "DiffuseMap": string texFile = xml.ReadString(); string texFileName = Path.GetFileNameWithoutExtension(texFile) + ".tex"; mat.SetTextureFile(0, texFileName); FileLocation fl = dest as FileLocation; if (fl != null) { string dstTex = Path.Combine(Path.GetDirectoryName(fl.Path), texFileName); if (!File.Exists(dstTex) && File.Exists(texFile)) { TextureConverter conv = new TextureConverter(); conv.Convert(fl, new DevFileLocation(dstTex)); //File.Copy(Path.Combine(srcPath, texFile), dstTex, false); } } break; } } } mat.IsTransparent = opacity < 1; ambient.Alpha = opacity; diffuse.Alpha = opacity; emissive.Alpha = opacity; specular.Alpha = opacity; mat.Ambient = ambient; mat.Diffuse = diffuse; mat.Emissive = emissive; mat.Specular = specular; return(mat); }
public ItemStack(string name, Server tserver, int count, string tex, string display, string descrip, Color4F color, string model, bool bound, int datum, params KeyValuePair <string, TemplateObject>[] attrs) : this(name, null, tserver, count, tex, display, descrip, color, model, bound, datum, attrs) { }
/// <summary> /// Loads an item from data. /// </summary> /// <param name="name">The name.</param> /// <param name="secondary_name">The secondary name, if any.</param> /// <param name="count">The count of items in this stack.</param> /// <param name="tex">The texture name.</param> /// <param name="display">The display name.</param> /// <param name="descrip">The description.</param> /// <param name="color">The color.</param> /// <param name="model">The model.</param> /// <param name="datum">The 'datum' value.</param> public void Load(string name, string secondary_name, int count, string tex, string display, string descrip, Color4F color, string model, int datum) { SetName(name); SecondaryName = secondary_name; Count = count; DisplayName = display; Description = descrip; SetModelName(model); Datum = datum; SetTextureName(tex); DrawColor = color; }
/// <summary> /// Sets the color of the next rendered objects. /// </summary> /// <param name="c">The color.</param> public void SetColor(Color4F c) { SetColor(new Vector4(c.R, c.G, c.B, c.A)); }
public GlowstickEntity(Color4F col, Region tregion) : base(tregion) { Color = col; }
public RenderPassRenderTargetDesc_NativeInterop(ref RenderPassRenderTargetDesc desc) { clearColor = (byte)(desc.clearColor ? 1 : 0); clearColorValue = desc.clearColorValue; }
/// <summary> /// Set the color of rendered objects. /// </summary> /// <param name="c">The color.</param> /// <param name="view">The relevant view.</param> public void SetColor(Color4F c, View3D view) { SetColor(new Vector4(c.R, c.G, c.B, c.A), view); }
public override void Setup(Material mat, ref RenderOperation op) { if (mode == RenderMode.Depth) { Matrix lightPrjTrans; Matrix.Multiply(ref op.Transformation, ref EffectParams.DepthViewProj, out lightPrjTrans); shdVtxShader.SetValue("mvp", ref lightPrjTrans); } else if (mode == RenderMode.DeferredNormal) { Matrix worldView = op.Transformation * EffectParams.CurrentCamera.ViewMatrix; Matrix mvp = worldView * EffectParams.CurrentCamera.ProjectionMatrix; nrmGenVShader.SetValue("mvp", ref mvp); nrmGenVShader.SetValue("worldView", ref worldView); if (!stateSetted) { ShaderSamplerState state = new ShaderSamplerState(); state.AddressU = TextureAddressMode.Wrap; state.AddressV = TextureAddressMode.Wrap; state.AddressW = TextureAddressMode.Wrap; state.MinFilter = TextureFilter.Linear; state.MagFilter = TextureFilter.Linear; state.MipFilter = TextureFilter.Linear; state.MaxAnisotropy = 8; state.MipMapLODBias = 0; nrmGenPShader.SetSamplerState("texDif", ref state); ResourceHandle<Texture> clrTex = mat.GetTexture(0); if (clrTex != null) { nrmGenPShader.SetTexture("texDif", clrTex); } } } else { Matrix mvp = op.Transformation * EffectParams.CurrentCamera.ViewMatrix * EffectParams.CurrentCamera.ProjectionMatrix; vtxShader.SetValue("mvp", ref mvp); vtxShader.SetValue("world", ref op.Transformation); Matrix lightPrjTrans; Matrix.Multiply(ref op.Transformation, ref EffectParams.DepthViewProj, out lightPrjTrans); vtxShader.SetValue("smTrans", lightPrjTrans); City sender = op.Sender as City; pixShader.SetValue("k_a", mat.Ambient); if (sender != null && sender.IsCaptured) { Color4F color = new Color4F(sender.Owner.SideColor); pixShader.SetValue("k_d", color); } else { pixShader.SetValue("k_d", mat.Diffuse); } if (!stateSetted) { ShaderSamplerState state = new ShaderSamplerState(); state.AddressU = TextureAddressMode.Wrap; state.AddressV = TextureAddressMode.Wrap; state.AddressW = TextureAddressMode.Wrap; state.MinFilter = TextureFilter.Anisotropic; state.MagFilter = TextureFilter.Anisotropic; state.MipFilter = TextureFilter.Linear; state.MaxAnisotropy = 8; state.MipMapLODBias = 0; pixShader.SetSamplerState("texDif", ref state); ResourceHandle<Texture> clrTex = mat.GetTexture(0); if (clrTex != null) { pixShader.SetTexture("texDif", clrTex); } stateSetted = true; } } }
public override void Setup(Material mat, ref RenderOperation op) { if (mode == RenderMode.Depth) { Matrix lightPrjTrans; Matrix.Multiply(ref op.Transformation, ref EffectParams.DepthViewProj, out lightPrjTrans); shdVtxShader.SetValue("mvp", ref lightPrjTrans); } else if (mode == RenderMode.DeferredNormal) { Matrix worldView = op.Transformation * EffectParams.CurrentCamera.ViewMatrix; Matrix mvp = worldView * EffectParams.CurrentCamera.ProjectionMatrix; nrmGenVShader.SetValue("mvp", ref mvp); nrmGenVShader.SetValue("worldView", ref worldView); if (!stateSetted) { ShaderSamplerState state = new ShaderSamplerState(); state.AddressU = TextureAddressMode.Wrap; state.AddressV = TextureAddressMode.Wrap; state.AddressW = TextureAddressMode.Wrap; state.MinFilter = TextureFilter.Linear; state.MagFilter = TextureFilter.Linear; state.MipFilter = TextureFilter.Linear; state.MaxAnisotropy = 8; state.MipMapLODBias = 0; nrmGenPShader.SetSamplerState("texDif", ref state); ResourceHandle <Texture> clrTex = mat.GetTexture(0); if (clrTex != null) { nrmGenPShader.SetTexture("texDif", clrTex); } } } else { Matrix mvp = op.Transformation * EffectParams.CurrentCamera.ViewMatrix * EffectParams.CurrentCamera.ProjectionMatrix; vtxShader.SetValue("mvp", ref mvp); vtxShader.SetValue("world", ref op.Transformation); Matrix lightPrjTrans; Matrix.Multiply(ref op.Transformation, ref EffectParams.DepthViewProj, out lightPrjTrans); vtxShader.SetValue("smTrans", lightPrjTrans); City sender = op.Sender as City; pixShader.SetValue("k_a", mat.Ambient); if (sender != null && sender.IsCaptured) { Color4F color = new Color4F(sender.Owner.SideColor); pixShader.SetValue("k_d", color); } else { pixShader.SetValue("k_d", mat.Diffuse); } if (!stateSetted) { ShaderSamplerState state = new ShaderSamplerState(); state.AddressU = TextureAddressMode.Wrap; state.AddressV = TextureAddressMode.Wrap; state.AddressW = TextureAddressMode.Wrap; state.MinFilter = TextureFilter.Anisotropic; state.MagFilter = TextureFilter.Anisotropic; state.MipFilter = TextureFilter.Linear; state.MaxAnisotropy = 8; state.MipMapLODBias = 0; pixShader.SetSamplerState("texDif", ref state); ResourceHandle <Texture> clrTex = mat.GetTexture(0); if (clrTex != null) { pixShader.SetTexture("texDif", clrTex); } stateSetted = true; } } }
public static string ToColorString(this Color4F c) { return((c.R) + "," + (c.G) + "," + (c.B) + "," + (c.A)); }
/// <summary> /// Adapt a color effect for rendering. /// TODO: Does this logic belong in FreneticGameEngine? /// </summary> /// <param name="vt">The coordinate.</param> /// <param name="tcol">The base 't-color' value.</param> /// <returns>The resultant color.</returns> public Vector4 AdaptColor(Vector3 vt, Color4F tcol) { return(AdaptColor(vt.ToOpenTK3D(), tcol)); }
public static ItemStack FromString(Server tserver, string input) { int brack = input.IndexOf('['); string name = input.Substring(0, brack); string contents = input.Substring(brack + 1, input.Length - (brack + 1)); List <KeyValuePair <string, string> > pairs = SplitUpPairs(contents); string secname = ""; int count = 1; string tex = ""; string display = ""; string descrip = ""; string model = ""; string components = ""; bool bound = false; string shared = ""; string local = ""; double weight = 1; double volume = 1; int datum = 0; double temperature = 0; Color4F color = Color4F.White; bool renderComp = true; Location renderCompOffs = Location.Zero; foreach (KeyValuePair <string, string> pair in pairs) { string tkey = UnescapeTagBase.Unescape(pair.Key); string tval = UnescapeTagBase.Unescape(pair.Value); switch (tkey) { case "secondary": secname = tval; break; case "display": display = tval; break; case "count": count = Utilities.StringToInt(tval); break; case "description": descrip = tval; break; case "texture": tex = tval; break; case "model": model = tval; break; case "bound": bound = tval == "true"; break; case "drawcolor": color = Colors.ColorForText(tval); break; case "datum": datum = IntDatumFor(tval); break; case "weight": weight = Utilities.StringToFloat(tval); break; case "volume": volume = Utilities.StringToFloat(tval); break; case "temperature": temperature = Utilities.StringToFloat(tval); break; case "shared": shared = tval; break; case "local": local = tval; break; case "components": components = tval; break; case "renderascomponent": renderComp = tval.ToLowerFast() == "true"; break; case "componentrenderoffset": renderCompOffs = Location.FromString(tval); break; default: break; // Ignore errors as much as possible here. // TODO: Maybe actually just error? } } ItemStack item = new ItemStack(name, secname, tserver, count, tex, display, descrip, color, model, bound, datum) { Weight = weight, Volume = volume, Temperature = temperature }; pairs = SplitUpPairs(shared.Substring(1, shared.Length - 2)); foreach (KeyValuePair <string, string> pair in pairs) { string dat = UnescapeTagBase.Unescape(pair.Value); string type = dat.Substring(0, 4); string content = dat.Substring(5); TemplateObject togive = TOFor(tserver, type, content); item.SharedAttributes.Add(UnescapeTagBase.Unescape(pair.Key), togive); } pairs = SplitUpPairs(local.Substring(1, local.Length - 2)); foreach (KeyValuePair <string, string> pair in pairs) { string dat = UnescapeTagBase.Unescape(pair.Value); string type = dat.Substring(0, 4); string content = dat.Substring(5); TemplateObject togive = TOFor(tserver, type, content); item.Attributes.Add(UnescapeTagBase.Unescape(pair.Key), togive); } string[] npairs = components.Substring(1, local.Length - 2).SplitFast(';', 2); foreach (string pair in npairs) { string dat = UnescapeTagBase.Unescape(pair); if (dat.Length > 0) { item.Components.Add(FromString(tserver, dat)); } } item.RenderAsComponent = renderComp; item.ComponentRenderOffset = renderCompOffs; return(item); }
Material ParseMaterial(XmlReader xml) { Material res = new Material(null); int depth = xml.Depth; float opacity = 1; Color4F diffuse = new Color4F(); Color4F ambient = new Color4F(); Color4F specular = new Color4F(); Color4F emissive = new Color4F(); while (xml.Read() && xml.Depth > depth) { if (xml.IsStartElement() && !xml.IsEmptyElement) { switch (xml.Name) { case "Diffuse": diffuse = ParseColor3(xml.ReadString()); break; case "Ambient": ambient = ParseColor3(xml.ReadString()); break; case "Specular": specular = ParseColor3(xml.ReadString()); break; case "Emissive": emissive = ParseColor3(xml.ReadString()); break; case "Opacity": opacity = float.Parse(xml.ReadString()) / 100f; break; case "Power": res.Power = float.Parse(xml.ReadString()); break; case "DiffuseMap": res.SetTextureFile(0, xml.ReadString()); break; } } } res.Diffuse = new Color4F(opacity, diffuse.Red, diffuse.Green, diffuse.Blue); res.Ambient = new Color4F(opacity, ambient.Red, ambient.Green, ambient.Blue); res.Specular = new Color4F(opacity, specular.Red, specular.Green, specular.Blue); res.Emissive = new Color4F(opacity, emissive.Red, emissive.Green, emissive.Blue); return res; }
void TestFontRender() { var arialData = provider.loadFont ("fonts/arial.ttf"); var fontCache = new vectorx.font.FontCache (arialData); var str = "abcdefghjiklmnopqrstuvwxyz"; var font = fontCache.createFontWithNameAndSize ("Arial", 16); var color = new Color4F (1.0f, 0.0f, 0.0f, 1.0f); var attrs = MainCs._createStringAttributes (new vectorx.font.AttributedRange(0, -1), font, color); var attrString = new vectorx.font.AttributedString (str, attrs); var colorStorage = new vectorx.ColorStorage (512, 512, null); var context = new vectorx.font.FontContext (); var layout = context.calculateTextLayout (attrString, colorStorage.selectedRect, null, null); context.renderStringToColorStorage (layout, colorStorage, false); var texture = createTexture (colorStorage); GetComponent<Renderer> ().material.mainTexture = texture; System.Console.Write (""); }