Skip to content

Commit

Permalink
Merge pull request #902 from unoplatform/dev/jela/jiterpreter
Browse files Browse the repository at this point in the history
chore: Adjust raytracer performance
  • Loading branch information
jeromelaban authored Oct 24, 2024
2 parents daf3274 + 2a9e663 commit 33cab56
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/Uno.Wasm.Sample.RayTracer.Shared/Benchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ struct Vec3
{
public Num X, Y, Z;

public static readonly Vec3 Zero = new Vec3();

public Vec3(Num x, Num y, Num z)
{
X = x;
Expand Down Expand Up @@ -115,6 +113,12 @@ public static Vec3 Normalize(Vec3 v)
}
}

static class Vec3Const
{
// Required for AOT with https://github.com/dotnet/runtime/issues/109170
public static readonly Vec3 Zero = new Vec3();
}

struct Ray
{
public Vec3 Org;
Expand Down Expand Up @@ -226,7 +230,7 @@ private static Vec3 trace (Ray ray, Scene scene, int depth)
}
}

if (obj == null) return Vec3.Zero;
if (obj == null) return Vec3Const.Zero;

var point_of_hit = ray.Org + (ray.Dir * nearest);
var normal = Sphere.Normal(obj, point_of_hit);
Expand All @@ -238,7 +242,7 @@ private static Vec3 trace (Ray ray, Scene scene, int depth)
normal = -normal;
}

Vec3 color = Vec3.Zero;
Vec3 color = Vec3Const.Zero;
var reflection_ratio = obj.Reflection;

foreach(var l in scene.Lights)
Expand Down Expand Up @@ -309,7 +313,7 @@ private static Vec3 trace (Ray ray, Scene scene, int depth)

public static byte[] Render(Scene scene, byte[] pixels)
{
var eye = Vec3.Zero;
var eye = Vec3Const.Zero;
Num h = (Num)Math.Tan(((fov / 360) * (2 * PI)) / 2) * 2;
Num w = h * Width / Height;

Expand Down

0 comments on commit 33cab56

Please sign in to comment.