public DirectionalLight(Vector3 direction, RealColor colour, WorldBounds bounds, float _power) { this.Direction = direction; this.color = colour.Copy(); this.bounds = bounds; power = _power; }
public DiffuseLight(Vertex[] triangle, RealColor color, float power) { a = triangle[0]; b = triangle[1]; c = triangle[2]; this.color = color.Copy(); this.power = power; Normal = RadiosityHelper.ComputeTriangleNormal(a, b, c); Center = Vector3.BaryCentric(a.position, b.position, c.position, 0.333333f, 0.333333f); }
public void SetColor(RealColor color, bool use_alpha) { Clear(); if (use_alpha) { Add(color.R, color.G, color.B, color.A); } else { Add(color.R, color.G, color.B); } }
protected override void RegisterVariables(VariableRegistry local) { //hack to not have to reference wpf stuff to get the Media.Color :( var black = new RealColor(); black.SetDrawingColor(Color.Black); var white = new RealColor(); white.SetDrawingColor(Color.White); local.Register($"{DeviceName}_color", black, "Default Color", white, black); local.Register($"{DeviceName}_override", false, "Override DLL"); local.Register($"{DeviceName}_dlltype", DLLType.LGS, "DLL Type"); }
/// <summary> /// Constructs a point light. /// </summary> /// <param name="position"></param> /// <param name="colour"></param> /// <param name="power"></param> public RadiosityLight(Vector3 position, RealColor colour, float power) { this.m_randomNumberGen = new Random(); this.m_position = position; this.m_colour = colour; this.m_power = power; // Create DX3D version: this.m_light = new Light(); this.m_light.Type = LightType.Point; this.m_light.Diffuse = System.Drawing.Color.FromArgb((int)(m_colour[0] * 255), (int)(m_colour[1] * 255), (int)(m_colour[2] * 255)); this.m_light.Position = this.m_position; this.m_light.Attenuation0 = this.m_power; }
public static RealColor ComputeLightingEstimate(CompressedPhoton[] photons, RadiosityMaterial material, Vector3 surfaceNormal) { RealColor estimate = RealColor.Black.Copy(); for (int p = 0; p < photons.Length; p++) { float dotP = (surfaceNormal != Vector3.Empty) ? Vector3.Dot(surfaceNormal, photons[p].Direction) : 0.5f; if (dotP < 0) { continue; } estimate.Add(photons[p].Power.Copy().Multiply(dotP)); } estimate.Multiply((float)RadiosityHelper.RadiosityDiffuseConstant); estimate.Multiply(material.AmbientLight); return(estimate); }
public object UpdateLights(VariableRegistry settings, IGameState state = null) { EffectLayer layer = new EffectLayer(this.ID); RealColor FG = settings.GetVariable <RealColor>("foregroundColour"); RealColor BG = settings.GetVariable <RealColor>("backgroundColour"); if (!this.threadRunning) { this.threadRunning = true; ThreadPool.QueueUserWorkItem(this.Battery); } if (this.batteryStatus.isCharging == true) { FG = settings.GetVariable <RealColor>("chargingColour"); BG = settings.GetVariable <RealColor>("chargingBGColour"); } layer.PercentEffect(FG.GetDrawingColor(), BG.GetDrawingColor(), settings.GetVariable <KeySequence>("keys") ?? DefaultKeys, this.batteryStatus.percentage, 100D, PercentEffectType.Progressive_Gradual); return(layer); }
/// <summary> /// Constructs a diffuse light. /// </summary> /// <param name="direction"></param> /// <param name="colour"></param> public RadiosityLight(Vector3 direction, RealColor colour, WorldBounds bounds, int pointCount) { this.m_randomNumberGen = new Random(); this.m_direction = direction; this.m_colour = colour.Copy(); // Create DX3D version: this.m_light = new Light(); this.m_light.Type = LightType.Directional; /*this.m_light.Diffuse = Color.FromArgb((int)(m_colour[0] * 255), * (int)(m_colour[1] * 255), * (int)(m_colour[2] * 255));*/ this.m_light.Direction = this.m_direction; this.bounds = bounds; this.pointCount = pointCount; width = bounds.X.Upper - bounds.X.Lower; height = bounds.Y.Upper - bounds.Y.Lower; }
/// <summary> /// Constructs a spot light. /// </summary> /// <param name="position"></param> /// <param name="direction"></param> /// <param name="colour"></param> /// <param name="power"></param> public RadiosityLight(Vector3 position, Vector3 direction, RealColor colour, float power) { this.m_randomNumberGen = new Random(); this.m_position = position; this.m_direction = direction; m_colour = colour.Copy(); //this.m_colour = colour; this.m_power = power; // Create DX version. this.m_light = new Light(); this.m_light.Type = LightType.Spot; this.m_light.Diffuse = System.Drawing.Color.FromArgb((int)m_colour[0], (int)m_colour[1], (int)m_colour[2]); this.m_light.Position = m_position; this.m_light.Direction = m_direction; this.m_light.Range = 1.0f; this.m_light.InnerConeAngle = 0.5f; this.m_light.OuterConeAngle = 1.0f; this.m_light.Falloff = 1.0f; this.m_light.Attenuation0 = m_power; }
public ColladaColor(RealColor color, float alpha_override) : this() { SetColor(color, alpha_override); }
public ColladaColor(RealColor color, bool use_alpha) : this() { SetColor(color, use_alpha); }
private void CreateRender() { int screenWidth = MdxRender.Device.Viewport.Width; int screenHeight = MdxRender.Device.Viewport.Height; float dist2 = RadiosityHelper.GatherDistance * RadiosityHelper.GatherDistance; Bitmap renderBitm;// = new Bitmap(screenWidth, screenHeight); float[,,] hdr = new float[screenWidth, screenHeight, 3]; ChangeStage(RadiosityStage.TextureGeneration, screenWidth * screenHeight); SetOperation("Rendering..."); int tenPercent = screenWidth / 10; int left = screenWidth / 2 - tenPercent; int right = screenWidth / 2 + tenPercent; for (int y = 0; y < screenHeight; y++) { for (int x = 0; x < screenWidth; x++) { Vector3 direction, origin; MdxRender.CalculatePickRayWorld(x, y, out direction, out origin); //AddDebugRay(origin, direction); RadiosityIntersection intersect = m_bsp[0].RadiosityIntersect(origin, direction); //AddDebugPoint(intersect.Position); if (!intersect.NoIntersection) { Vector3 normal = m_bsp[0].GetFaceNormal(intersect.LightmapIndex, intersect.MaterialIndex, intersect.FaceIndex); List <CompressedPhoton> photons = photonMap.RetrieveNearestNeighbors((PhotonVector3)intersect.Position, dist2, 10000); RealColor sum = RealColor.Black.Copy();//new RealColor(photons.Count, photons.Count, photons.Count); if (photons.Count == 0) { System.Diagnostics.Debugger.Break(); } foreach (CompressedPhoton phot in photons) { float dotP = Vector3.Dot(-phot.Direction, normal); if (dotP < 0) { dotP = 0; } sum.Add(phot.Power.Copy().Multiply(dotP)); } if ((sum.G > sum.B) && (sum.G > sum.R)) { if (x >= left) { if (x <= right) { if (photons.Count > 100) { AddDebugRay(origin, direction); AddDebugPoint(origin); foreach (var photon in photons) { AddDebugPoint(photon.position.ToVector3()); } } } } //System.Diagnostics.Debugger.Break(); } //sum.Multiply(1 / (dist2 * (float)Math.PI)); //sum.Multiply(intersect.Material.AmbientLight); for (int c = 0; c < 3; c++) { hdr[x, y, c] = sum[c]; } } else { hdr[x, y, 0] = 0; hdr[x, y, 1] = 0; hdr[x, y, 2] = 0; } IncrementProgress(); } } //renderBitm = LinearTonemap(hdr); Bitmap tempBitmap = new Bitmap(screenWidth, screenHeight); //Graphics g = Graphics.FromImage(tempBitmap); //g.DrawImage(renderBitm, 0, 0); //g.Dispose(); //renderBitm.Dispose(); tempBitmap.Save(@"C:\Users\David\render.bmp"); return; }
/// <summary> /// Creates a photon, usually created by a light source. /// </summary> /// <param name="position">Position of photon.</param> /// <param name="direction">Initial direction of photon.</param> /// <param name="color">Colour of photon</param> public Photon(Vector3 position, Vector3 direction, RealColor color) { this.m_position = position; this.m_direction = direction; this.m_colour = color.Copy(); }
public CompressedPhoton() { Power = RealColor.Black.Copy(); position = new PhotonVector3(0f, 0f, 0f); }
private void CreateLightmap(float dist2, Vector3 badPoint, string path, int texIndex, float hemisphereSizeDivisor, TextureMap texMap, ref float maxIntensity) { int gatherCount = 100; int width = (int)(texMap.Width); // * RadiosityHelper.LightmapScale); int height = (int)(texMap.Height); // * RadiosityHelper.LightmapScale); float heightF = (float)texMap.Height; // *RadiosityHelper.LightmapScale; float widthF = (float)texMap.Width; // *RadiosityHelper.LightmapScale; float currentMaxIntensity = float.MinValue; float diffuse = (float)RadiosityHelper.RadiosityDiffuseConstant; widthF -= 1f; heightF -= 1f; SetOperation("Creating texture #" + (texIndex + 1)); //List<CompressedPhoton> photons; Bitmap bitm = new Bitmap(width, height, PixelFormat.Format32bppRgb); RadiosityMaterial mat; Vector3 norm; for (int x = 0; x < width; x++) { for (int y = 0; y < heightF; y++) { bitm.SetPixel(x, y, m_bsp[0].ConvertUVTo3D(x, y, texIndex, 1, out mat, out norm) != Vector3.Empty ? new RealColor(1, 1, 1).ToARGB() : RealColor.Black.ToARGB()); } } bitm.Save("k:\\convmap_" + texIndex + "_" + 1); //CreateLightmapWork(dist2, ref badPoint, texIndex, hemisphereSizeDivisor, texMap, width, height, heightF, widthF, ref currentMaxIntensity); // We are going to cycle through the materials of the bsp. EnhancedMesh[] meshes = m_bsp[0].GetMeshes(texIndex); for (int m = 0; m < meshes.Length; m++) { EnhancedMesh material = meshes[m]; int faceCount = material.Indices.Length; RectangleBounds <float> bounds = new RectangleBounds <float>(material.Vertices[0].u2, material.Vertices[0].v2); // First we're going to figure out a rectangle for this material. for (int v = 0; v < material.Vertices.Length; v++) { bounds.Update(material.Vertices[v].u2, material.Vertices[v].v2); } int x = (int)Math.Floor((widthF * bounds.left)); int startX = x; int endX = (int)Math.Ceiling(widthF * bounds.right); int y = (int)Math.Floor(heightF * bounds.top); int endY = (int)Math.Ceiling(heightF * bounds.bottom); //System.Diagnostics.Debugger.Break(); for (; y <= endY; y++) { x = startX; for (; x <= endX; x++) { RadiosityMaterial illMaterial; Vector3 faceNormal; //if (y == 81) // // if (x == 2) //System.Diagnostics.Debugger.Break(); Vector3 worldPoint = m_bsp[0].ConvertUVTo3D(x, y, texIndex, m, out illMaterial, out faceNormal); //AddDebugRay(worldPoint, faceNormal); if (worldPoint != Vector3.Empty) { AddDebugPoint(worldPoint, RadiosityDebugPointListID.EstimateLocations); var photons = photonMap.RetrieveNearestNeighbors((PhotonVector3)worldPoint, dist2, gatherCount, faceNormal); RealColor estimate = RealColor.Black; if (photons.Count > 0) { for (int p = 0; p < photons.Count; p++) { if (photons.list[p].photonPtr == null) { continue; } float dotP = Vector3.Dot(photons.list[p].photonPtr.Direction, faceNormal); if (dotP < 0) { dotP *= -1; //AddDebugPoint(photons.list[p].photonPtr //AddDebugRay(photons.list[p].photonPtr.position.ToVector3(), photons.list[p].photonPtr.Direction); } estimate.Add(photons.list[p].photonPtr.Power.Copy().Multiply(dotP)); } estimate.Multiply(diffuse); estimate.Multiply(hemisphereSizeDivisor); estimate.Multiply(illMaterial.AmbientLight); //estimate.Multiply(1f / photons.Count); if (RadiosityHelper.DoDistantLights) { if (illMaterial.DistantLightCount > 1) { estimate.LambertianShade(faceNormal, illMaterial.DistantLight2Color, illMaterial.DistantLight2Direction, illMaterial.AmbientLight); estimate.LambertianShade(faceNormal, illMaterial.DistantLight1Color, illMaterial.DistantLight1Direction, illMaterial.AmbientLight); } else if (illMaterial.DistantLightCount > 0) { estimate.LambertianShade(faceNormal, illMaterial.DistantLight1Color, illMaterial.DistantLight1Direction, illMaterial.AmbientLight); } } texMap.SetPixel(x, y, estimate); } else { texMap.SetPixel(x, y, new RealColor(Color.Pink)); } } //else continue; // if there is no normal, the estimate is useless. } } } if (currentMaxIntensity > maxIntensity) { maxIntensity = currentMaxIntensity; } texMap.SaveHDR(path + "lightmap_" + texIndex + ".hdr"); bitm = texMap.Filter(new LinearToneMapper(), false); bitm.Save(path + "lightmap_" + texIndex + ".bmp"); }
public void SetColor(RealColor color, float alpha_override) { Clear(); Add(color.R, color.G, color.B, alpha_override); }
private struct HDRSample { public RealColor AVG; public int Count; public HDRSample(RealColor avg, int count) { AVG = avg; Count = count; }