public Intersection(IPrimitive hitPrimitive, Point3D hitPoint, Vector3D normal, float tMin, float tMax, bool hitFromInSide) { this.HitPoint = hitPoint; this.Normal = normal; this.TMin = tMin; this.TMax = tMax; this.HitPrimitive = hitPrimitive; this.HitFromInSide = hitFromInSide; this.CurrentTextureCoordinate = UVCoordinate.Zero; }
public override void Deserialize(Stream input) { this.Version = input.ReadValueU32(); this.Name = input.ReadStringAlignedU8(); this.BillboardMode = new FourCC(input); this.Rotation = new Vector4(input); this.Colour = input.ReadValueU32(); this.Uv0 = new UVCoordinate(input); this.Uv1 = new UVCoordinate(input); this.Uv2 = new UVCoordinate(input); this.Uv3 = new UVCoordinate(input); this.Width = input.ReadValueF32(); this.Height = input.ReadValueF32(); this.Distance = input.ReadValueF32(); this.UVOffset = new UVCoordinate(input); }
public static Vector3D BumpNormal(Texture bumpTexture, Intersection intersection) { const float scale = 1; UVCoordinate uv = intersection.CurrentTextureCoordinate; float dx = 1.0f / (bumpTexture.Width - 1); float dy = 1.0f / (bumpTexture.Height - 1); float b0 = bumpTexture.GetPixel(uv).Luminance; float bx = bumpTexture.GetPixel(uv.U + dx, uv.V).Luminance; float by = bumpTexture.GetPixel(uv.U, uv.V + dy).Luminance; return((intersection.Normal + new Vector3D(scale * (bx - b0) / dx, scale * (by - b0) / dy, 1)).Normalized); //RGBColor color = bumpTexture.GetPixel(uv); //Vector3D tangent1, tangent2; //Vector3D.Orthonormalize(intersection.Normal, out tangent1, out tangent2); }
public override bool TryCalculateIntersection(Ray ray, out Intersection intersection) { intersection = new Intersection(); Vector3 rayToSphere = ray.Origin - this.Position; float B = Vector3.Dot(rayToSphere, ray.Direction); float C = Vector3.Dot(rayToSphere, rayToSphere) - (Radius * Radius); float D = B * B - C; if (D > 0) { var distance = -B - (float)Math.Sqrt(D); var hitPosition = ray.Origin + (ray.Direction * new Vector3(distance)); var normal = hitPosition - this.Position; UVCoordinate uv = this.GetUVCoordinate(hitPosition); intersection = new Intersection(hitPosition, normal, ray.Direction, this, Material.GetDiffuseColorAtCoordinates(uv), distance); return(true); } else { return(false); } }
/// <summary> /// Returns the specular color of a material at the given UV coordinates. /// </summary> public Color GetSpecularColorAtCoordinates(UVCoordinate uv) { return(GetSpecularColorAtCoordinates(uv.U, uv.V)); }
/// <summary> /// Returns the specular color of a material at the given UV coordinates. /// </summary> public Color GetDiffuseColorAtCoordinates(UVCoordinate uv) { return(GetDiffuseColorAtCoordinates(uv.U, uv.V)); }
//public static implicit operator Texture(Bitmap texture) //{ // return new Texture(texture); //} //public void ProcessTextureImage(Bitmap texture) //{ // textureMatrix = new RGBColor[texture.Width, texture.Height]; // for (int i = 0; i < texture.Width; i++) // { // for (int j = 0; j < texture.Height; j++) // { // textureMatrix[i, j] = RGBColor.FromColor(texture.GetPixel(i, j)); // } // } // texture.Dispose(); //} public RGBColor GetPixel(UVCoordinate uv) { return(this.textureMatrix[(int)(uv.U * this.Width), (int)(uv.V * this.Height)]); }
/// <summary> /// Returns the specular color of a material at the given UV coordinates. /// </summary> public Color GetSpecularColorAtCoordinates(UVCoordinate uv) { return GetSpecularColorAtCoordinates(uv.U, uv.V); }
/// <summary> /// Returns the specular color of a material at the given UV coordinates. /// </summary> public Color GetDiffuseColorAtCoordinates(UVCoordinate uv) { return GetDiffuseColorAtCoordinates(uv.U, uv.V); }