static Vector3 Ray_color(Ray r, Vector3 background, HitTable world, int depth) { Hit_Record rec = default; // If we've exceeded the ray bounce limit, no more light is gathered. if (depth <= 0) { return(Vector3.Zero); } // If the ray hits nothing, return the background color. if (!world.Hit(r, 0.001f, Helpers.Infinity, ref rec)) { return(background); } Ray scattered; Vector3 attenuation; Vector3 emitted = rec.Mat_ptr.Emitted(rec.U, rec.V, rec.P); if (!rec.Mat_ptr.Scatter(r, rec, out attenuation, out scattered)) { return(emitted); } return(emitted + attenuation * Ray_color(scattered, background, world, depth - 1)); }
static Vector3 Ray_color(Ray r, HitTable world, int depth) { Hit_Record rec = default; // If we've exceeded the ray bounce limit, no more light is gathered. if (depth <= 0) { return(Vector3.Zero); } if (world.Hit(r, 0.001f, Helpers.Infinity, ref rec)) { Ray scattered; Vector3 attenuation; if (rec.Mat_ptr.Scatter(r, rec, out attenuation, out scattered)) { return(attenuation * Ray_color(scattered, world, depth - 1)); } return(Vector3.Zero); } Vector3 unit_direction = Vector3.Normalize(r.Direction); var t = 0.5f * (unit_direction.Y + 1.0f); return((1.0f - t) * new Vector3(1.0f, 1.0f, 1.0f) + t * new Vector3(0.5f, 0.7f, 1.0f)); }
public BVH_Node(List <HitTable> objects, uint start, uint end, float time0, float time1) { int axis = Helpers.random.Next(0, 2); IComparer <HitTable> comparator; if (axis == 0) { comparator = new XComparator(); } else if (axis == 1) { comparator = new YComparator(); } else { comparator = new ZComparator(); } uint object_span = end - start; if (object_span == 1) { left = right = objects[(int)start]; } else if (object_span == 2) { if (comparator.Compare(objects[(int)start], objects[(int)start + 1]) <= 0) { left = objects[(int)start]; right = objects[(int)start + 1]; } else { left = objects[(int)start + 1]; right = objects[(int)start]; } } else { objects.Sort((int)start, (int)(end - start), comparator); var mid = start + object_span / 2; left = new BVH_Node(objects, start, mid, time0, time1); right = new BVH_Node(objects, mid, end, time0, time1); } AABB box_left = null; AABB box_right = null; if (!left.Bounding_box(time0, time1, out box_left) || !right.Bounding_box(time0, time1, out box_right) ) { Console.WriteLine("No bounding box in bvh_node constructor."); } box = Helpers.Surrounding_box(box_left, box_right); }
private void CalculateHitTables() { if (/*TODO Something to notice that we need to recalculate attack table*/ true) { actor.Stats.MainHand.Table = HitTable.GenerateMainHandTable(actor.Stats, target); if (actor.Stats.OffHand != null) { actor.Stats.OffHand.Table = HitTable.GenerateOffHandTable(actor.Stats, target); } } }
public static bool Box_compare(HitTable a, HitTable b, int axis) { AABB box_a = null; AABB box_b = null; if (!a.Bounding_box(0, 0, out box_a) || !b.Bounding_box(0, 0, out box_b)) { Console.WriteLine("No bounding box in bvh_node constructor."); } return(Helpers.Vector3GetValue(box_a.min, axis) < Helpers.Vector3GetValue(box_b.min, axis)); }
public Swing Activate(Stats stats, Target target) { var swing = new Swing { Outcome = HitTable.Roll(stats.MainHand.Table), Damage = 600 + (15 * stats.Resource) }; stats.Resource = 0; swing.Damage = Damage.ReduceArmor(swing.Damage, stats, target); return(swing); }
static Vector3 Ray_color(Ray r, HitTable world) { Hit_Record rec = default; if (world.Hit(r, 0, Helpers.Infinity, ref rec)) { return(0.5f * (rec.Normal + Vector3.One)); } Vector3 unit_direction = Vector3.Normalize(r.Direction); var t = 0.5f * (unit_direction.Y + 1.0f); return((1.0f - t) * new Vector3(1.0f, 1.0f, 1.0f) + t * new Vector3(0.5f, 0.7f, 1.0f)); }
public bool SetBreakpoint(IntPtr address) { if (BreakpointTable.ContainsKey(address)) { return(false); } var buffer = mem.ReadBytes(address, 0x1); BreakpointTable.Add(address, buffer[0]); HitTable.Add(address, 0); mem.Write(address, new byte[] { 0xCC }); return(true); }
static Vector3 Ray_color(Ray r, HitTable world, int depth) { Hit_Record rec = default; // If we've exceeded the ray bounce limit, no more light is gathered. if (depth <= 0) { return(Vector3.Zero); } if (world.Hit(r, 0.001f, Helpers.Infinity, ref rec)) { Vector3 target = rec.P + Helpers.Random_in_hemisphere(rec.Normal); return(0.5f * Ray_color(new Ray(rec.P, target - rec.P), world, depth - 1)); } Vector3 unit_direction = Vector3.Normalize(r.Direction); var t = 0.5f * (unit_direction.Y + 1.0f); return((1.0f - t) * new Vector3(1.0f, 1.0f, 1.0f) + t * new Vector3(0.5f, 0.7f, 1.0f)); }
public Rotate_y(HitTable p, float angle) { this.ptr = p; var radians = Helpers.Degress_to_radians(angle); sin_theta = (float)Math.Sin(radians); cos_theta = (float)Math.Cos(radians); hasbox = ptr.Bounding_box(0, 1, out bbox); Vector3 min = new Vector3(Helpers.Infinity, Helpers.Infinity, Helpers.Infinity); Vector3 max = new Vector3(-Helpers.Infinity, -Helpers.Infinity, -Helpers.Infinity); for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { var x = i * bbox.max.X + (1 - i) * bbox.min.X; var y = j * bbox.max.Y + (1 - j) * bbox.min.Y; var z = k * bbox.max.Z + (1 - k) * bbox.min.Z; var newx = cos_theta * x + sin_theta * z; var newz = -sin_theta * x + cos_theta * z; Vector3 tester = new Vector3(newx, y, newz); for (int c = 0; c < 3; c++) { Helpers.Vector3SetValue(ref min, c, (float)Math.Min(Helpers.Vector3GetValue(min, c), Helpers.Vector3GetValue(tester, c))); Helpers.Vector3SetValue(ref max, c, (float)Math.Max(Helpers.Vector3GetValue(max, c), Helpers.Vector3GetValue(tester, c))); } } } } bbox = new AABB(min, max); }
public void Add(HitTable o) { this.Objects.Add(o); }
public Hitable_List(HitTable hitTable) : this() { this.Objects.Add(hitTable); }
public Translate(HitTable p, Vector3 displacement) { this.ptr = p; this.offset = displacement; }
public Constant_medium(HitTable b, float d, Texture a) { this.boundary = b; this.neg_inv_density = -1 / d; this.phase_function = new Isotropic(a); }
public Flip_face(HitTable p) { this.ptr = p; }
public static bool Box_z_compare(HitTable a, HitTable b) { return(Box_compare(a, b, 2)); }
internal Outcome Swing() { this.Cooldown = this.Speed; return(HitTable.Roll(this.Table)); }