Skip to content

Commit

Permalink
extended vis features
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrit committed Jul 19, 2024
1 parent a7f2a79 commit f265bd7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
2 changes: 2 additions & 0 deletions SeeSharp/Geometry/BoundingBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,6 @@ public bool IsInside(Vector3 point)
/// Surface area of the box
/// </summary>
public float SurfaceArea => 2 * (Diagonal.X * (Diagonal.Y + Diagonal.Z) + Diagonal.Y * Diagonal.Z);

public float Volume => Diagonal.X * Diagonal.Y * Diagonal.Z;
}
25 changes: 25 additions & 0 deletions SeeSharp/Geometry/MeshFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,31 @@ public static Mesh MakeCylinder(Vector3 from, Vector3 to, float radius, int numS
return result;
}

public static Mesh MakeAABB(BoundingBox boundingBox) {
Vector3 x = new(boundingBox.Diagonal.X, 0, 0);
Vector3 y = new(0, boundingBox.Diagonal.Y, 0);
Vector3 z = new(0, 0, boundingBox.Diagonal.Z);
Vector3[] vertices = [
boundingBox.Min,
boundingBox.Min + x,
boundingBox.Min + x + y,
boundingBox.Min + y,
boundingBox.Min + z,
boundingBox.Min + z + x,
boundingBox.Min + z + x + y,
boundingBox.Min + z + y,
];
int[] indices = [
0, 1, 2, 0, 2, 3, // front
4, 6, 5, 4, 7, 6, // back
4, 0, 3, 4, 3, 7, // left
1, 5, 2, 5, 6, 2, // right
3, 2, 6, 3, 6, 7, // top
0, 5, 1, 0, 4, 5, // bottom
];
return new(vertices, indices);
}

/// <summary>
/// Creates a triangulated sphere around a point.
/// </summary>
Expand Down
6 changes: 3 additions & 3 deletions SeeSharp/Integrators/DebugVisualizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ public override void Render(Scene scene) {
/// The shading value at a primary hit point. The default implementation uses "eye light shading",
/// i.e., the cosine between the outgoing direction and the normal.
/// </summary>
public virtual RgbColor ComputeColor(SurfacePoint hit, Vector3 from) {
public virtual RgbColor ComputeColor(SurfacePoint hit, Vector3 from, uint row, uint col) {
float cosine = Math.Abs(Vector3.Dot(hit.Normal, from));
cosine /= hit.Normal.Length();
cosine /= from.Length();
return RgbColor.White * cosine;
}

private void RenderPixel(Scene scene, uint row, uint col, uint sampleIndex) {
public virtual void RenderPixel(Scene scene, uint row, uint col, uint sampleIndex) {
// Seed the random number generator
uint pixelIndex = row * (uint)scene.FrameBuffer.Width + col;
var rng = new RNG(BaseSeed, pixelIndex, sampleIndex);
Expand All @@ -54,7 +54,7 @@ private void RenderPixel(Scene scene, uint row, uint col, uint sampleIndex) {

// Shade and splat
RgbColor value = RgbColor.Black;
if (hit) value = ComputeColor(hit, -primaryRay.Direction);
if (hit) value = ComputeColor(hit, -primaryRay.Direction, row, col);
scene.FrameBuffer.Splat((int)col, (int)row, value);
}
}
4 changes: 2 additions & 2 deletions SeeSharp/Integrators/Util/PathVisualizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ public override void Render(Scene scene) {

/// <returns>A grayscale color for scene geometry or the color of the intersected path marker</returns>
/// <inheritdoc />
public override RgbColor ComputeColor(SurfacePoint hit, Vector3 from) {
public override RgbColor ComputeColor(SurfacePoint hit, Vector3 from, uint row, uint col) {
int type;
if (!markerTypes.TryGetValue(hit.Mesh, out type))
return base.ComputeColor(hit, from);
return base.ComputeColor(hit, from, row, col);

RgbColor color = new RgbColor(1, 0, 0);
TypeToColor?.TryGetValue(type, out color);
Expand Down

0 comments on commit f265bd7

Please sign in to comment.