public override V3 GetNormal(V3 intersection = null) { V3 normal = Normal; if (!HasBump()) { normal.Normalize(); return(normal); } V3 AB = PointB - PointA; V3 AC = PointC - PointA; V3 AI = intersection - PointA; float u = ((AC ^ Normal) * AI) / (AB ^ AC).Norm(); float v = ((Normal ^ AB) * AI) / (AC ^ AB).Norm(); BumpTexture.Bump(u, v, out float dhdu, out float dhdv); V3 T2 = AB ^ (dhdv * normal); V3 T3 = (dhdu * normal) ^ AC; V3 normalBump = normal + (BumpIntensity * (T2 + T3)); normalBump.Normalize(); return(normalBump); }
/// <summary> /// Calcul la normale a partir d une intersection /// A partir de cette intersection on va calculer u et v /// </summary> /// <param name="intersection">L intersection</param> /// <returns>La normal par rapport a l intersection</returns> public override V3 GetNormal(V3 intersection = null) { Tools.InvertCoordSpherique(FindSpherePoint(intersection), Radius, out float u, out float v); V3 normal = GetNormal(u, v); if (!HasBump()) { normal.Normalize(); return(normal); } float uTexture = u / Tools.TAU; float vTexture = -(v + Tools.PI2) / (Tools.PI2 + Tools.PI2); BumpTexture.Bump(uTexture, vTexture, out float dhdu, out float dhdv); V3 T2 = FindPointDerU(u, v) ^ (dhdv * normal); V3 T3 = (dhdu * normal) ^ FindPointDerV(u, v); V3 normalBump = normal + (BumpIntensity * (T2 + T3)); normalBump.Normalize(); return(normalBump); }
public bool Use() { var prg = GetShaderProgram(); if (lastUserProgram == null) { lastUserProgram = ShaderProgram.Current; } ShaderProgram.SwitchResult res = prg.Use(); //prg.SetUniform("MaterialIndex", BufferOffset); prg.SetUniform("IsTessellatedTerrain", Type == MaterialType.TessellatedTerrain); prg.SetUniform("TessellationMultiplier", TessellationMultiplier); prg.SetUniform("InvertUVy", InvertUVy); prg.SetUniform("IsBillboard", IsBillboard); prg.SetUniform("SpecularColor", SpecularColor); prg.SetUniform("DiffuseColor", DiffuseColor); prg.SetUniform("ParallaxHeightMultiplier", ParallaxHeightMultiplier); prg.SetUniform("Roughness", Roughness); prg.SetUniform("Alpha", Alpha); prg.SetUniform("NormalTexEnabled", NormalsTexture != null); prg.SetUniform("BumpTexEnabled", BumpTexture != null); prg.SetUniform("AlphaTexEnabled", AlphaTexture != null); prg.SetUniform("RoughnessTexEnabled", RoughnessTexture != null); prg.SetUniform("DiffuseTexEnabled", DiffuseTexture != null); prg.SetUniform("SpecularTexEnabled", SpecularTexture != null); if (NormalsTexture != null) { NormalsTexture.Use(prg.getConstInt("normalsTexBind")); } if (BumpTexture != null) { BumpTexture.Use(prg.getConstInt("bumpTexBind")); } if (AlphaTexture != null) { AlphaTexture.Use(prg.getConstInt("alphaTexBind")); } if (RoughnessTexture != null) { RoughnessTexture.Use(prg.getConstInt("roughnessTexBind")); } if (DiffuseTexture != null) { DiffuseTexture.Use(prg.getConstInt("diffuseTexBind")); } if (SpecularTexture != null) { SpecularTexture.Use(prg.getConstInt("specularTexBind")); } return(true); }