Skip to content
This repository has been archived by the owner on Oct 3, 2022. It is now read-only.

Commit

Permalink
Add crappy new PRNG based on xorwow
Browse files Browse the repository at this point in the history
Distributed ray casting
  • Loading branch information
jonathonracz committed Jan 21, 2018
1 parent e07b258 commit 3d2bf7d
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 129 deletions.
20 changes: 8 additions & 12 deletions jtracer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@
2834A69E1FFD54BC00267954 /* JTMetalRender.metal in Sources */ = {isa = PBXBuildFile; fileRef = 2834A69D1FFD54BC00267954 /* JTMetalRender.metal */; };
287BF7F61FEA38BC001BB98A /* Metal.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 287BF7F41FEA38BC001BB98A /* Metal.framework */; };
28B1742E1FEA381C003AD1DC /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 28B1742D1FEA381C003AD1DC /* AppDelegate.m */; };
28B174311FEA381C003AD1DC /* ViewController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 28B174301FEA381C003AD1DC /* ViewController.mm */; };
28B174311FEA381C003AD1DC /* JTRenderViewController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 28B174301FEA381C003AD1DC /* JTRenderViewController.mm */; };
28B174331FEA381C003AD1DC /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 28B174321FEA381C003AD1DC /* Assets.xcassets */; };
28B174361FEA381C003AD1DC /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 28B174341FEA381C003AD1DC /* Main.storyboard */; };
28B174391FEA381D003AD1DC /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 28B174381FEA381D003AD1DC /* main.m */; };
28B174441FEA381D003AD1DC /* jtracerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 28B174431FEA381D003AD1DC /* jtracerTests.m */; };
28C648811FFF1E3D00454706 /* Random.mm in Sources */ = {isa = PBXBuildFile; fileRef = 28C648801FFF1E3D00454706 /* Random.mm */; };
28D27E1020082FB0003D055E /* JTDisplayLink.m in Sources */ = {isa = PBXBuildFile; fileRef = 28D27E0F20082FB0003D055E /* JTDisplayLink.m */; };
28D27E1620092F6E003D055E /* JTRenderState.mm in Sources */ = {isa = PBXBuildFile; fileRef = 28D27E1520092F6E003D055E /* JTRenderState.mm */; };
28D27E1920095ACD003D055E /* JTRenderer.mm in Sources */ = {isa = PBXBuildFile; fileRef = 28D27E1820095ACD003D055E /* JTRenderer.mm */; };
Expand Down Expand Up @@ -49,8 +48,8 @@
28B174291FEA381C003AD1DC /* jtracer.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = jtracer.app; sourceTree = BUILT_PRODUCTS_DIR; };
28B1742C1FEA381C003AD1DC /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
28B1742D1FEA381C003AD1DC /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
28B1742F1FEA381C003AD1DC /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = "<group>"; };
28B174301FEA381C003AD1DC /* ViewController.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ViewController.mm; sourceTree = "<group>"; };
28B1742F1FEA381C003AD1DC /* JTRenderViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JTRenderViewController.h; sourceTree = "<group>"; };
28B174301FEA381C003AD1DC /* JTRenderViewController.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = JTRenderViewController.mm; sourceTree = "<group>"; };
28B174321FEA381C003AD1DC /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
28B174351FEA381C003AD1DC /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
28B174371FEA381D003AD1DC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand All @@ -59,8 +58,7 @@
28B1743F1FEA381D003AD1DC /* jtracerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = jtracerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
28B174431FEA381D003AD1DC /* jtracerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = jtracerTests.m; sourceTree = "<group>"; };
28B174451FEA381D003AD1DC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
28C6487F1FFF1A8100454706 /* JTNumerics.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.h; path = JTNumerics.h; sourceTree = "<group>"; };
28C648801FFF1E3D00454706 /* Random.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = Random.mm; sourceTree = "<group>"; };
28C6487F1FFF1A8100454706 /* JTRandom.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.h; path = JTRandom.h; sourceTree = "<group>"; };
28C648821FFF247700454706 /* JTTypes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JTTypes.h; sourceTree = "<group>"; };
28D27E0D200829AF003D055E /* JTBRDF.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JTBRDF.h; sourceTree = "<group>"; };
28D27E0E20082FB0003D055E /* JTDisplayLink.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JTDisplayLink.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -145,8 +143,8 @@
28D27E1520092F6E003D055E /* JTRenderState.mm */,
28B174381FEA381D003AD1DC /* main.m */,
28B174341FEA381C003AD1DC /* Main.storyboard */,
28B1742F1FEA381C003AD1DC /* ViewController.h */,
28B174301FEA381C003AD1DC /* ViewController.mm */,
28B1742F1FEA381C003AD1DC /* JTRenderViewController.h */,
28B174301FEA381C003AD1DC /* JTRenderViewController.mm */,
);
path = jtracer;
sourceTree = "<group>";
Expand All @@ -156,7 +154,6 @@
children = (
28B174431FEA381D003AD1DC /* jtracerTests.m */,
28B174451FEA381D003AD1DC /* Info.plist */,
28C648801FFF1E3D00454706 /* Random.mm */,
);
path = jtracerTests;
sourceTree = "<group>";
Expand All @@ -166,7 +163,7 @@
children = (
2823DD252000070E00BE7F9A /* JTBindPoints.h */,
2834A69F1FFD57EF00267954 /* JTShaderTypes.h */,
28C6487F1FFF1A8100454706 /* JTNumerics.h */,
28C6487F1FFF1A8100454706 /* JTRandom.h */,
28C648821FFF247700454706 /* JTTypes.h */,
28D27E0D200829AF003D055E /* JTBRDF.h */,
28D27E1D200AD081003D055E /* JTTrace.h */,
Expand Down Expand Up @@ -281,7 +278,7 @@
buildActionMask = 2147483647;
files = (
2834A6981FFD382800267954 /* JTMetalRender.mm in Sources */,
28B174311FEA381C003AD1DC /* ViewController.mm in Sources */,
28B174311FEA381C003AD1DC /* JTRenderViewController.mm in Sources */,
2834A69E1FFD54BC00267954 /* JTMetalRender.metal in Sources */,
28D27E1020082FB0003D055E /* JTDisplayLink.m in Sources */,
28D27E1920095ACD003D055E /* JTRenderer.mm in Sources */,
Expand All @@ -296,7 +293,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
28C648811FFF1E3D00454706 /* Random.mm in Sources */,
28B174441FEA381D003AD1DC /* jtracerTests.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
4 changes: 2 additions & 2 deletions jtracer/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -736,10 +736,10 @@
</objects>
<point key="canvasLocation" x="773" y="793"/>
</scene>
<!--View Controller-->
<!--Render View Controller-->
<scene sceneID="hIz-AP-VOD">
<objects>
<viewController id="XfG-lQ-9wD" customClass="ViewController" sceneMemberID="viewController">
<viewController id="XfG-lQ-9wD" customClass="JTRenderViewController" sceneMemberID="viewController">
<view key="view" id="m2S-Jp-Qdl">
<rect key="frame" x="0.0" y="0.0" width="480" height="270"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
Expand Down
2 changes: 1 addition & 1 deletion jtracer/External/OpenSimplexCPP
1 change: 0 additions & 1 deletion jtracer/JTMetalRender.metal
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ using namespace metal;

#include "Trace/JTShaderTypes.h"
#include "Trace/JTBindPoints.h"
#include "Trace/JTNumerics.h"

#include "Trace/JTTrace.h"

Expand Down
4 changes: 2 additions & 2 deletions jtracer/ViewController.h → jtracer/JTRenderViewController.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// ViewController.h
// JTRenderViewController.h
// jtracer
//
// Created by Jonathon Racz on 12/20/17.
Expand All @@ -8,6 +8,6 @@

#import <Cocoa/Cocoa.h>

@interface ViewController : NSViewController
@interface JTRenderViewController : NSViewController

@end
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
//
// ViewController.m
// JTRenderViewController.mm
// jtracer
//
// Created by Jonathon Racz on 12/20/17.
// Copyright © 2017 jonathonracz. All rights reserved.
//

#import "ViewController.h"
#import "JTRenderViewController.h"
#import "JTDisplayLink.h"
#import "JTMetalRender.h"
#import "JTCGRender.h"
#import "JTRenderState.h"

@interface ViewController () {
@interface JTRenderViewController () {
JTRenderState *_renderState;
JTDisplayLink *_displayLink;
JTMetalRender *_metalView;
Expand All @@ -24,7 +24,7 @@ @interface ViewController () {

@end

@implementation ViewController
@implementation JTRenderViewController

- (void)viewDidLoad {
[super viewDidLoad];
Expand Down
48 changes: 0 additions & 48 deletions jtracer/Trace/JTNumerics.h

This file was deleted.

54 changes: 54 additions & 0 deletions jtracer/Trace/JTRandom.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// JTRandom.h
// jtracer
//
// Created by Jonathon Racz on 1/4/18.
// Copyright © 2018 jonathonracz. All rights reserved.
//

#pragma once

#include <simd/simd.h>
#include "JTTypes.h"
#include "JTShaderTypes.h"

namespace jt
{

class PRNG
{
public:
PRNG()
{
}

~PRNG() = default;

uint32 generate()
{
uint32 t = (x ^ (x >> 2));
x = y;
y = z;
z = w;
w = v;
v = (v ^ (v << 4)) ^ (t ^ (t << 1));
return (d += 362437) + v;
}

float generateNormal()
{
// TODO: in a distributed raytracing situation, this should be
// 0 <= x < 1, but currently it's 0 <= x <= 1.
return generate() / static_cast<float>(JT_UINT32_MAX);
}

private:
uint32 x = 123456789;
uint32 y = 362436069;
uint32 z = 521288629;
uint32 w = 88675123;
uint32 v = 5783321;
uint32 d = 6615241;
};

};
10 changes: 6 additions & 4 deletions jtracer/Trace/JTTrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "JTRay.h"
#include "JTSphere.h"
#include "JTCamera.h"
#include "JTNumerics.h"
#include "JTRandom.h"
#include "JTBackgroundGradient.h"

namespace jt
Expand All @@ -24,7 +24,9 @@ namespace Trace

float4 runTrace(JT_CONSTANT const Uniforms& uniforms, uint2 pos, uint2 dimensions)
{
PRNG random = PRNG(OpenSimplex::Noise::noise2(uniforms.context, pos.x, pos.y));
//float noiseValue = OpenSimplex::Noise::noise2(uniforms.context, pos.x, pos.y);
//uint32 noiseValueInt = reinterpret_cast<JT_THREAD uint32&>(noiseValue);
PRNG random;

// Create a sphere world.
Camera camera;
Expand All @@ -36,8 +38,8 @@ float4 runTrace(JT_CONSTANT const Uniforms& uniforms, uint2 pos, uint2 dimension
float3 color = make_float3(0.0f, 0.0f, 0.0f);
size_t samplesPerPixel = 128;
for (size_t i = 0; i < samplesPerPixel; ++i) {
float u = (pos.x) / static_cast<float>(dimensions.x);
float v = (pos.y) / static_cast<float>(dimensions.y);
float u = (pos.x + (random.generateNormal() - 0.5f)) / static_cast<float>(dimensions.x);
float v = (pos.y + (random.generateNormal() - 0.5f)) / static_cast<float>(dimensions.y);
Ray mainRay = camera.makeRay(u, v);
if (world.hitTest(mainRay, hitRecord))
color += 0.5f * (hitRecord.normal + 1);
Expand Down
3 changes: 3 additions & 0 deletions jtracer/Trace/JTTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#include <iostream>
#endif

#define JT_UINT32_MAX 0xffffffffUL
#define JT_UINT64_MAX 0xffffffffffffffffULL

#include <simd/simd.h>
using namespace simd;

Expand Down
55 changes: 0 additions & 55 deletions jtracerTests/Random.mm

This file was deleted.

0 comments on commit 3d2bf7d

Please sign in to comment.