diff --git a/Source/OptiX/Private/OptiXLaserActor.cpp b/Source/OptiX/Private/OptiXLaserActor.cpp index 7eb77f066fb152ca9f59a638cf1e0059849f9398..da87c3e34d62d94fc90b287f1ef5e6a79ffc8761 100644 --- a/Source/OptiX/Private/OptiXLaserActor.cpp +++ b/Source/OptiX/Private/OptiXLaserActor.cpp @@ -124,6 +124,11 @@ void AOptiXLaserActor::InitInstancedMeshData() LineTransform.SetRotation(Rot); + if (LineTransform.ContainsNaN()) + { + UE_LOG(LogTemp, Fatal, TEXT("Line Transform contains NaNs!")); + } + InstancedStaticMeshComponent->AddInstanceWorldSpace(LineTransform); Count++; } @@ -248,6 +253,11 @@ void AOptiXLaserActor::DisplayLines() bIsDirty = false; } + if (LineTransform.ContainsNaN()) + { + UE_LOG(LogTemp, Fatal, TEXT("Line Transform contains NaNs!")); + } + //UE_LOG(LogTemp, Display, TEXT("# Instances: %i"), InstancedStaticMeshComponent->GetInstanceCount()); InstancedStaticMeshComponent->UpdateInstanceTransform(TransformIndex, LineTransform, true, bIsDirty, true); diff --git a/Source/OptiX/Private/OptiXLaserComponent.cpp b/Source/OptiX/Private/OptiXLaserComponent.cpp index a080f1df005968eedaa45e4ffee353f18ef34c55..2418285073cdf1da9534adc115cc705f86ae00c9 100644 --- a/Source/OptiX/Private/OptiXLaserComponent.cpp +++ b/Source/OptiX/Private/OptiXLaserComponent.cpp @@ -17,6 +17,8 @@ UOptiXLaserComponent::UOptiXLaserComponent() LaserMaxDepth = 20; LaserEntryPoint = 1; // Default, will be overwritten anyway + LaserBufferSize = LaserMaxDepth * 50 * 50 * 2; + RayTIR = false; TargetBufferWrite = 0; //todo @@ -27,6 +29,9 @@ UOptiXLaserComponent::UOptiXLaserComponent() LaserTracesPerFrame = 300; RayCount = 0; + IntersectionData.AddZeroed(LaserBufferSize); + + // Find and load default patterns: static ConstructorHelpers::FObjectFinder<UTexture2D> CrossTexture(TEXT("Texture2D'/OptiX/Cross.Cross'")); @@ -176,7 +181,7 @@ void UOptiXLaserComponent::Init() OptiXContext->SetBuffer("laserIndex", LaserIndexBuffer); OptiXContext->SetBuffer("laserDir", LaserDirectionBuffer); - LaserOutputBuffer = OptiXContext->CreateBuffer(RT_BUFFER_OUTPUT, RT_FORMAT_FLOAT4, LaserMaxDepth * 50 * 50 * 2); + LaserOutputBuffer = OptiXContext->CreateBuffer(RT_BUFFER_OUTPUT, RT_FORMAT_FLOAT4, LaserBufferSize); OptiXContext->SetBuffer("result_laser", LaserOutputBuffer); SetRayTIR(RayTIR); @@ -190,9 +195,6 @@ void UOptiXLaserComponent::Init() SetLaserPattern(CurrentLaserPattern); - IntersectionData.AddUninitialized(LaserOutputBuffer->GetSize1D()); - - UpdateLaserPosition(); } diff --git a/Source/OptiX/Private/OptiXLensActor.cpp b/Source/OptiX/Private/OptiXLensActor.cpp new file mode 100644 index 0000000000000000000000000000000000000000..01fb6d7e7a5d096345f5e5c013a4b813bea0b006 --- /dev/null +++ b/Source/OptiX/Private/OptiXLensActor.cpp @@ -0,0 +1,31 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#include "OptiXLensActor.h" + +#include "UObject/ConstructorHelpers.h" +#include "Runtime/Engine/Classes/Components/StaticMeshComponent.h" +#include "Runtime/Engine/Classes/Engine/StaticMesh.h" + +AOptiXLensActor::AOptiXLensActor(const FObjectInitializer& ObjectInitializer) + : Super(ObjectInitializer) +{ + UE_LOG(LogTemp, Display, TEXT("OptiX Target Actor Constructor")); + + PrimaryActorTick.bCanEverTick = false; + + //static ConstructorHelpers::FObjectFinder<UStaticMesh>MeshAsset(TEXT("StaticMesh'/OptiX/target.target'")); + //UStaticMesh* Asset = MeshAsset.Object; + + //GetStaticMeshComponent()->SetStaticMesh(Asset); + //SetActorEnableCollision(false); + + OptiXLensComponent = CreateDefaultSubobject<UOptiXLensComponent>(TEXT("LensComponent")); + OptiXLensComponent->SetupAttachment(RootComponent); + + OptiXLensComponent->SetRelativeLocationAndRotation({0, 0, OptiXLensComponent->GetLensRadius()}, FRotationMatrix::MakeFromZ({ 1, 0, 0 }).ToQuat()); + + GetStaticMeshComponent()->SetCollisionEnabled(ECollisionEnabled::NoCollision); + //RootComponent = OptiXTargetComponent; + //SM->SetupAttachment(OptiXTargetComponent); +} + diff --git a/Source/OptiX/Private/OptiXLensComponent.cpp b/Source/OptiX/Private/OptiXLensComponent.cpp index 18a34b2aaea8bb0bb19b1a71cd6e1dfa3c48dfa9..35e3610d37e96c7095ffcd7b4a0c451ffae8bf3b 100644 --- a/Source/OptiX/Private/OptiXLensComponent.cpp +++ b/Source/OptiX/Private/OptiXLensComponent.cpp @@ -5,13 +5,13 @@ UOptiXLensComponent::UOptiXLensComponent(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) { - Radius1 = 0.8 * 10; // todo default values - Radius2 = 1.0 * 10; - LensRadius = 0.1 * 10; + Radius1 = 0.8 * 100; // todo default values + Radius2 = 1.0 * 100; + LensRadius = 0.1 * 100; LensType1 = ELensSideType::CONVEX; LensType2 = ELensSideType::CONVEX; - LensThickness = 0.025 * 10; + LensThickness = 0.025 * 100; CurrentWavelength = 450.0f; } diff --git a/Source/OptiX/Private/OptiXTargetActor.cpp b/Source/OptiX/Private/OptiXTargetActor.cpp new file mode 100644 index 0000000000000000000000000000000000000000..abc8794b5cda35997e52754c9837481ba39d0db7 --- /dev/null +++ b/Source/OptiX/Private/OptiXTargetActor.cpp @@ -0,0 +1,30 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#include "OptiXTargetActor.h" + +#include "UObject/ConstructorHelpers.h" +#include "Runtime/Engine/Classes/Components/StaticMeshComponent.h" +#include "Runtime/Engine/Classes/Engine/StaticMesh.h" + +AOptiXTargetActor::AOptiXTargetActor(const FObjectInitializer& ObjectInitializer) + : Super(ObjectInitializer) +{ + UE_LOG(LogTemp, Display, TEXT("OptiX Target Actor Constructor")); + + PrimaryActorTick.bCanEverTick = false; + + //static ConstructorHelpers::FObjectFinder<UStaticMesh>MeshAsset(TEXT("StaticMesh'/OptiX/target.target'")); + //UStaticMesh* Asset = MeshAsset.Object; + + //GetStaticMeshComponent()->SetStaticMesh(Asset); + //SetActorEnableCollision(false); + + OptiXTargetComponent = CreateDefaultSubobject<UOptiXTargetComponent>(TEXT("TargetComponent")); + OptiXTargetComponent->SetupAttachment(RootComponent); + OptiXTargetComponent->SetRelativeLocation({ 0, 0, OptiXTargetComponent->TargetSize.Z / 2}); + + GetStaticMeshComponent()->SetCollisionEnabled(ECollisionEnabled::NoCollision); + //RootComponent = OptiXTargetComponent; + //SM->SetupAttachment(OptiXTargetComponent); +} + diff --git a/Source/OptiX/Private/OptiXTargetComponent.cpp b/Source/OptiX/Private/OptiXTargetComponent.cpp index a0c7139c94bde1f6e21377f88efb1cee4d42ec87..a58660412585010aa52b89859cd3a2cd32988538 100644 --- a/Source/OptiX/Private/OptiXTargetComponent.cpp +++ b/Source/OptiX/Private/OptiXTargetComponent.cpp @@ -2,6 +2,14 @@ #include "OptiXTargetComponent.h" +UOptiXTargetComponent::UOptiXTargetComponent(const FObjectInitializer& ObjectInitializer) + : Super(ObjectInitializer) +{ + Texture = LoadObject<UTexture2D>(this, TEXT("Texture2D'/OptiX/Checker.Checker'")); + TextureSize = FIntPoint(Texture->GetSizeX(), Texture->GetSizeY()); + TargetSize = FVector(2.0f, 20.0f, 20.0f * static_cast<float>(TextureSize.Y) / static_cast<float>(TextureSize.X)); +} + void UOptiXTargetComponent::UpdateOptiXComponent() { if (OptiXGeometry != nullptr && OptiXTransform != nullptr && OptiXAcceleration != nullptr) @@ -52,16 +60,8 @@ void UOptiXTargetComponent::InitOptiXMaterial() void UOptiXTargetComponent::InitOptiXGroups() { OptiXGeometryInstance = OptiXContext->CreateGeometryInstance(OptiXGeometry, OptiXMaterial); - - // Load Texture from file: - - UTexture2D* Texture = LoadObject<UTexture2D>(this, TEXT("Texture2D'/OptiX/Checker.Checker'")); - - // Size is the same for all 6 - int32 X = Texture->GetSizeX(); - int32 Y = Texture->GetSizeY(); - - OptiXGeometryInstance->SetFloat3D("size", 2.0f, 2.0f * static_cast<float>(Y) / static_cast<float>(X), 0.02f); // Why? TODO + + SetSize(TargetSize); UOptiXTextureSampler* Sampler = OptiXContext->CreateTextureSampler(); //Sampler->AddToRoot(); @@ -76,9 +76,9 @@ void UOptiXTargetComponent::InitOptiXGroups() - UE_LOG(LogTemp, Display, TEXT("Texture with Size: (%i, %i)"), X, Y); + UE_LOG(LogTemp, Display, TEXT("Texture with Size: (%i, %i)"), TextureSize.X, TextureSize.Y); - UOptiXBuffer* Buffer = OptiXContext->CreateBufferUByte2D(RT_BUFFER_INPUT, X, Y); + UOptiXBuffer* Buffer = OptiXContext->CreateBufferUByte2D(RT_BUFFER_INPUT, TextureSize.X, TextureSize.Y); optix::uchar4* BufferData = static_cast<optix::uchar4*>(Buffer->MapNative()); @@ -87,11 +87,11 @@ void UOptiXTargetComponent::InitOptiXGroups() FColor* TextureData = static_cast<FColor*>(Mip.BulkData.Lock(LOCK_READ_WRITE)); // Texture index conversion is a real pain... - for (int32 i = 0; i < X; ++i) { - for (int32 j = 0; j < Y; ++j) { + for (int32 i = 0; i < TextureSize.X; ++i) { + for (int32 j = 0; j < TextureSize.Y; ++j) { - int32 TextureIndex = (X * Y - 1) - i * X - j; - int32 BufferIndex = ((j)*(X)+i); + int32 TextureIndex = (TextureSize.X * TextureSize.Y - 1) - i * TextureSize.X - j; + int32 BufferIndex = ((j)*(TextureSize.X)+i); //UE_LOG(LogTemp, Display, TEXT("Values: %i"), TextureData[BufferIndex]); @@ -160,4 +160,15 @@ void UOptiXTargetComponent::CleanOptiXComponent() Super::CleanOptiXComponent(); OptiXGeometryGroup = nullptr; -} \ No newline at end of file +} + +void UOptiXTargetComponent::SetSize(FVector NewSize) +{ + OptiXGeometryInstance->SetFloat3DVector("size", NewSize); + TargetSize = NewSize; +} + +FVector UOptiXTargetComponent::GetSize() +{ + return TargetSize; +} diff --git a/Source/OptiX/Private/cuda/already generated - optical bench/laser_caster.cu b/Source/OptiX/Private/cuda/already generated - optical bench/laser_caster.cu index befa342fa7616b27cf0d81150e4581a7dd56f8c0..5b0e06eaa8d1be9f4e3e269717209b7f40bc76d7 100644 --- a/Source/OptiX/Private/cuda/already generated - optical bench/laser_caster.cu +++ b/Source/OptiX/Private/cuda/already generated - optical bench/laser_caster.cu @@ -47,6 +47,7 @@ rtDeclareVariable(float3, laser_up, , ); rtDeclareVariable(Matrix4x4, laser_rot, , ); rtDeclareVariable(float, laserBeamWidth, , ); +rtDeclareVariable(float, laserSize, , ); rtBuffer<int, 2> laserIndex; rtBuffer<float3, 2> laserDir; @@ -54,7 +55,7 @@ rtBuffer<float4, 1> result_laser; RT_PROGRAM void laser_caster(){ - const float laserSize = 0.04; + float2 d = make_float2(launch_index.x, launch_index.y) / make_float2(launch_dim.x, launch_dim.y) - make_float2(0.5f, 0.5f); float3 ray_origin = laser_origin + laser_right * laserSize * d.x + laser_up * laserSize * d.y; diff --git a/Source/OptiX/Private/cuda/already generated - optical bench/laser_target.cu b/Source/OptiX/Private/cuda/already generated - optical bench/laser_target.cu index f72efc28edb4867d10ff21456c530cb45b6dde9e..324156314b7bbf79e98e11c8782917846b2f5e3c 100644 --- a/Source/OptiX/Private/cuda/already generated - optical bench/laser_target.cu +++ b/Source/OptiX/Private/cuda/already generated - optical bench/laser_target.cu @@ -40,36 +40,41 @@ rtDeclareVariable(int, writeable_surface, attribute writeable_surface, ); RT_PROGRAM void intersect(int primIdx) { //Hit Z? - float t_1 = (p1.z - ray.origin.z) * (1.0f / ray.direction.z); - float2 rel_size_z = (make_float2(ray.origin + ray.direction * t_1) - (make_float2(p1) - stretchXY1/2))/stretchXY1; + float t_1 = (p1.x - ray.origin.x) * (1.0f / ray.direction.x); + float3 hp = ray.origin + ray.direction * t_1; + float2 rel_size_z = (make_float2(hp.y, hp.z) - (make_float2(p1.y, p1.z) - stretchXY1/2))/stretchXY1; bool hit_z = rel_size_z.x < 1 && rel_size_z.y < 1 && rel_size_z.x >= 0 && rel_size_z.y >= 0; - //Hit X? - float t_2 = (p2.x - ray.origin.x) * (1.0f / ray.direction.x); - float3 hp = ray.origin + ray.direction * t_2; - float2 rel_size_x = (make_float2(hp.z, hp.y) - (make_float2(p2.z, p2.y) - stretchXZ2/2))/stretchXZ2; - bool hit_x = rel_size_x.x < 1 && rel_size_x.y < 1 && rel_size_x.x >= 0 && rel_size_x.y >= 0; + //Hit X? - ignore this for now + //float t_2 = (p2.x - ray.origin.x) * (1.0f / ray.direction.x); + //float3 hp = ray.origin + ray.direction * t_2; + //float2 rel_size_x = (make_float2(hp.z, hp.y) - (make_float2(p2.z, p2.y) - stretchXZ2/2))/stretchXZ2; + //bool hit_x = rel_size_x.x < 1 && rel_size_x.y < 1 && rel_size_x.x >= 0 && rel_size_x.y >= 0; //Which one is closer - float tmin = fminf(t_1 + (!hit_z > 0)*0x7f800000 , t_2 + (!hit_x > 0)*100000); //0x7f800000 == +INFINITY - float2 rel_size = (tmin == t_1) * rel_size_z + (tmin == t_2) * rel_size_x; - if((hit_x || hit_z) && rtPotentialIntersection(tmin)) { - texture_coord = rel_size; - writeable_surface = tmin == t_1; + //float tmin = fminf(t_1 + (!hit_z > 0)*0x7f800000 , t_2 + (!hit_x > 0)*100000); //0x7f800000 == +INFINITY + //float2 rel_size = (tmin == t_1) * rel_size_z + (tmin == t_2) * rel_size_x; + if((hit_z) && rtPotentialIntersection(t_1)) { + texture_coord = make_float2(1 - rel_size_z.x, 1 - rel_size_z.y); + writeable_surface = 1; // don't need this as well rtReportIntersection(0); } } RT_PROGRAM void bounds (int, optix::Aabb* aabb) { - float min_x = fminf(p1.x - stretchXY1.x/2, p2.x); - float min_y = fminf(p1.y - stretchXY1.y/2, p2.y - stretchXZ2.y/2); - float min_z = fminf(p1.z, p2.z - stretchXZ2.x/2); - - float max_x = fmaxf(p1.x + stretchXY1.x/2, p2.x); - float max_y = fmaxf(p1.y + stretchXY1.y/2, p2.y + stretchXZ2.y/2); - float max_z = fmaxf(p1.z, p2.z + stretchXZ2.x/2); - aabb->m_min = make_float3(min_x,min_y,min_z); - aabb->m_max = make_float3(max_x,max_y,max_z); + // Make this a plane with x == 0 + + //float min_x = fminf(p1.x - stretchXY1.x/2, p2.x); + //float min_y = fminf(p1.y, p2.y - stretchXY1.x / 2); + //float min_z = fminf(p1.z - stretchXY1.y / 2, p2.z - stretchXZ2.y / 2); + //// + //float max_x = fmaxf(p1.x + stretchXY1.x/2, p2.x); + //float max_y = fmaxf(p1.y, p2.y - stretchXY1.y / 2); + //float max_z = fmaxf(p1.z - stretchXY1.y / 2, p2.z - stretchXZ2.y / 2); + + + aabb->m_min = make_float3(-0.01, p1.y - stretchXY1.x / 2, p1.z - stretchXY1.y / 2); + aabb->m_max = make_float3(0.01, p1.y + stretchXY1.x / 2, p1.z + stretchXY1.y / 2); } diff --git a/Source/OptiX/Private/cuda/laser_target_material.cu b/Source/OptiX/Private/cuda/already generated - optical bench/laser_target_material.cu similarity index 100% rename from Source/OptiX/Private/cuda/laser_target_material.cu rename to Source/OptiX/Private/cuda/already generated - optical bench/laser_target_material.cu diff --git a/Source/OptiX/Private/cuda/already generated - tutorial/box.cu b/Source/OptiX/Private/cuda/already generated - tutorial/box.cu deleted file mode 100644 index 70d8fcbfb368af004f69cf7797a01b0a6ae5d501..0000000000000000000000000000000000000000 --- a/Source/OptiX/Private/cuda/already generated - tutorial/box.cu +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2018 NVIDIA CORPORATION. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of NVIDIA CORPORATION nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <optix.h> -#include <optixu/optixu_math_namespace.h> -#include <optixu/optixu_matrix_namespace.h> -#include <optixu/optixu_aabb_namespace.h> - -using namespace optix; - -rtDeclareVariable(float3, boxmin, , ); -rtDeclareVariable(float3, boxmax, , ); -rtDeclareVariable(optix::Ray, ray, rtCurrentRay, ); -rtDeclareVariable(float3, texcoord, attribute texcoord, ); -rtDeclareVariable(float3, geometric_normal, attribute geometric_normal, ); -rtDeclareVariable(float3, shading_normal, attribute shading_normal, ); - -static __device__ float3 boxnormal(float t, float3 t0, float3 t1) -{ - float3 neg = make_float3(t==t0.x?1:0, t==t0.y?1:0, t==t0.z?1:0); - float3 pos = make_float3(t==t1.x?1:0, t==t1.y?1:0, t==t1.z?1:0); - return pos-neg; -} - -RT_PROGRAM void box_intersect(int) -{ - float3 t0 = (boxmin - ray.origin)/ray.direction; - float3 t1 = (boxmax - ray.origin)/ray.direction; - float3 near = fminf(t0, t1); - float3 far = fmaxf(t0, t1); - float tmin = fmaxf( near ); - float tmax = fminf( far ); - - if(tmin <= tmax) { - bool check_second = true; - if( rtPotentialIntersection( tmin ) ) { - texcoord = make_float3( 0.0f ); - shading_normal = geometric_normal = boxnormal( tmin, t0, t1 ); - if(rtReportIntersection(0)) - check_second = false; - } - if(check_second) { - if( rtPotentialIntersection( tmax ) ) { - texcoord = make_float3( 0.0f ); - shading_normal = geometric_normal = boxnormal( tmax, t0, t1 ); - rtReportIntersection(0); - } - } - } -} - -RT_PROGRAM void box_bounds (int, float result[6]) -{ - optix::Aabb* aabb = (optix::Aabb*)result; - aabb->set(boxmin, boxmax); -} diff --git a/Source/OptiX/Private/cuda/already generated - tutorial/commonStructs.h b/Source/OptiX/Private/cuda/already generated - tutorial/commonStructs.h deleted file mode 100644 index 5c51001f9874ce10da1283a503b03bffc7aa529b..0000000000000000000000000000000000000000 --- a/Source/OptiX/Private/cuda/already generated - tutorial/commonStructs.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2018 NVIDIA CORPORATION. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of NVIDIA CORPORATION nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#pragma once - -#include <optixu/optixu_vector_types.h> - -struct BasicLight -{ -#if defined(__cplusplus) - typedef optix::float3 float3; -#endif - float3 pos; - float3 color; - int casts_shadow; - int padding; // make this structure 32 bytes -- powers of two are your friend! -}; - - diff --git a/Source/OptiX/Private/cuda/already generated - tutorial/helpers.h b/Source/OptiX/Private/cuda/already generated - tutorial/helpers.h deleted file mode 100644 index 0b12868a8131ce334fd03b84a0fe09ffe8cfa929..0000000000000000000000000000000000000000 --- a/Source/OptiX/Private/cuda/already generated - tutorial/helpers.h +++ /dev/null @@ -1,256 +0,0 @@ -/* - * Copyright (c) 2018 NVIDIA CORPORATION. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of NVIDIA CORPORATION nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#pragma once - -#include <optixu/optixu_math_namespace.h> - -// Convert a float3 in [0,1)^3 to a uchar4 in [0,255]^4 -- 4th channel is set to 255 -#ifdef __CUDACC__ -static __device__ __inline__ optix::uchar4 make_color(const optix::float3& c) -{ - return optix::make_uchar4( static_cast<unsigned char>(__saturatef(c.z)*255.99f), /* B */ - static_cast<unsigned char>(__saturatef(c.y)*255.99f), /* G */ - static_cast<unsigned char>(__saturatef(c.x)*255.99f), /* R */ - 255u); /* A */ -} -#endif - -// Sample Phong lobe relative to U, V, W frame -static -__host__ __device__ __inline__ optix::float3 sample_phong_lobe( optix::float2 sample, float exponent, - optix::float3 U, optix::float3 V, optix::float3 W ) -{ - const float power = expf( logf(sample.y)/(exponent+1.0f) ); - const float phi = sample.x * 2.0f * (float)M_PIf; - const float scale = sqrtf(1.0f - power*power); - - const float x = cosf(phi)*scale; - const float y = sinf(phi)*scale; - const float z = power; - - return x*U + y*V + z*W; -} - -// Sample Phong lobe relative to U, V, W frame -static -__host__ __device__ __inline__ optix::float3 sample_phong_lobe( const optix::float2 &sample, float exponent, - const optix::float3 &U, const optix::float3 &V, const optix::float3 &W, - float &pdf, float &bdf_val ) -{ - const float cos_theta = powf(sample.y, 1.0f/(exponent+1.0f) ); - - const float phi = sample.x * 2.0f * M_PIf; - const float sin_theta = sqrtf(1.0f - cos_theta*cos_theta); - - const float x = cosf(phi)*sin_theta; - const float y = sinf(phi)*sin_theta; - const float z = cos_theta; - - const float powered_cos = powf( cos_theta, exponent ); - pdf = (exponent+1.0f) / (2.0f*M_PIf) * powered_cos; - bdf_val = (exponent+2.0f) / (2.0f*M_PIf) * powered_cos; - - return x*U + y*V + z*W; -} - -// Get Phong lobe PDF for local frame -static -__host__ __device__ __inline__ float get_phong_lobe_pdf( float exponent, const optix::float3 &normal, const optix::float3 &dir_out, - const optix::float3 &dir_in, float &bdf_val) -{ - using namespace optix; - - float3 r = -reflect(dir_out, normal); - const float cos_theta = fabs(dot(r, dir_in)); - const float powered_cos = powf(cos_theta, exponent ); - - bdf_val = (exponent+2.0f) / (2.0f*M_PIf) * powered_cos; - return (exponent+1.0f) / (2.0f*M_PIf) * powered_cos; -} - -// Create ONB from normal. Resulting W is parallel to normal -static -__host__ __device__ __inline__ void create_onb( const optix::float3& n, optix::float3& U, optix::float3& V, optix::float3& W ) -{ - using namespace optix; - - W = normalize( n ); - U = cross( W, optix::make_float3( 0.0f, 1.0f, 0.0f ) ); - - if ( fabs( U.x ) < 0.001f && fabs( U.y ) < 0.001f && fabs( U.z ) < 0.001f ) - U = cross( W, make_float3( 1.0f, 0.0f, 0.0f ) ); - - U = normalize( U ); - V = cross( W, U ); -} - -// Create ONB from normalized vector -static -__device__ __inline__ void create_onb( const optix::float3& n, optix::float3& U, optix::float3& V) -{ - using namespace optix; - - U = cross( n, make_float3( 0.0f, 1.0f, 0.0f ) ); - - if ( dot( U, U ) < 1e-3f ) - U = cross( n, make_float3( 1.0f, 0.0f, 0.0f ) ); - - U = normalize( U ); - V = cross( n, U ); -} - -// Compute the origin ray differential for transfer -static -__host__ __device__ __inline__ optix::float3 differential_transfer_origin(optix::float3 dPdx, optix::float3 dDdx, float t, optix::float3 direction, optix::float3 normal) -{ - float dtdx = -optix::dot((dPdx + t*dDdx), normal)/optix::dot(direction, normal); - return (dPdx + t*dDdx)+dtdx*direction; -} - -// Compute the direction ray differential for a pinhole camera -static -__host__ __device__ __inline__ optix::float3 differential_generation_direction(optix::float3 d, optix::float3 basis) -{ - float dd = optix::dot(d,d); - return (dd*basis-optix::dot(d,basis)*d)/(dd*sqrtf(dd)); -} - -// Compute the direction ray differential for reflection -static -__host__ __device__ __inline__ -optix::float3 differential_reflect_direction(optix::float3 dPdx, optix::float3 dDdx, optix::float3 dNdP, - optix::float3 D, optix::float3 N) -{ - using namespace optix; - - float3 dNdx = dNdP*dPdx; - float dDNdx = dot(dDdx,N) + dot(D,dNdx); - return dDdx - 2*(dot(D,N)*dNdx + dDNdx*N); -} - -// Compute the direction ray differential for refraction -static __host__ __device__ __inline__ -optix::float3 differential_refract_direction(optix::float3 dPdx, optix::float3 dDdx, optix::float3 dNdP, - optix::float3 D, optix::float3 N, float ior, optix::float3 T) -{ - using namespace optix; - - float eta; - if(dot(D,N) > 0.f) { - eta = ior; - N = -N; - } else { - eta = 1.f / ior; - } - - float3 dNdx = dNdP*dPdx; - float mu = eta*dot(D,N)-dot(T,N); - float TN = -sqrtf(1-eta*eta*(1-dot(D,N)*dot(D,N))); - float dDNdx = dot(dDdx,N) + dot(D,dNdx); - float dmudx = (eta - (eta*eta*dot(D,N))/TN)*dDNdx; - return eta*dDdx - (mu*dNdx+dmudx*N); -} - -// Color space conversions -static __host__ __device__ __inline__ optix::float3 Yxy2XYZ( const optix::float3& Yxy ) -{ - // avoid division by zero - if( Yxy.z < 1e-4 ) - return optix::make_float3( 0.0f, 0.0f, 0.0f ); - - return optix::make_float3( Yxy.y * ( Yxy.x / Yxy.z ), - Yxy.x, - ( 1.0f - Yxy.y - Yxy.z ) * ( Yxy.x / Yxy.z ) ); -} - -static __host__ __device__ __inline__ optix::float3 XYZ2rgb( const optix::float3& xyz) -{ - const float R = optix::dot( xyz, optix::make_float3( 3.2410f, -1.5374f, -0.4986f ) ); - const float G = optix::dot( xyz, optix::make_float3( -0.9692f, 1.8760f, 0.0416f ) ); - const float B = optix::dot( xyz, optix::make_float3( 0.0556f, -0.2040f, 1.0570f ) ); - return optix::make_float3( R, G, B ); -} - -static __host__ __device__ __inline__ optix::float3 Yxy2rgb( optix::float3 Yxy ) -{ - using namespace optix; - - // avoid division by zero - if( Yxy.z < 1e-4 ) - return make_float3( 0.0f, 0.0f, 0.0f ); - - // First convert to xyz - float3 xyz = make_float3( Yxy.y * ( Yxy.x / Yxy.z ), - Yxy.x, - ( 1.0f - Yxy.y - Yxy.z ) * ( Yxy.x / Yxy.z ) ); - - const float R = dot( xyz, make_float3( 3.2410f, -1.5374f, -0.4986f ) ); - const float G = dot( xyz, make_float3( -0.9692f, 1.8760f, 0.0416f ) ); - const float B = dot( xyz, make_float3( 0.0556f, -0.2040f, 1.0570f ) ); - return make_float3( R, G, B ); -} - -static __host__ __device__ __inline__ optix::float3 rgb2Yxy( optix::float3 rgb) -{ - using namespace optix; - - // convert to xyz - const float X = dot( rgb, make_float3( 0.4124f, 0.3576f, 0.1805f ) ); - const float Y = dot( rgb, make_float3( 0.2126f, 0.7152f, 0.0722f ) ); - const float Z = dot( rgb, make_float3( 0.0193f, 0.1192f, 0.9505f ) ); - - // avoid division by zero - // here we make the simplifying assumption that X, Y, Z are positive - float denominator = X + Y + Z; - if ( denominator < 1e-4 ) - return make_float3( 0.0f, 0.0f, 0.0f ); - - // convert xyz to Yxy - return make_float3( Y, - X / ( denominator ), - Y / ( denominator ) ); -} - -static __host__ __device__ __inline__ optix::float3 tonemap( const optix::float3 &hdr_value, float Y_log_av, float Y_max) -{ - using namespace optix; - - float3 val_Yxy = rgb2Yxy( hdr_value ); - - float Y = val_Yxy.x; // Y channel is luminance - const float a = 0.04f; - float Y_rel = a * Y / Y_log_av; - float mapped_Y = Y_rel * (1.0f + Y_rel / (Y_max * Y_max)) / (1.0f + Y_rel); - - float3 mapped_Yxy = make_float3( mapped_Y, val_Yxy.y, val_Yxy.z ); - float3 mapped_rgb = Yxy2rgb( mapped_Yxy ); - - return mapped_rgb; -} - diff --git a/Source/OptiX/Private/cuda/already generated - tutorial/parallelogram.cu b/Source/OptiX/Private/cuda/already generated - tutorial/parallelogram.cu deleted file mode 100644 index 8145dbb3796c95b837dfe484c3e0b521426e955a..0000000000000000000000000000000000000000 --- a/Source/OptiX/Private/cuda/already generated - tutorial/parallelogram.cu +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2018 NVIDIA CORPORATION. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of NVIDIA CORPORATION nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <optix_world.h> - -using namespace optix; - -rtDeclareVariable(float4, plane, , ); -rtDeclareVariable(float3, v1, , ); -rtDeclareVariable(float3, v2, , ); -rtDeclareVariable(float3, anchor, , ); -rtDeclareVariable(int, lgt_instance, , ) = {0}; - -rtDeclareVariable(float3, texcoord, attribute texcoord, ); -rtDeclareVariable(float3, geometric_normal, attribute geometric_normal, ); -rtDeclareVariable(float3, shading_normal, attribute shading_normal, ); -rtDeclareVariable(int, lgt_idx, attribute lgt_idx, ); -rtDeclareVariable(optix::Ray, ray, rtCurrentRay, ); - -RT_PROGRAM void intersect(int primIdx) -{ - float3 n = make_float3( plane ); - float dt = dot(ray.direction, n ); - float t = (plane.w - dot(n, ray.origin))/dt; - if( t > ray.tmin && t < ray.tmax ) { - float3 p = ray.origin + ray.direction * t; - float3 vi = p - anchor; - float a1 = dot(v1, vi); - if(a1 >= 0 && a1 <= 1){ - float a2 = dot(v2, vi); - if(a2 >= 0 && a2 <= 1){ - if( rtPotentialIntersection( t ) ) { - shading_normal = geometric_normal = n; - texcoord = make_float3(a1,a2,0); - lgt_idx = lgt_instance; - rtReportIntersection( 0 ); - } - } - } - } -} - -RT_PROGRAM void bounds (int, float result[6]) -{ - // v1 and v2 are scaled by 1./length^2. Rescale back to normal for the bounds computation. - const float3 tv1 = v1 / dot( v1, v1 ); - const float3 tv2 = v2 / dot( v2, v2 ); - const float3 p00 = anchor; - const float3 p01 = anchor + tv1; - const float3 p10 = anchor + tv2; - const float3 p11 = anchor + tv1 + tv2; - const float area = length(cross(tv1, tv2)); - - optix::Aabb* aabb = (optix::Aabb*)result; - - if(area > 0.0f && !isinf(area)) { - aabb->m_min = fminf( fminf( p00, p01 ), fminf( p10, p11 ) ); - aabb->m_max = fmaxf( fmaxf( p00, p01 ), fmaxf( p10, p11 ) ); - } else { - aabb->invalidate(); - } -} - diff --git a/Source/OptiX/Private/cuda/already generated - tutorial/phong.h b/Source/OptiX/Private/cuda/already generated - tutorial/phong.h deleted file mode 100644 index d5f007fdb62e4d6ff051dbd87a228d528891f70d..0000000000000000000000000000000000000000 --- a/Source/OptiX/Private/cuda/already generated - tutorial/phong.h +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright (c) 2018 NVIDIA CORPORATION. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of NVIDIA CORPORATION nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <optix_world.h> -#include "commonStructs.h" -#include "helpers.h" - -struct PerRayData_radiance -{ - float4 result; - float importance; - int depth; -}; - -struct PerRayData_shadow -{ - float3 attenuation; -}; - - -rtDeclareVariable(int, max_depth, , ); -rtBuffer<BasicLight> lights; -rtDeclareVariable(float3, ambient_light_color, , ); -rtDeclareVariable(unsigned int, radiance_ray_type, , ); -rtDeclareVariable(unsigned int, shadow_ray_type, , ); -rtDeclareVariable(float, scene_epsilon, , ); -rtDeclareVariable(rtObject, top_object, , ); -rtDeclareVariable(rtObject, top_shadower, , ); - -rtDeclareVariable(optix::Ray, ray, rtCurrentRay, ); -rtDeclareVariable(float, t_hit, rtIntersectionDistance, ); -rtDeclareVariable(PerRayData_radiance, prd, rtPayload, ); -rtDeclareVariable(PerRayData_shadow, prd_shadow, rtPayload, ); - -static __device__ void phongShadowed() -{ - // this material is opaque, so it fully attenuates all shadow rays - prd_shadow.attenuation = optix::make_float3(0.0f); - rtTerminateRay(); -} - -static -__device__ void phongShade( float3 p_Kd, - float3 p_Ka, - float3 p_Ks, - float3 p_Kr, - float p_phong_exp, - float3 p_normal ) -{ - float3 hit_point = ray.origin + t_hit * ray.direction; - - // ambient contribution - - float3 result = p_Ka * ambient_light_color; - - // compute direct lighting - unsigned int num_lights = lights.size(); - for(int i = 0; i < num_lights; ++i) { - BasicLight light = lights[i]; - float Ldist = optix::length(light.pos - hit_point); - float3 L = optix::normalize(light.pos - hit_point); - float nDl = optix::dot( p_normal, L); - - // cast shadow ray - float3 light_attenuation = make_float3(static_cast<float>( nDl > 0.0f )); - if ( nDl > 0.0f && light.casts_shadow ) { - PerRayData_shadow shadow_prd; - shadow_prd.attenuation = make_float3(1.0f); - optix::Ray shadow_ray = optix::make_Ray( hit_point, L, shadow_ray_type, scene_epsilon, Ldist ); - rtTrace(top_shadower, shadow_ray, shadow_prd); - light_attenuation = shadow_prd.attenuation; - } - - // If not completely shadowed, light the hit point - if( fmaxf(light_attenuation) > 0.0f ) { - float3 Lc = light.color * light_attenuation; - - result += p_Kd * nDl * Lc; - - float3 H = optix::normalize(L - ray.direction); - float nDh = optix::dot( p_normal, H ); - if(nDh > 0) { - float power = pow(nDh, p_phong_exp); - result += p_Ks * power * Lc; - } - } - } - - if( fmaxf( p_Kr ) > 0 ) { - - // ray tree attenuation - PerRayData_radiance new_prd; - new_prd.importance = prd.importance * optix::luminance( p_Kr ); - new_prd.depth = prd.depth + 1; - - // reflection ray - if( new_prd.importance >= 0.01f && new_prd.depth <= max_depth) { - float3 R = optix::reflect( ray.direction, p_normal ); - optix::Ray refl_ray = optix::make_Ray( hit_point, R, radiance_ray_type, scene_epsilon, RT_DEFAULT_MAX ); - rtTrace(top_object, refl_ray, new_prd); - result += p_Kr * make_float3(new_prd.result.x, new_prd.result.y, new_prd.result.z); - } - } - float4 final_result = make_float4(result, 1.0); - // pass the color back up the tree - prd.result = final_result; -} diff --git a/Source/OptiX/Private/cuda/already generated - tutorial/random.h b/Source/OptiX/Private/cuda/already generated - tutorial/random.h deleted file mode 100644 index 1aed82d90992e5a78f6843a55b7c664646a7d0c6..0000000000000000000000000000000000000000 --- a/Source/OptiX/Private/cuda/already generated - tutorial/random.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2018 NVIDIA CORPORATION. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of NVIDIA CORPORATION nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <optixu/optixu_math_namespace.h> - -template<unsigned int N> -static __host__ __device__ __inline__ unsigned int tea( unsigned int val0, unsigned int val1 ) -{ - unsigned int v0 = val0; - unsigned int v1 = val1; - unsigned int s0 = 0; - - for( unsigned int n = 0; n < N; n++ ) - { - s0 += 0x9e3779b9; - v0 += ((v1<<4)+0xa341316c)^(v1+s0)^((v1>>5)+0xc8013ea4); - v1 += ((v0<<4)+0xad90777d)^(v0+s0)^((v0>>5)+0x7e95761e); - } - - return v0; -} - -// Generate random unsigned int in [0, 2^24) -static __host__ __device__ __inline__ unsigned int lcg(unsigned int &prev) -{ - const unsigned int LCG_A = 1664525u; - const unsigned int LCG_C = 1013904223u; - prev = (LCG_A * prev + LCG_C); - return prev & 0x00FFFFFF; -} - -static __host__ __device__ __inline__ unsigned int lcg2(unsigned int &prev) -{ - prev = (prev*8121 + 28411) % 134456; - return prev; -} - -// Generate random float in [0, 1) -static __host__ __device__ __inline__ float rnd(unsigned int &prev) -{ - return ((float) lcg(prev) / (float) 0x01000000); -} - -static __host__ __device__ __inline__ unsigned int rot_seed( unsigned int seed, unsigned int frame ) -{ - return seed ^ frame; -} diff --git a/Source/OptiX/Private/cuda/already generated - tutorial/tutorial.h b/Source/OptiX/Private/cuda/already generated - tutorial/tutorial.h deleted file mode 100644 index 1e95144473b0b39cd9d417e82798c6208ec3a37c..0000000000000000000000000000000000000000 --- a/Source/OptiX/Private/cuda/already generated - tutorial/tutorial.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2018 NVIDIA CORPORATION. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of NVIDIA CORPORATION nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <optix.h> -#include <optix_math.h> -// Used by all the tutorial cuda files -#include "commonStructs.h" - -using namespace optix; - -//#define FLT_MAX 1e30; - -static __device__ __inline__ float3 exp( const float3& x ) -{ - return make_float3(exp(x.x), exp(x.y), exp(x.z)); -} - -static __device__ __inline__ float step( float min, float value ) -{ - return value<min?0:1; -} - -static __device__ __inline__ float3 mix( float3 a, float3 b, float x ) -{ - return a*(1-x) + b*x; -} - -static __device__ __inline__ float3 schlick( float nDi, const float3& rgb ) -{ - float r = fresnel_schlick(nDi, 5, rgb.x, 1); - float g = fresnel_schlick(nDi, 5, rgb.y, 1); - float b = fresnel_schlick(nDi, 5, rgb.z, 1); - return make_float3(r, g, b); -} - -static __device__ __inline__ uchar4 make_color(const float3& c) -{ - return make_uchar4( static_cast<unsigned char>(__saturatef(c.z)*255.99f), /* B */ - static_cast<unsigned char>(__saturatef(c.y)*255.99f), /* G */ - static_cast<unsigned char>(__saturatef(c.x)*255.99f), /* R */ - 255u); /* A */ -} - -static __device__ __inline__ uchar4 make_color_with_alpha(const float3& c, unsigned char& alpha) -{ - return make_uchar4( static_cast<unsigned char>(__saturatef(c.z)*255.99f), /* B */ - static_cast<unsigned char>(__saturatef(c.y)*255.99f), /* G */ - static_cast<unsigned char>(__saturatef(c.x)*255.99f), /* R */ - alpha); /* A */ -} - -struct PerRayData_radiance -{ - float3 result; - float importance; - int depth; - int hit; -}; - -struct PerRayData_shadow -{ - float3 attenuation; -}; - diff --git a/Source/OptiX/Private/cuda/already generated - tutorial/tutorial0.cu b/Source/OptiX/Private/cuda/already generated - tutorial/tutorial0.cu deleted file mode 100644 index df53369228ed978ffad69566be6c447beb4dd642..0000000000000000000000000000000000000000 --- a/Source/OptiX/Private/cuda/already generated - tutorial/tutorial0.cu +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (c) 2018 NVIDIA CORPORATION. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of NVIDIA CORPORATION nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "tutorial.h" - -rtDeclareVariable(float3, shading_normal, attribute shading_normal, ); - -rtDeclareVariable(PerRayData_radiance, prd_radiance, rtPayload, ); - -rtDeclareVariable(optix::Ray, ray, rtCurrentRay, ); -rtDeclareVariable(uint2, launch_index, rtLaunchIndex, ); - -rtDeclareVariable(unsigned int, radiance_ray_type, , ); -rtDeclareVariable(float, scene_epsilon, , ); -rtDeclareVariable(rtObject, top_object, , ); - - -// -// Pinhole camera implementation -// -rtDeclareVariable(float3, eye, , ); -rtDeclareVariable(float3, U, , ); -rtDeclareVariable(float3, V, , ); -rtDeclareVariable(float3, W, , ); -rtDeclareVariable(float3, bad_color, , ); -rtBuffer<uchar4, 2> output_buffer; - -RT_PROGRAM void pinhole_camera() -{ - size_t2 screen = output_buffer.size(); - - float2 d = make_float2(launch_index) / make_float2(screen) * 2.f - 1.f; - float3 ray_origin = eye; - float3 ray_direction = normalize(d.x*U + d.y*V + W); - - optix::Ray ray(ray_origin, ray_direction, radiance_ray_type, scene_epsilon ); - - PerRayData_radiance prd; - prd.importance = 1.f; - prd.depth = 0; - - rtTrace(top_object, ray, prd); - - output_buffer[launch_index] = make_color( prd.result ); -} - -// -// Returns solid color for miss rays -// -rtDeclareVariable(float3, bg_color, , ); -RT_PROGRAM void miss() -{ - prd_radiance.result = bg_color; -} - - -// -// Returns shading normal as the surface shading result -// -RT_PROGRAM void closest_hit_radiance0() -{ - prd_radiance.result = normalize(rtTransformNormal(RT_OBJECT_TO_WORLD, shading_normal))*0.5f + 0.5f; -} - - -// -// Set pixel to solid color upon failur -// -RT_PROGRAM void exception() -{ - output_buffer[launch_index] = make_color( bad_color ); -} diff --git a/Source/OptiX/Private/cuda/already generated - tutorial/tutorial1.cu b/Source/OptiX/Private/cuda/already generated - tutorial/tutorial1.cu deleted file mode 100644 index d9dbc0854cb984b47b04186f624c0eefb2c2d67f..0000000000000000000000000000000000000000 --- a/Source/OptiX/Private/cuda/already generated - tutorial/tutorial1.cu +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright (c) 2018 NVIDIA CORPORATION. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of NVIDIA CORPORATION nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include <optix_world.h> -#include "tutorial.h" - -rtDeclareVariable(float3, shading_normal, attribute shading_normal, ); -rtDeclareVariable(float3, geometric_normal, attribute geometric_normal, ); - -rtDeclareVariable(PerRayData_radiance, prd_radiance, rtPayload, ); - -rtDeclareVariable(optix::Ray, ray, rtCurrentRay, ); -rtDeclareVariable(float, t_hit, rtIntersectionDistance, ); -rtDeclareVariable(uint2, launch_index, rtLaunchIndex, ); - -rtDeclareVariable(unsigned int, radiance_ray_type, , ); -rtDeclareVariable(float, scene_epsilon, , ); -rtDeclareVariable(rtObject, top_object, , ); - - -// -// Pinhole camera implementation -// -//rtDeclareVariable(float3, eye, , ); -//rtDeclareVariable(float3, U, , ); -//rtDeclareVariable(float3, V, , ); -//rtDeclareVariable(float3, W, , ); - -rtDeclareVariable(Matrix4x4, invViewProjection, , ); -rtDeclareVariable(Matrix4x4, viewProjection, , ); - -rtDeclareVariable(uint2, launch_dim, rtLaunchDim, ); - -rtDeclareVariable(float3, bad_color, , ); -rtBuffer<uchar4, 2> output_buffer; - -RT_PROGRAM void pinhole_camera() -{ - /* size_t2 screen = output_buffer.size(); - - float2 d = make_float2(launch_index) / make_float2(screen) * 2.f - 1.f; - float3 ray_origin = eye; - float3 ray_direction = normalize(d.x*U + d.y*V + W); - - optix::Ray ray(ray_origin, ray_direction, radiance_ray_type, scene_epsilon ); - - PerRayData_radiance prd; - prd.importance = 1.f; - prd.depth = 0; - - rtTrace(top_object, ray, prd); - - output_buffer[launch_index] = make_color( prd.result );*/ - - float2 d = make_float2(launch_index) / make_float2(launch_dim); - float dx = d.x * 2 - 1.0f; - float dy = ((1.0f - d.y) - 0.5f) * 2.0f; - - float4 ray_start_4 = invViewProjection * make_float4(dx, dy, 1.0f, 1.0f); - float4 ray_end_4 = invViewProjection * make_float4(dx, dy, 0.5f, 1.0f); - - float3 ray_origin = make_float3(ray_start_4.x, ray_start_4.y, ray_start_4.z); - float3 ray_end = make_float3(ray_end_4.x, ray_end_4.y, ray_end_4.z); - - - if (ray_start_4.w != 0) - { - ray_origin = (ray_origin / ray_start_4.w); - } - if (ray_end_4.w != 0) - { - ray_end = (ray_end / ray_end_4.w); - } - - float3 ray_direction = normalize(ray_end - ray_origin); - - optix::Ray ray(ray_origin, ray_direction, radiance_ray_type, scene_epsilon); - - PerRayData_radiance prd; - prd.importance = 1.f; - prd.depth = 0; - - rtTrace(top_object, ray, prd); - - output_buffer[launch_index] = make_color(prd.result); -} - - -// -// Returns solid color for miss rays -// -rtDeclareVariable(float3, bg_color, , ); -RT_PROGRAM void miss() -{ - prd_radiance.result = bg_color; -} - - -// -// (UPDATED) -// Implements basic lambertian surface shading model -// -rtDeclareVariable(float3, Ka, , ); -rtDeclareVariable(float3, Kd, , ); -rtDeclareVariable(float3, ambient_light_color, , ); -rtBuffer<BasicLight> lights; - -RT_PROGRAM void closest_hit_radiance1() -{ - float3 world_geo_normal = normalize( rtTransformNormal( RT_OBJECT_TO_WORLD, geometric_normal ) ); - float3 world_shade_normal = normalize( rtTransformNormal( RT_OBJECT_TO_WORLD, shading_normal ) ); - float3 ffnormal = faceforward( world_shade_normal, -ray.direction, world_geo_normal ); - float3 color = Ka * ambient_light_color; - - float3 hit_point = ray.origin + t_hit * ray.direction; - - for(int i = 0; i < lights.size(); ++i) { - BasicLight light = lights[i]; - float3 L = normalize(light.pos - hit_point); - float nDl = dot( ffnormal, L); - - if( nDl > 0 ) - color += Kd * nDl * light.color; - - } - prd_radiance.result = color; -} - - -// -// Set pixel to solid color upon failure -// -RT_PROGRAM void exception() -{ - output_buffer[launch_index] = make_color( bad_color ); -} diff --git a/Source/OptiX/Private/cuda/already generated - tutorial/tutorial10.cu b/Source/OptiX/Private/cuda/already generated - tutorial/tutorial10.cu deleted file mode 100644 index 97ffd95ead0c11fa3162c520854b33397a460a10..0000000000000000000000000000000000000000 --- a/Source/OptiX/Private/cuda/already generated - tutorial/tutorial10.cu +++ /dev/null @@ -1,538 +0,0 @@ -/* - * Copyright (c) 2018 NVIDIA CORPORATION. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of NVIDIA CORPORATION nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include <optix_world.h> -#include "tutorial.h" -#include <optixu/optixu_aabb.h> - -rtDeclareVariable(float3, geometric_normal, attribute geometric_normal, ); -rtDeclareVariable(float3, shading_normal, attribute shading_normal, ); - -rtDeclareVariable(PerRayData_radiance, prd_radiance, rtPayload, ); -rtDeclareVariable(PerRayData_shadow, prd_shadow, rtPayload, ); - -rtDeclareVariable(optix::Ray, ray, rtCurrentRay, ); -rtDeclareVariable(float, t_hit, rtIntersectionDistance, ); -rtDeclareVariable(uint2, launch_index, rtLaunchIndex, ); - -rtDeclareVariable(unsigned int, radiance_ray_type, , ); -rtDeclareVariable(unsigned int, shadow_ray_type , , ); -rtDeclareVariable(float, scene_epsilon, , ); -rtDeclareVariable(rtObject, top_object, , ); - - -// -// Pinhole camera implementation -// -//rtDeclareVariable(float3, eye, , ); -//rtDeclareVariable(float3, U, , ); -//rtDeclareVariable(float3, V, , ); -//rtDeclareVariable(float3, W, , ); -rtDeclareVariable(Matrix4x4, invViewProjection, , ); -rtDeclareVariable(Matrix4x4, viewProjection, , ); - -rtDeclareVariable(uint2, launch_dim, rtLaunchDim, ); - -rtDeclareVariable(float3, bad_color, , ); -rtBuffer<uchar4, 2> output_buffer; - -RT_PROGRAM void pinhole_camera() -{ - /* size_t2 screen = output_buffer.size(); - - float2 d = make_float2(launch_index) / make_float2(screen) * 2.f - 1.f; - float3 ray_origin = eye; - float3 ray_direction = normalize(d.x*U + d.y*V + W); - - optix::Ray ray(ray_origin, ray_direction, radiance_ray_type, scene_epsilon ); - - PerRayData_radiance prd; - prd.importance = 1.f; - prd.depth = 0; - - rtTrace(top_object, ray, prd); - - output_buffer[launch_index] = make_color( prd.result );*/ - - float2 d = make_float2(launch_index) / make_float2(launch_dim); - float dx = d.x * 2 - 1.0f; - float dy = ((1.0f - d.y) - 0.5f) * 2.0f; - - float4 ray_start_4 = invViewProjection * make_float4(dx, dy, 1.0f, 1.0f); - float4 ray_end_4 = invViewProjection * make_float4(dx, dy, 0.5f, 1.0f); - - float3 ray_origin = make_float3(ray_start_4.x, ray_start_4.y, ray_start_4.z); - float3 ray_end = make_float3(ray_end_4.x, ray_end_4.y, ray_end_4.z); - - //float3 ray_direction_pinhole = normalize(old_d.x*U + old_d.y*V + W); - - - if (ray_start_4.w != 0) - { - ray_origin = (ray_origin / ray_start_4.w); - } - if (ray_end_4.w != 0) - { - ray_end = (ray_end / ray_end_4.w); - } - - float3 ray_direction = normalize(ray_end - ray_origin); - - optix::Ray ray(ray_origin, ray_direction, radiance_ray_type, scene_epsilon); - - PerRayData_radiance prd; - prd.importance = 1.f; - prd.depth = 0; - prd.hit = 0; - - rtTrace(top_object, ray, prd); - - unsigned char a = 0u; - - if (prd.hit == 1) - { - a = 255u; - } - - uchar4 final_result = - make_uchar4(static_cast<unsigned char>(__saturatef(prd.result.z)*255.99f), /* B */ - static_cast<unsigned char>(__saturatef(prd.result.y)*255.99f), /* G */ - static_cast<unsigned char>(__saturatef(prd.result.x)*255.99f), /* R */ - a); - - output_buffer[launch_index] = final_result; -} - - -// -// Environment map background -// -rtTextureSampler<float4, 2> envmap; - -rtDeclareVariable(int, skybox, , ); - -RT_PROGRAM void envmap_miss() -{ - //float theta = atan2f( ray.direction.x, ray.direction.z ); - //float phi = M_PIf * 0.5f - acosf( ray.direction.y ); - //float u = (theta + M_PIf) * (0.5f * M_1_PIf); - //float v = 0.5f * ( 1.0f + sin(phi) ); - //prd_radiance.result = make_float3( tex2D(envmap, u, v) ); - - prd_radiance.result = make_float3(optix::rtTexCubemap<float4>(skybox, ray.direction.x, ray.direction.y, -ray.direction.z)); - -} - - -// -// Terminates and fully attenuates ray after any hit -// -RT_PROGRAM void any_hit_shadow() -{ - // this material is opaque, so it fully attenuates all shadow rays - prd_shadow.attenuation = make_float3(0); - - rtTerminateRay(); -} - - -// -// Procedural rusted metal surface shader -// - -/* - * Translated to CUDA C from Larry Gritz's LGRustyMetal.sl shader found at: - * http://renderman.org/RMR/Shaders/LGShaders/LGRustyMetal.sl - * - * Used with permission from tal AT renderman DOT org. - */ - -rtDeclareVariable(float3, ambient_light_color, , ); -rtBuffer<BasicLight> lights; -rtDeclareVariable(rtObject, top_shadower, , ); -rtDeclareVariable(float, importance_cutoff, , ); -rtDeclareVariable(int, max_depth, , ); -rtDeclareVariable(float3, reflectivity_n, , ); - -rtDeclareVariable(float, metalKa, , ) = 1; -rtDeclareVariable(float, metalKs, , ) = 1; -rtDeclareVariable(float, metalroughness, , ) = .1; -rtDeclareVariable(float, rustKa, , ) = 1; -rtDeclareVariable(float, rustKd, , ) = 1; -rtDeclareVariable(float3, rustcolor, , ) = {.437, .084, 0}; -rtDeclareVariable(float3, metalcolor, , ) = {.7, .7, .7}; -rtDeclareVariable(float, txtscale, , ) = .02; -rtDeclareVariable(float, rusty, , ) = 0.2; -rtDeclareVariable(float, rustbump, , ) = 0.85; -#define MAXOCTAVES 6 - -rtTextureSampler<float, 3> noise_texture; -static __device__ __inline__ float snoise(float3 p) -{ - return tex3D(noise_texture, p.x, p.y, p.z) * 2 -1; -} - -RT_PROGRAM void box_closest_hit_radiance() -{ - float3 world_geo_normal = normalize( rtTransformNormal( RT_OBJECT_TO_WORLD, geometric_normal ) ); - float3 world_shade_normal = normalize( rtTransformNormal( RT_OBJECT_TO_WORLD, shading_normal ) ); - float3 ffnormal = faceforward( world_shade_normal, -ray.direction, world_geo_normal ); - float3 hit_point = ray.origin + t_hit * ray.direction; - - /* Sum several octaves of abs(snoise), i.e. turbulence. Limit the - * number of octaves by the estimated change in PP between adjacent - * shading samples. - */ - float3 PP = txtscale * hit_point; - float a = 1; - float sum = 0; - for(int i = 0; i < MAXOCTAVES; i++ ){ - sum += a * fabs(snoise(PP)); - PP *= 2.0f; - a *= 0.5f; - } - - /* Scale the rust appropriately, modulate it by another noise - * computation, then sharpen it by squaring its value. - */ - float rustiness = step (1-rusty, clamp (sum,0.0f,1.0f)); - rustiness *= clamp (abs(snoise(PP)), 0.0f, .08f) / 0.08f; - rustiness *= rustiness; - - /* If we have any rust, calculate the color of the rust, taking into - * account the perturbed normal and shading like matte. - */ - float3 Nrust = ffnormal; - if (rustiness > 0) { - /* If it's rusty, also add a high frequency bumpiness to the normal */ - Nrust = normalize(ffnormal + rustbump * snoise(PP)); - Nrust = faceforward (Nrust, -ray.direction, world_geo_normal); - } - - float3 color = mix(metalcolor * metalKa, rustcolor * rustKa, rustiness) * ambient_light_color; - for(int i = 0; i < lights.size(); ++i) { - BasicLight light = lights[i]; - float3 L = normalize(light.pos - hit_point); - float nmDl = dot( ffnormal, L); - float nrDl = dot( Nrust, L); - - if( nmDl > 0.0f || nrDl > 0.0f ){ - // cast shadow ray - PerRayData_shadow shadow_prd; - shadow_prd.attenuation = make_float3(1.0f); - float Ldist = length(light.pos - hit_point); - optix::Ray shadow_ray( hit_point, L, shadow_ray_type, scene_epsilon, Ldist ); - rtTrace(top_shadower, shadow_ray, shadow_prd); - float3 light_attenuation = shadow_prd.attenuation; - - if( fmaxf(light_attenuation) > 0.0f ){ - float3 Lc = light.color * light_attenuation; - nrDl = max(nrDl * rustiness, 0.0f); - color += rustKd * rustcolor * nrDl * Lc; - - float r = nmDl * (1.0f-rustiness); - if(nmDl > 0.0f){ - float3 H = normalize(L - ray.direction); - float nmDh = dot( ffnormal, H ); - if(nmDh > 0) - color += r * metalKs * Lc * pow(nmDh, 1.f/metalroughness); - } - } - - } - } - - float3 r = schlick(-dot(ffnormal, ray.direction), reflectivity_n * (1-rustiness)); - float importance = prd_radiance.importance * optix::luminance( r ); - - // reflection ray - if( importance > importance_cutoff && prd_radiance.depth < max_depth) { - PerRayData_radiance refl_prd; - refl_prd.importance = importance; - refl_prd.depth = prd_radiance.depth+1; - float3 R = reflect( ray.direction, ffnormal ); - optix::Ray refl_ray( hit_point, R, radiance_ray_type, scene_epsilon ); - rtTrace(top_object, refl_ray, refl_prd); - color += r * refl_prd.result; - } - - prd_radiance.result = color; - prd_radiance.hit = 1; -} - - -// -// Phong surface shading with shadows and schlick-approximated fresnel reflections. -// Uses procedural texture to determine diffuse response. -// -rtDeclareVariable(float, phong_exp, , ); -rtDeclareVariable(float3, tile_v0, , ); -rtDeclareVariable(float3, tile_v1, , ); -rtDeclareVariable(float3, crack_color, , ); -rtDeclareVariable(float, crack_width, , ); -rtDeclareVariable(float3, Ka, , ); -rtDeclareVariable(float3, Ks, , ); -rtDeclareVariable(float3, Kd, , ); - -RT_PROGRAM void floor_closest_hit_radiance() -{ - float3 world_geo_normal = normalize( rtTransformNormal( RT_OBJECT_TO_WORLD, geometric_normal ) ); - float3 world_shade_normal = normalize( rtTransformNormal( RT_OBJECT_TO_WORLD, shading_normal ) ); - float3 ffnormal = faceforward( world_shade_normal, -ray.direction, world_geo_normal ); - float3 color = Ka * ambient_light_color; - - float3 hit_point = ray.origin + t_hit * ray.direction; - - float v0 = dot(tile_v0, hit_point); - float v1 = dot(tile_v1, hit_point); - v0 = v0 - floor(v0); - v1 = v1 - floor(v1); - - float3 local_Kd; - if( v0 > crack_width && v1 > crack_width ){ - local_Kd = Kd; - } else { - local_Kd = crack_color; - } - - for(int i = 0; i < lights.size(); ++i) { - BasicLight light = lights[i]; - float3 L = normalize(light.pos - hit_point); - float nDl = dot( ffnormal, L); - - if( nDl > 0.0f ){ - // cast shadow ray - PerRayData_shadow shadow_prd; - shadow_prd.attenuation = make_float3(1.0f); - float Ldist = length(light.pos - hit_point); - optix::Ray shadow_ray( hit_point, L, shadow_ray_type, scene_epsilon, Ldist ); - rtTrace(top_shadower, shadow_ray, shadow_prd); - float3 light_attenuation = shadow_prd.attenuation; - - if( fmaxf(light_attenuation) > 0.0f ){ - float3 Lc = light.color * light_attenuation; - color += local_Kd * nDl * Lc; - - float3 H = normalize(L - ray.direction); - float nDh = dot( ffnormal, H ); - if(nDh > 0) - color += Ks * Lc * pow(nDh, phong_exp); - } - - } - } - - float3 r = schlick(-dot(ffnormal, ray.direction), reflectivity_n); - float importance = prd_radiance.importance * optix::luminance( r ); - - // reflection ray - if( importance > importance_cutoff && prd_radiance.depth < max_depth) { - PerRayData_radiance refl_prd; - refl_prd.importance = importance; - refl_prd.depth = prd_radiance.depth+1; - float3 R = reflect( ray.direction, ffnormal ); - optix::Ray refl_ray( hit_point, R, radiance_ray_type, scene_epsilon ); - rtTrace(top_object, refl_ray, refl_prd); - color += r * refl_prd.result; - } - prd_radiance.hit = 1; - prd_radiance.result = color; -} - - -// -// Bounding box program for programmable convex hull primitive -// -rtDeclareVariable(float3, chull_bbmin, , ); -rtDeclareVariable(float3, chull_bbmax, , ); -RT_PROGRAM void chull_bounds (int primIdx, float result[6]) -{ - optix::Aabb* aabb = (optix::Aabb*)result; - aabb->m_min = chull_bbmin; - aabb->m_max = chull_bbmax; -} - - -// -// Intersection program for programmable convex hull primitive -// -rtBuffer<float4> planes; -RT_PROGRAM void chull_intersect(int primIdx) -{ - int n = planes.size(); - float t0 = -FLT_MAX; - float t1 = FLT_MAX; - float3 t0_normal = make_float3(0); - float3 t1_normal = make_float3(0); - for(int i = 0; i < n && t0 < t1; ++i ) { - float4 plane = planes[i]; - float3 n = make_float3(plane); - float d = plane.w; - - float denom = dot(n, ray.direction); - float t = -(d + dot(n, ray.origin))/denom; - if( denom < 0){ - // enter - if(t > t0){ - t0 = t; - t0_normal = n; - } - } else { - //exit - if(t < t1){ - t1 = t; - t1_normal = n; - } - } - } - - if(t0 > t1) - return; - - if(rtPotentialIntersection( t0 )){ - shading_normal = geometric_normal = t0_normal; - rtReportIntersection(0); - } else if(rtPotentialIntersection( t1 )){ - shading_normal = geometric_normal = t1_normal; - rtReportIntersection(0); - } -} - - -// -// (NEW) -// Attenuates shadow rays for shadowing transparent objects -// - -rtDeclareVariable(float3, shadow_attenuation, , ); - -RT_PROGRAM void glass_any_hit_shadow() -{ - float3 world_normal = normalize( rtTransformNormal( RT_OBJECT_TO_WORLD, shading_normal ) ); - float nDi = fabs(dot(world_normal, ray.direction)); - - prd_shadow.attenuation *= 1-fresnel_schlick(nDi, 5, 1-shadow_attenuation, make_float3(1)); - - rtIgnoreIntersection(); -} - - -// -// Dielectric surface shader -// -rtDeclareVariable(float3, cutoff_color, , ); -rtDeclareVariable(float, fresnel_exponent, , ); -rtDeclareVariable(float, fresnel_minimum, , ); -rtDeclareVariable(float, fresnel_maximum, , ); -rtDeclareVariable(float, refraction_index, , ); -rtDeclareVariable(int, refraction_maxdepth, , ); -rtDeclareVariable(int, reflection_maxdepth, , ); -rtDeclareVariable(float3, refraction_color, , ); -rtDeclareVariable(float3, reflection_color, , ); -rtDeclareVariable(float3, extinction_constant, , ); -RT_PROGRAM void glass_closest_hit_radiance() -{ - // intersection vectors - const float3 h = ray.origin + t_hit * ray.direction; // hitpoint - const float3 n = normalize(rtTransformNormal(RT_OBJECT_TO_WORLD, shading_normal)); // normal - const float3 i = ray.direction; // incident direction - - float reflection = 1.0f; - float3 result = make_float3(0.0f); - - float3 beer_attenuation; - if(dot(n, ray.direction) > 0){ - // Beer's law attenuation - beer_attenuation = exp(extinction_constant * t_hit); - } else { - beer_attenuation = make_float3(1); - } - - // refraction - if (prd_radiance.depth < min(refraction_maxdepth, max_depth)) - { - float3 t; // transmission direction - if ( refract(t, i, n, refraction_index) ) - { - - // check for external or internal reflection - float cos_theta = dot(i, n); - if (cos_theta < 0.0f) - cos_theta = -cos_theta; - else - cos_theta = dot(t, n); - - reflection = fresnel_schlick(cos_theta, fresnel_exponent, fresnel_minimum, fresnel_maximum); - - float importance = prd_radiance.importance * (1.0f-reflection) * optix::luminance( refraction_color * beer_attenuation ); - if ( importance > importance_cutoff ) { - optix::Ray ray( h, t, radiance_ray_type, scene_epsilon ); - PerRayData_radiance refr_prd; - refr_prd.depth = prd_radiance.depth+1; - refr_prd.importance = importance; - - rtTrace( top_object, ray, refr_prd ); - result += (1.0f - reflection) * refraction_color * refr_prd.result; - } else { - result += (1.0f - reflection) * refraction_color * cutoff_color; - } - } - // else TIR - } - - // reflection - if (prd_radiance.depth < min(reflection_maxdepth, max_depth)) - { - float3 r = reflect(i, n); - - float importance = prd_radiance.importance * reflection * optix::luminance( reflection_color * beer_attenuation ); - if ( importance > importance_cutoff ) { - optix::Ray ray( h, r, radiance_ray_type, scene_epsilon ); - PerRayData_radiance refl_prd; - refl_prd.depth = prd_radiance.depth+1; - refl_prd.importance = importance; - - rtTrace( top_object, ray, refl_prd ); - result += reflection * reflection_color * refl_prd.result; - } else { - result += reflection * reflection_color * cutoff_color; - } - } - - result = result * beer_attenuation; - prd_radiance.hit = 1; - prd_radiance.result = result; -} - - -// -// Set pixel to solid color upon failure -// -RT_PROGRAM void exception() -{ - output_buffer[launch_index] = make_color( bad_color ); -} diff --git a/Source/OptiX/Private/cuda/already generated - tutorial/tutorial11.cu b/Source/OptiX/Private/cuda/already generated - tutorial/tutorial11.cu deleted file mode 100644 index 0e77db9e2e4cbcce89e2ec82fbf4bf39f2381e42..0000000000000000000000000000000000000000 --- a/Source/OptiX/Private/cuda/already generated - tutorial/tutorial11.cu +++ /dev/null @@ -1,477 +0,0 @@ -/* - * Copyright (c) 2018 NVIDIA CORPORATION. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of NVIDIA CORPORATION nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "tutorial.h" -#include <optixu/optixu_aabb_namespace.h> - -rtDeclareVariable(float3, geometric_normal, attribute geometric_normal, ); -rtDeclareVariable(float3, shading_normal, attribute shading_normal, ); - -rtDeclareVariable(PerRayData_radiance, prd_radiance, rtPayload, ); -rtDeclareVariable(PerRayData_shadow, prd_shadow, rtPayload, ); - -rtDeclareVariable(optix::Ray, ray, rtCurrentRay, ); -rtDeclareVariable(float, t_hit, rtIntersectionDistance, ); -rtDeclareVariable(uint2, launch_index, rtLaunchIndex, ); - -rtDeclareVariable(unsigned int, radiance_ray_type, , ); -rtDeclareVariable(unsigned int, shadow_ray_type , , ); -rtDeclareVariable(float, scene_epsilon, , ); -rtDeclareVariable(rtObject, top_object, , ); - - -// -// (NEW) -// Environment map camera -// -rtDeclareVariable(float3, eye, , ); -rtDeclareVariable(float3, U, , ); -rtDeclareVariable(float3, V, , ); -rtDeclareVariable(float3, W, , ); -rtDeclareVariable(float3, bad_color, , ); -rtBuffer<uchar4, 2> output_buffer; -RT_PROGRAM void env_camera() -{ - size_t2 screen = output_buffer.size(); - - float2 d = make_float2(launch_index) / make_float2(screen) * make_float2(2.0f * M_PIf , M_PIf) + make_float2(M_PIf, 0); - float3 angle = make_float3(cos(d.x) * sin(d.y), -cos(d.y), sin(d.x) * sin(d.y)); - float3 ray_origin = eye; - float3 ray_direction = normalize(angle.x*normalize(U) + angle.y*normalize(V) + angle.z*normalize(W)); - - optix::Ray ray(ray_origin, ray_direction, radiance_ray_type, scene_epsilon); - - PerRayData_radiance prd; - prd.importance = 1.f; - prd.depth = 0; - - rtTrace(top_object, ray, prd); - - output_buffer[launch_index] = make_color( prd.result ); -} - - -// -// Environment map background -// -rtTextureSampler<float4, 2> envmap; -RT_PROGRAM void envmap_miss() -{ - float theta = atan2f( ray.direction.x, ray.direction.z ); - float phi = M_PIf * 0.5f - acosf( ray.direction.y ); - float u = (theta + M_PIf) * (0.5f * M_1_PIf); - float v = 0.5f * ( 1.0f + sin(phi) ); - prd_radiance.result = make_float3( tex2D(envmap, u, v) ); -} - - -// -// Terminates and fully attenuates ray after any hit -// -RT_PROGRAM void any_hit_shadow() -{ - // this material is opaque, so it fully attenuates all shadow rays - prd_shadow.attenuation = make_float3(0); - - rtTerminateRay(); -} - - -// -// Procedural rusted metal surface shader -// - -/* - * Translated to CUDA C from Larry Gritz's LGRustyMetal.sl shader found at: - * http://renderman.org/RMR/Shaders/LGShaders/LGRustyMetal.sl - * - * Used with permission from tal AT renderman DOT org. - */ - -rtDeclareVariable(float3, ambient_light_color, , ); -rtBuffer<BasicLight> lights; -rtDeclareVariable(rtObject, top_shadower, , ); -rtDeclareVariable(float, importance_cutoff, , ); -rtDeclareVariable(int, max_depth, , ); -rtDeclareVariable(float3, reflectivity_n, , ); - -rtDeclareVariable(float, metalKa, , ) = 1; -rtDeclareVariable(float, metalKs, , ) = 1; -rtDeclareVariable(float, metalroughness, , ) = .1; -rtDeclareVariable(float, rustKa, , ) = 1; -rtDeclareVariable(float, rustKd, , ) = 1; -rtDeclareVariable(float3, rustcolor, , ) = {.437, .084, 0}; -rtDeclareVariable(float3, metalcolor, , ) = {.7, .7, .7}; -rtDeclareVariable(float, txtscale, , ) = .02; -rtDeclareVariable(float, rusty, , ) = 0.2; -rtDeclareVariable(float, rustbump, , ) = 0.85; -#define MAXOCTAVES 6 - -rtTextureSampler<float, 3> noise_texture; -static __device__ __inline__ float snoise(float3 p) -{ - return tex3D(noise_texture, p.x, p.y, p.z) * 2 -1; -} - -RT_PROGRAM void box_closest_hit_radiance() -{ - float3 world_geo_normal = normalize( rtTransformNormal( RT_OBJECT_TO_WORLD, geometric_normal ) ); - float3 world_shade_normal = normalize( rtTransformNormal( RT_OBJECT_TO_WORLD, shading_normal ) ); - float3 ffnormal = faceforward( world_shade_normal, -ray.direction, world_geo_normal ); - float3 hit_point = ray.origin + t_hit * ray.direction; - - /* Sum several octaves of abs(snoise), i.e. turbulence. Limit the - * number of octaves by the estimated change in PP between adjacent - * shading samples. - */ - float3 PP = txtscale * hit_point; - float a = 1; - float sum = 0; - for(int i = 0; i < MAXOCTAVES; i++ ){ - sum += a * fabs(snoise(PP)); - PP *= 2.0f; - a *= 0.5f; - } - - /* Scale the rust appropriately, modulate it by another noise - * computation, then sharpen it by squaring its value. - */ - float rustiness = step (1-rusty, clamp (sum,0.0f,1.0f)); - rustiness *= clamp (abs(snoise(PP)), 0.0f, .08f) / 0.08f; - rustiness *= rustiness; - - /* If we have any rust, calculate the color of the rust, taking into - * account the perturbed normal and shading like matte. - */ - float3 Nrust = ffnormal; - if (rustiness > 0) { - /* If it's rusty, also add a high frequency bumpiness to the normal */ - Nrust = normalize(ffnormal + rustbump * snoise(PP)); - Nrust = faceforward (Nrust, -ray.direction, world_geo_normal); - } - - float3 color = mix(metalcolor * metalKa, rustcolor * rustKa, rustiness) * ambient_light_color; - for(int i = 0; i < lights.size(); ++i) { - BasicLight light = lights[i]; - float3 L = normalize(light.pos - hit_point); - float nmDl = dot( ffnormal, L); - float nrDl = dot( Nrust, L); - - if( nmDl > 0.0f || nrDl > 0.0f ){ - // cast shadow ray - PerRayData_shadow shadow_prd; - shadow_prd.attenuation = make_float3(1.0f); - float Ldist = length(light.pos - hit_point); - optix::Ray shadow_ray( hit_point, L, shadow_ray_type, scene_epsilon, Ldist ); - rtTrace(top_shadower, shadow_ray, shadow_prd); - float3 light_attenuation = shadow_prd.attenuation; - - if( fmaxf(light_attenuation) > 0.0f ){ - float3 Lc = light.color * light_attenuation; - nrDl = max(nrDl * rustiness, 0.0f); - color += rustKd * rustcolor * nrDl * Lc; - - float r = nmDl * (1.0f-rustiness); - if(nmDl > 0.0f){ - float3 H = normalize(L - ray.direction); - float nmDh = dot( ffnormal, H ); - if(nmDh > 0) - color += r * metalKs * Lc * pow(nmDh, 1.f/metalroughness); - } - } - - } - } - - float3 r = schlick(-dot(ffnormal, ray.direction), reflectivity_n * (1-rustiness)); - float importance = prd_radiance.importance * optix::luminance( r ); - - // reflection ray - if( importance > importance_cutoff && prd_radiance.depth < max_depth) { - PerRayData_radiance refl_prd; - refl_prd.importance = importance; - refl_prd.depth = prd_radiance.depth+1; - float3 R = reflect( ray.direction, ffnormal ); - optix::Ray refl_ray( hit_point, R, radiance_ray_type, scene_epsilon ); - rtTrace(top_object, refl_ray, refl_prd); - color += r * refl_prd.result; - } - - prd_radiance.result = color; -} - - -// -// Phong surface shading with shadows and schlick-approximated fresnel reflections. -// Uses procedural texture to determine diffuse response. -// -rtDeclareVariable(float, phong_exp, , ); -rtDeclareVariable(float3, tile_v0, , ); -rtDeclareVariable(float3, tile_v1, , ); -rtDeclareVariable(float3, crack_color, , ); -rtDeclareVariable(float, crack_width, , ); -rtDeclareVariable(float3, Ka, , ); -rtDeclareVariable(float3, Ks, , ); -rtDeclareVariable(float3, Kd, , ); - -RT_PROGRAM void floor_closest_hit_radiance() -{ - float3 world_geo_normal = normalize( rtTransformNormal( RT_OBJECT_TO_WORLD, geometric_normal ) ); - float3 world_shade_normal = normalize( rtTransformNormal( RT_OBJECT_TO_WORLD, shading_normal ) ); - float3 ffnormal = faceforward( world_shade_normal, -ray.direction, world_geo_normal ); - float3 color = Ka * ambient_light_color; - - float3 hit_point = ray.origin + t_hit * ray.direction; - - float v0 = dot(tile_v0, hit_point); - float v1 = dot(tile_v1, hit_point); - v0 = v0 - floor(v0); - v1 = v1 - floor(v1); - - float3 local_Kd; - if( v0 > crack_width && v1 > crack_width ){ - local_Kd = Kd; - } else { - local_Kd = crack_color; - } - - for(int i = 0; i < lights.size(); ++i) { - BasicLight light = lights[i]; - float3 L = normalize(light.pos - hit_point); - float nDl = dot( ffnormal, L); - - if( nDl > 0.0f ){ - // cast shadow ray - PerRayData_shadow shadow_prd; - shadow_prd.attenuation = make_float3(1.0f); - float Ldist = length(light.pos - hit_point); - optix::Ray shadow_ray( hit_point, L, shadow_ray_type, scene_epsilon, Ldist ); - rtTrace(top_shadower, shadow_ray, shadow_prd); - float3 light_attenuation = shadow_prd.attenuation; - - if( fmaxf(light_attenuation) > 0.0f ){ - float3 Lc = light.color * light_attenuation; - color += local_Kd * nDl * Lc; - - float3 H = normalize(L - ray.direction); - float nDh = dot( ffnormal, H ); - if(nDh > 0) - color += Ks * Lc * pow(nDh, phong_exp); - } - - } - } - - float3 r = schlick(-dot(ffnormal, ray.direction), reflectivity_n); - float importance = prd_radiance.importance * optix::luminance( r ); - - // reflection ray - if( importance > importance_cutoff && prd_radiance.depth < max_depth) { - PerRayData_radiance refl_prd; - refl_prd.importance = importance; - refl_prd.depth = prd_radiance.depth+1; - float3 R = reflect( ray.direction, ffnormal ); - optix::Ray refl_ray( hit_point, R, radiance_ray_type, scene_epsilon ); - rtTrace(top_object, refl_ray, refl_prd); - color += r * refl_prd.result; - } - - prd_radiance.result = color; -} - - -// -// Bounding box program for programmable convex hull primitive -// -rtDeclareVariable(float3, chull_bbmin, , ); -rtDeclareVariable(float3, chull_bbmax, , ); -RT_PROGRAM void chull_bounds (int primIdx, float result[6]) -{ - optix::Aabb* aabb = (optix::Aabb*)result; - aabb->m_min = chull_bbmin; - aabb->m_max = chull_bbmax; -} - - -// -// Intersection program for programmable convex hull primitive -// -rtBuffer<float4> planes; -RT_PROGRAM void chull_intersect(int primIdx) -{ - int n = planes.size(); - float t0 = -FLT_MAX; - float t1 = FLT_MAX; - float3 t0_normal = make_float3(0); - float3 t1_normal = make_float3(0); - for(int i = 0; i < n && t0 < t1; ++i ) { - float4 plane = planes[i]; - float3 n = make_float3(plane); - float d = plane.w; - - float denom = dot(n, ray.direction); - float t = -(d + dot(n, ray.origin))/denom; - if( denom < 0){ - // enter - if(t > t0){ - t0 = t; - t0_normal = n; - } - } else { - //exit - if(t < t1){ - t1 = t; - t1_normal = n; - } - } - } - - if(t0 > t1) - return; - - if(rtPotentialIntersection( t0 )){ - shading_normal = geometric_normal = t0_normal; - rtReportIntersection(0); - } else if(rtPotentialIntersection( t1 )){ - shading_normal = geometric_normal = t1_normal; - rtReportIntersection(0); - } -} - - -// -// Attenuates shadow rays for shadowing transparent objects -// -rtDeclareVariable(float3, shadow_attenuation, , ); - -RT_PROGRAM void glass_any_hit_shadow() -{ - float3 world_normal = normalize( rtTransformNormal( RT_OBJECT_TO_WORLD, shading_normal ) ); - float nDi = fabs(dot(world_normal, ray.direction)); - - prd_shadow.attenuation *= 1-fresnel_schlick(nDi, 5, 1-shadow_attenuation, make_float3(1)); - - rtIgnoreIntersection(); -} - - -// -// Dielectric surface shader -// -rtDeclareVariable(float3, cutoff_color, , ); -rtDeclareVariable(float, fresnel_exponent, , ); -rtDeclareVariable(float, fresnel_minimum, , ); -rtDeclareVariable(float, fresnel_maximum, , ); -rtDeclareVariable(float, refraction_index, , ); -rtDeclareVariable(int, refraction_maxdepth, , ); -rtDeclareVariable(int, reflection_maxdepth, , ); -rtDeclareVariable(float3, refraction_color, , ); -rtDeclareVariable(float3, reflection_color, , ); -rtDeclareVariable(float3, extinction_constant, , ); -RT_PROGRAM void glass_closest_hit_radiance() -{ - // intersection vectors - const float3 h = ray.origin + t_hit * ray.direction; // hitpoint - const float3 n = normalize(rtTransformNormal(RT_OBJECT_TO_WORLD, shading_normal)); // normal - const float3 i = ray.direction; // incident direction - - float reflection = 1.0f; - float3 result = make_float3(0.0f); - - float3 beer_attenuation; - if(dot(n, ray.direction) > 0){ - // Beer's law attenuation - beer_attenuation = exp(extinction_constant * t_hit); - } else { - beer_attenuation = make_float3(1); - } - - // refraction - if (prd_radiance.depth < min(refraction_maxdepth, max_depth)) - { - float3 t; // transmission direction - if ( refract(t, i, n, refraction_index) ) - { - - // check for external or internal reflection - float cos_theta = dot(i, n); - if (cos_theta < 0.0f) - cos_theta = -cos_theta; - else - cos_theta = dot(t, n); - - reflection = fresnel_schlick(cos_theta, fresnel_exponent, fresnel_minimum, fresnel_maximum); - - float importance = prd_radiance.importance * (1.0f-reflection) * optix::luminance( refraction_color * beer_attenuation ); - if ( importance > importance_cutoff ) { - optix::Ray ray( h, t, radiance_ray_type, scene_epsilon ); - PerRayData_radiance refr_prd; - refr_prd.depth = prd_radiance.depth+1; - refr_prd.importance = importance; - - rtTrace( top_object, ray, refr_prd ); - result += (1.0f - reflection) * refraction_color * refr_prd.result; - } else { - result += (1.0f - reflection) * refraction_color * cutoff_color; - } - } - // else TIR - } - - // reflection - if (prd_radiance.depth < min(reflection_maxdepth, max_depth)) - { - float3 r = reflect(i, n); - - float importance = prd_radiance.importance * reflection * optix::luminance( reflection_color * beer_attenuation ); - if ( importance > importance_cutoff ) { - optix::Ray ray( h, r, radiance_ray_type, scene_epsilon ); - PerRayData_radiance refl_prd; - refl_prd.depth = prd_radiance.depth+1; - refl_prd.importance = importance; - - rtTrace( top_object, ray, refl_prd ); - result += reflection * reflection_color * refl_prd.result; - } else { - result += reflection * reflection_color * cutoff_color; - } - } - - result = result * beer_attenuation; - - prd_radiance.result = result; -} - - -// -// Set pixel to solid color upon failure -// -RT_PROGRAM void exception() -{ - output_buffer[launch_index] = make_color( bad_color ); -} diff --git a/Source/OptiX/Private/cuda/already generated - tutorial/tutorial2.cu b/Source/OptiX/Private/cuda/already generated - tutorial/tutorial2.cu deleted file mode 100644 index 55f64b23371e18941d38d6b5eeb1feb638326c5f..0000000000000000000000000000000000000000 --- a/Source/OptiX/Private/cuda/already generated - tutorial/tutorial2.cu +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (c) 2018 NVIDIA CORPORATION. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of NVIDIA CORPORATION nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "tutorial.h" - -rtDeclareVariable(float3, geometric_normal, attribute geometric_normal, ); -rtDeclareVariable(float3, shading_normal, attribute shading_normal, ); - -rtDeclareVariable(PerRayData_radiance, prd_radiance, rtPayload, ); - -rtDeclareVariable(optix::Ray, ray, rtCurrentRay, ); -rtDeclareVariable(float, t_hit, rtIntersectionDistance, ); -rtDeclareVariable(uint2, launch_index, rtLaunchIndex, ); - -rtDeclareVariable(unsigned int, radiance_ray_type, , ); -rtDeclareVariable(float, scene_epsilon, , ); -rtDeclareVariable(rtObject, top_object, , ); - - -// -// Pinhole camera implementation -// -rtDeclareVariable(float3, eye, , ); -rtDeclareVariable(float3, U, , ); -rtDeclareVariable(float3, V, , ); -rtDeclareVariable(float3, W, , ); -rtDeclareVariable(float3, bad_color, , ); -rtBuffer<uchar4, 2> output_buffer; - -RT_PROGRAM void pinhole_camera() -{ - size_t2 screen = output_buffer.size(); - - float2 d = make_float2(launch_index) / make_float2(screen) * 2.f - 1.f; - float3 ray_origin = eye; - float3 ray_direction = normalize(d.x*U + d.y*V + W); - - optix::Ray ray(ray_origin, ray_direction, radiance_ray_type, scene_epsilon ); - - PerRayData_radiance prd; - prd.importance = 1.f; - prd.depth = 0; - - rtTrace(top_object, ray, prd); - - output_buffer[launch_index] = make_color( prd.result ); -} - - -// -// Returns solid color for miss rays -// -rtDeclareVariable(float3, bg_color, , ); -RT_PROGRAM void miss() -{ - prd_radiance.result = bg_color; -} - - -// -// (UPDATED) -// Implements basic phong shading model -- lambertian plus highlights -// -rtDeclareVariable(float3, Ka, , ); -rtDeclareVariable(float3, Ks, , ); -rtDeclareVariable(float, phong_exp, , ); -rtDeclareVariable(float3, Kd, , ); -rtDeclareVariable(float3, ambient_light_color, , ); -rtBuffer<BasicLight> lights; - -RT_PROGRAM void closest_hit_radiance2() -{ - float3 world_geo_normal = normalize( rtTransformNormal( RT_OBJECT_TO_WORLD, geometric_normal ) ); - float3 world_shade_normal = normalize( rtTransformNormal( RT_OBJECT_TO_WORLD, shading_normal ) ); - float3 ffnormal = faceforward( world_shade_normal, -ray.direction, world_geo_normal ); - float3 color = Ka * ambient_light_color; - - float3 hit_point = ray.origin + t_hit * ray.direction; - - for(int i = 0; i < lights.size(); ++i) { - BasicLight light = lights[i]; - float3 L = normalize(light.pos - hit_point); - float nDl = dot( ffnormal, L); - - if( nDl > 0 ){ - float3 Lc = light.color; - color += Kd * nDl * Lc; - - float3 H = normalize(L - ray.direction); - float nDh = dot( ffnormal, H ); - if(nDh > 0) - color += Ks * Lc * pow(nDh, phong_exp); - - } - } - prd_radiance.result = color; -} - - -// -// Set pixel to solid color upon failure -// -RT_PROGRAM void exception() -{ - output_buffer[launch_index] = make_color( bad_color ); -} diff --git a/Source/OptiX/Private/cuda/already generated - tutorial/tutorial3.cu b/Source/OptiX/Private/cuda/already generated - tutorial/tutorial3.cu deleted file mode 100644 index db603ba5740fe614591acd7c488a6cf159cbb47a..0000000000000000000000000000000000000000 --- a/Source/OptiX/Private/cuda/already generated - tutorial/tutorial3.cu +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright (c) 2018 NVIDIA CORPORATION. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of NVIDIA CORPORATION nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "tutorial.h" - -rtDeclareVariable(float3, geometric_normal, attribute geometric_normal, ); -rtDeclareVariable(float3, shading_normal, attribute shading_normal, ); - -rtDeclareVariable(PerRayData_radiance, prd_radiance, rtPayload, ); -rtDeclareVariable(PerRayData_shadow, prd_shadow, rtPayload, ); - -rtDeclareVariable(optix::Ray, ray, rtCurrentRay, ); -rtDeclareVariable(float, t_hit, rtIntersectionDistance, ); -rtDeclareVariable(uint2, launch_index, rtLaunchIndex, ); - -rtDeclareVariable(unsigned int, radiance_ray_type, , ); -rtDeclareVariable(unsigned int, shadow_ray_type , , ); -rtDeclareVariable(float, scene_epsilon, , ); -rtDeclareVariable(rtObject, top_object, , ); - - -// -// Pinhole camera implementation -// -rtDeclareVariable(float3, eye, , ); -rtDeclareVariable(float3, U, , ); -rtDeclareVariable(float3, V, , ); -rtDeclareVariable(float3, W, , ); -rtDeclareVariable(float3, bad_color, , ); -rtBuffer<uchar4, 2> output_buffer; - -RT_PROGRAM void pinhole_camera() -{ - size_t2 screen = output_buffer.size(); - - float2 d = make_float2(launch_index) / make_float2(screen) * 2.f - 1.f; - float3 ray_origin = eye; - float3 ray_direction = normalize(d.x*U + d.y*V + W); - - optix::Ray ray(ray_origin, ray_direction, radiance_ray_type, scene_epsilon ); - - PerRayData_radiance prd; - prd.importance = 1.f; - prd.depth = 0; - - rtTrace(top_object, ray, prd); - - output_buffer[launch_index] = make_color( prd.result ); -} - - -// -// Returns solid color for miss rays -// -rtDeclareVariable(float3, bg_color, , ); -RT_PROGRAM void miss() -{ - prd_radiance.result = bg_color; -} - - -// -// (NEW) -// Terminates and fully attenuates ray after any hit -// -RT_PROGRAM void any_hit_shadow() -{ - // this material is opaque, so it fully attenuates all shadow rays - prd_shadow.attenuation = make_float3(0); - - rtTerminateRay(); -} - - -// -// (UPDATED) -// Phong surface shading with shadows -// -rtDeclareVariable(float3, Ka, , ); -rtDeclareVariable(float3, Ks, , ); -rtDeclareVariable(float, phong_exp, , ); -rtDeclareVariable(float3, Kd, , ); -rtDeclareVariable(float3, ambient_light_color, , ); -rtBuffer<BasicLight> lights; -rtDeclareVariable(rtObject, top_shadower, , ); - -RT_PROGRAM void closest_hit_radiance3() -{ - float3 world_geo_normal = normalize( rtTransformNormal( RT_OBJECT_TO_WORLD, geometric_normal ) ); - float3 world_shade_normal = normalize( rtTransformNormal( RT_OBJECT_TO_WORLD, shading_normal ) ); - float3 ffnormal = faceforward( world_shade_normal, -ray.direction, world_geo_normal ); - float3 color = Ka * ambient_light_color; - - float3 hit_point = ray.origin + t_hit * ray.direction; - - for(int i = 0; i < lights.size(); ++i) { - BasicLight light = lights[i]; - float3 L = normalize(light.pos - hit_point); - float nDl = dot( ffnormal, L); - - if( nDl > 0.0f ){ - // cast shadow ray - PerRayData_shadow shadow_prd; - shadow_prd.attenuation = make_float3(1.0f); - float Ldist = length(light.pos - hit_point); - optix::Ray shadow_ray( hit_point, L, shadow_ray_type, scene_epsilon, Ldist ); - rtTrace(top_shadower, shadow_ray, shadow_prd); - float3 light_attenuation = shadow_prd.attenuation; - - if( fmaxf(light_attenuation) > 0.0f ){ - float3 Lc = light.color * light_attenuation; - color += Kd * nDl * Lc; - - float3 H = normalize(L - ray.direction); - float nDh = dot( ffnormal, H ); - if(nDh > 0) - color += Ks * Lc * pow(nDh, phong_exp); - } - - } - } - prd_radiance.result = color; -} - - -// -// Set pixel to solid color upon failure -// -RT_PROGRAM void exception() -{ - output_buffer[launch_index] = make_color( bad_color ); -} diff --git a/Source/OptiX/Private/cuda/already generated - tutorial/tutorial4.cu b/Source/OptiX/Private/cuda/already generated - tutorial/tutorial4.cu deleted file mode 100644 index 8c79acf1d46f9e2db775ae65a1bd346b5552c796..0000000000000000000000000000000000000000 --- a/Source/OptiX/Private/cuda/already generated - tutorial/tutorial4.cu +++ /dev/null @@ -1,217 +0,0 @@ -/* - * Copyright (c) 2018 NVIDIA CORPORATION. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of NVIDIA CORPORATION nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "tutorial.h" - -rtDeclareVariable(float3, geometric_normal, attribute geometric_normal, ); -rtDeclareVariable(float3, shading_normal, attribute shading_normal, ); - -rtDeclareVariable(PerRayData_radiance, prd_radiance, rtPayload, ); -rtDeclareVariable(PerRayData_shadow, prd_shadow, rtPayload, ); - -rtDeclareVariable(optix::Ray, ray, rtCurrentRay, ); -rtDeclareVariable(float, t_hit, rtIntersectionDistance, ); -rtDeclareVariable(uint2, launch_index, rtLaunchIndex, ); - -rtDeclareVariable(unsigned int, radiance_ray_type, , ); -rtDeclareVariable(unsigned int, shadow_ray_type , , ); -rtDeclareVariable(float, scene_epsilon, , ); -rtDeclareVariable(rtObject, top_object, , ); - - -// -// Pinhole camera implementation -// -rtDeclareVariable(float3, eye, , ); -rtDeclareVariable(float3, U, , ); -rtDeclareVariable(float3, V, , ); -rtDeclareVariable(float3, W, , ); -rtDeclareVariable(float3, bad_color, , ); -rtBuffer<uchar4, 2> output_buffer; - -RT_PROGRAM void pinhole_camera() -{ - size_t2 screen = output_buffer.size(); - - float2 d = make_float2(launch_index) / make_float2(screen) * 2.f - 1.f; - float3 ray_origin = eye; - float3 ray_direction = normalize(d.x*U + d.y*V + W); - - optix::Ray ray(ray_origin, ray_direction, radiance_ray_type, scene_epsilon ); - - PerRayData_radiance prd; - prd.importance = 1.f; - prd.depth = 0; - - rtTrace(top_object, ray, prd); - - output_buffer[launch_index] = make_color( prd.result ); -} - - -// -// Returns solid color for miss rays -// - -rtDeclareVariable(float3, bg_color, , ); -RT_PROGRAM void miss() -{ - prd_radiance.result = bg_color; -} - - -// -// Terminates and fully attenuates ray after any hit -// -RT_PROGRAM void any_hit_shadow() -{ - // this material is opaque, so it fully attenuates all shadow rays - prd_shadow.attenuation = make_float3(0); - - rtTerminateRay(); -} - - -// -// Phong surface shading with shadows -// -rtDeclareVariable(float3, Ka, , ); -rtDeclareVariable(float3, Ks, , ); -rtDeclareVariable(float, phong_exp, , ); -rtDeclareVariable(float3, Kd, , ); -rtDeclareVariable(float3, ambient_light_color, , ); -rtBuffer<BasicLight> lights; -rtDeclareVariable(rtObject, top_shadower, , ); - -RT_PROGRAM void closest_hit_radiance3() -{ - float3 world_geo_normal = normalize( rtTransformNormal( RT_OBJECT_TO_WORLD, geometric_normal ) ); - float3 world_shade_normal = normalize( rtTransformNormal( RT_OBJECT_TO_WORLD, shading_normal ) ); - float3 ffnormal = faceforward( world_shade_normal, -ray.direction, world_geo_normal ); - float3 color = Ka * ambient_light_color; - - float3 hit_point = ray.origin + t_hit * ray.direction; - - for(int i = 0; i < lights.size(); ++i) { - BasicLight light = lights[i]; - float3 L = normalize(light.pos - hit_point); - float nDl = dot( ffnormal, L); - - if( nDl > 0.0f ){ - // cast shadow ray - PerRayData_shadow shadow_prd; - shadow_prd.attenuation = make_float3(1.0f); - float Ldist = length(light.pos - hit_point); - optix::Ray shadow_ray( hit_point, L, shadow_ray_type, scene_epsilon, Ldist ); - rtTrace(top_shadower, shadow_ray, shadow_prd); - float3 light_attenuation = shadow_prd.attenuation; - - if( fmaxf(light_attenuation) > 0.0f ){ - float3 Lc = light.color * light_attenuation; - color += Kd * nDl * Lc; - - float3 H = normalize(L - ray.direction); - float nDh = dot( ffnormal, H ); - if(nDh > 0) - color += Ks * Lc * pow(nDh, phong_exp); - } - - } - } - prd_radiance.result = color; -} - - -// -// (NEW) -// Phong surface shading with shadows and reflections -// -rtDeclareVariable(float3, reflectivity, , ); -rtDeclareVariable(float, importance_cutoff, , ); -rtDeclareVariable(int, max_depth, , ); - -RT_PROGRAM void floor_closest_hit_radiance4() -{ - float3 world_geo_normal = normalize( rtTransformNormal( RT_OBJECT_TO_WORLD, geometric_normal ) ); - float3 world_shade_normal = normalize( rtTransformNormal( RT_OBJECT_TO_WORLD, shading_normal ) ); - float3 ffnormal = faceforward( world_shade_normal, -ray.direction, world_geo_normal ); - float3 color = Ka * ambient_light_color; - - float3 hit_point = ray.origin + t_hit * ray.direction; - - for(int i = 0; i < lights.size(); ++i) { - BasicLight light = lights[i]; - float3 L = normalize(light.pos - hit_point); - float nDl = dot( ffnormal, L); - - if( nDl > 0.0f ){ - // cast shadow ray - PerRayData_shadow shadow_prd; - shadow_prd.attenuation = make_float3(1.0f); - float Ldist = length(light.pos - hit_point); - optix::Ray shadow_ray( hit_point, L, shadow_ray_type, scene_epsilon, Ldist ); - rtTrace(top_shadower, shadow_ray, shadow_prd); - float3 light_attenuation = shadow_prd.attenuation; - - if( fmaxf(light_attenuation) > 0.0f ){ - float3 Lc = light.color * light_attenuation; - color += Kd * nDl * Lc; - - float3 H = normalize(L - ray.direction); - float nDh = dot( ffnormal, H ); - if(nDh > 0) - color += Ks * Lc * pow(nDh, phong_exp); - } - - } - } - - float importance = prd_radiance.importance * optix::luminance( reflectivity ); - - // reflection ray - if( importance > importance_cutoff && prd_radiance.depth < max_depth) { - PerRayData_radiance refl_prd; - refl_prd.importance = importance; - refl_prd.depth = prd_radiance.depth+1; - float3 R = reflect( ray.direction, ffnormal ); - optix::Ray refl_ray( hit_point, R, radiance_ray_type, scene_epsilon ); - rtTrace(top_object, refl_ray, refl_prd); - color += reflectivity * refl_prd.result; - } - - prd_radiance.result = color; -} - - -// -// Set pixel to solid color upon failure -// -RT_PROGRAM void exception() -{ - output_buffer[launch_index] = make_color( bad_color ); -} diff --git a/Source/OptiX/Private/cuda/already generated - tutorial/tutorial5.cu b/Source/OptiX/Private/cuda/already generated - tutorial/tutorial5.cu deleted file mode 100644 index 6f62ee72d9809fd3ed11b158f0d46d66561ee70a..0000000000000000000000000000000000000000 --- a/Source/OptiX/Private/cuda/already generated - tutorial/tutorial5.cu +++ /dev/null @@ -1,220 +0,0 @@ -/* - * Copyright (c) 2018 NVIDIA CORPORATION. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of NVIDIA CORPORATION nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "tutorial.h" - -rtDeclareVariable(float3, geometric_normal, attribute geometric_normal, ); -rtDeclareVariable(float3, shading_normal, attribute shading_normal, ); - -rtDeclareVariable(PerRayData_radiance, prd_radiance, rtPayload, ); -rtDeclareVariable(PerRayData_shadow, prd_shadow, rtPayload, ); - -rtDeclareVariable(optix::Ray, ray, rtCurrentRay, ); -rtDeclareVariable(float, t_hit, rtIntersectionDistance, ); -rtDeclareVariable(uint2, launch_index, rtLaunchIndex, ); - -rtDeclareVariable(unsigned int, radiance_ray_type, , ); -rtDeclareVariable(unsigned int, shadow_ray_type , , ); -rtDeclareVariable(float, scene_epsilon, , ); -rtDeclareVariable(rtObject, top_object, , ); - - -// -// Pinhole camera implementation -// -rtDeclareVariable(float3, eye, , ); -rtDeclareVariable(float3, U, , ); -rtDeclareVariable(float3, V, , ); -rtDeclareVariable(float3, W, , ); -rtDeclareVariable(float3, bad_color, , ); -rtBuffer<uchar4, 2> output_buffer; - -RT_PROGRAM void pinhole_camera() -{ - size_t2 screen = output_buffer.size(); - - float2 d = make_float2(launch_index) / make_float2(screen) * 2.f - 1.f; - float3 ray_origin = eye; - float3 ray_direction = normalize(d.x*U + d.y*V + W); - - optix::Ray ray(ray_origin, ray_direction, radiance_ray_type, scene_epsilon ); - - PerRayData_radiance prd; - prd.importance = 1.f; - prd.depth = 0; - - rtTrace(top_object, ray, prd); - - output_buffer[launch_index] = make_color( prd.result ); -} - - -// -// (NEW) -// Environment map background -// -rtTextureSampler<float4, 2> envmap; -RT_PROGRAM void envmap_miss() -{ - float theta = atan2f( ray.direction.x, ray.direction.z ); - float phi = M_PIf * 0.5f - acosf( ray.direction.y ); - float u = (theta + M_PIf) * (0.5f * M_1_PIf); - float v = 0.5f * ( 1.0f + sin(phi) ); - prd_radiance.result = make_float3( tex2D(envmap, u, v) ); -} - - -// -// Terminates and fully attenuates ray after any hit -// -RT_PROGRAM void any_hit_shadow() -{ - // this material is opaque, so it fully attenuates all shadow rays - prd_shadow.attenuation = make_float3(0); - - rtTerminateRay(); -} - - -// -// Phong surface shading with shadows -// -rtDeclareVariable(float3, Kd, , ); -rtDeclareVariable(float3, Ka, , ); -rtDeclareVariable(float3, Ks, , ); -rtDeclareVariable(float, phong_exp, , ); -rtDeclareVariable(float3, ambient_light_color, , ); -rtBuffer<BasicLight> lights; -rtDeclareVariable(rtObject, top_shadower, , ); - -RT_PROGRAM void closest_hit_radiance3() -{ - float3 world_geo_normal = normalize( rtTransformNormal( RT_OBJECT_TO_WORLD, geometric_normal ) ); - float3 world_shade_normal = normalize( rtTransformNormal( RT_OBJECT_TO_WORLD, shading_normal ) ); - float3 ffnormal = faceforward( world_shade_normal, -ray.direction, world_geo_normal ); - float3 color = Ka * ambient_light_color; - - float3 hit_point = ray.origin + t_hit * ray.direction; - - for(int i = 0; i < lights.size(); ++i) { - BasicLight light = lights[i]; - float3 L = normalize(light.pos - hit_point); - float nDl = dot( ffnormal, L); - - if( nDl > 0.0f ){ - // cast shadow ray - PerRayData_shadow shadow_prd; - shadow_prd.attenuation = make_float3(1.0f); - float Ldist = length(light.pos - hit_point); - optix::Ray shadow_ray( hit_point, L, shadow_ray_type, scene_epsilon, Ldist ); - rtTrace(top_shadower, shadow_ray, shadow_prd); - float3 light_attenuation = shadow_prd.attenuation; - - if( fmaxf(light_attenuation) > 0.0f ){ - float3 Lc = light.color * light_attenuation; - color += Kd * nDl * Lc; - - float3 H = normalize(L - ray.direction); - float nDh = dot( ffnormal, H ); - if(nDh > 0) - color += Ks * Lc * pow(nDh, phong_exp); - } - - } - } - prd_radiance.result = color; -} - - -// -// Phong surface shading with shadows and reflections -// -rtDeclareVariable(float3, reflectivity, , ); -rtDeclareVariable(float, importance_cutoff, , ); -rtDeclareVariable(int, max_depth, , ); - -RT_PROGRAM void floor_closest_hit_radiance4() -{ - float3 world_geo_normal = normalize( rtTransformNormal( RT_OBJECT_TO_WORLD, geometric_normal ) ); - float3 world_shade_normal = normalize( rtTransformNormal( RT_OBJECT_TO_WORLD, shading_normal ) ); - float3 ffnormal = faceforward( world_shade_normal, -ray.direction, world_geo_normal ); - float3 color = Ka * ambient_light_color; - - float3 hit_point = ray.origin + t_hit * ray.direction; - - for(int i = 0; i < lights.size(); ++i) { - BasicLight light = lights[i]; - float3 L = normalize(light.pos - hit_point); - float nDl = dot( ffnormal, L); - - if( nDl > 0.0f ){ - // cast shadow ray - PerRayData_shadow shadow_prd; - shadow_prd.attenuation = make_float3(1.0f); - float Ldist = length(light.pos - hit_point); - optix::Ray shadow_ray( hit_point, L, shadow_ray_type, scene_epsilon, Ldist ); - rtTrace(top_shadower, shadow_ray, shadow_prd); - float3 light_attenuation = shadow_prd.attenuation; - - if( fmaxf(light_attenuation) > 0.0f ){ - float3 Lc = light.color * light_attenuation; - color += Kd * nDl * Lc; - - float3 H = normalize(L - ray.direction); - float nDh = dot( ffnormal, H ); - if(nDh > 0) - color += Ks * Lc * pow(nDh, phong_exp); - } - - } - } - - float importance = prd_radiance.importance * optix::luminance( reflectivity ); - - // reflection ray - if( importance > importance_cutoff && prd_radiance.depth < max_depth) { - PerRayData_radiance refl_prd; - refl_prd.importance = importance; - refl_prd.depth = prd_radiance.depth+1; - float3 R = reflect( ray.direction, ffnormal ); - optix::Ray refl_ray( hit_point, R, radiance_ray_type, scene_epsilon ); - rtTrace(top_object, refl_ray, refl_prd); - color += reflectivity * refl_prd.result; - } - - prd_radiance.result = color; -} - - -// -// Set pixel to solid color upon failure -// -RT_PROGRAM void exception() -{ - output_buffer[launch_index] = make_color( bad_color ); -} diff --git a/Source/OptiX/Private/cuda/already generated - tutorial/tutorial6.cu b/Source/OptiX/Private/cuda/already generated - tutorial/tutorial6.cu deleted file mode 100644 index 44ab8694e0b769bfbbb05f8b685487f334f0c462..0000000000000000000000000000000000000000 --- a/Source/OptiX/Private/cuda/already generated - tutorial/tutorial6.cu +++ /dev/null @@ -1,222 +0,0 @@ -/* - * Copyright (c) 2018 NVIDIA CORPORATION. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of NVIDIA CORPORATION nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "tutorial.h" - -rtDeclareVariable(float3, geometric_normal, attribute geometric_normal, ); -rtDeclareVariable(float3, shading_normal, attribute shading_normal, ); - -rtDeclareVariable(PerRayData_radiance, prd_radiance, rtPayload, ); -rtDeclareVariable(PerRayData_shadow, prd_shadow, rtPayload, ); - -rtDeclareVariable(optix::Ray, ray, rtCurrentRay, ); -rtDeclareVariable(float, t_hit, rtIntersectionDistance, ); -rtDeclareVariable(uint2, launch_index, rtLaunchIndex, ); - -rtDeclareVariable(unsigned int, radiance_ray_type, , ); -rtDeclareVariable(unsigned int, shadow_ray_type , , ); -rtDeclareVariable(float, scene_epsilon, , ); -rtDeclareVariable(rtObject, top_object, , ); - - -// -// Pinhole camera implementation -// -rtDeclareVariable(float3, eye, , ); -rtDeclareVariable(float3, U, , ); -rtDeclareVariable(float3, V, , ); -rtDeclareVariable(float3, W, , ); -rtDeclareVariable(float3, bad_color, , ); -rtBuffer<uchar4, 2> output_buffer; - -RT_PROGRAM void pinhole_camera() -{ - size_t2 screen = output_buffer.size(); - - float2 d = make_float2(launch_index) / make_float2(screen) * 2.f - 1.f; - float3 ray_origin = eye; - float3 ray_direction = normalize(d.x*U + d.y*V + W); - - optix::Ray ray(ray_origin, ray_direction, radiance_ray_type, scene_epsilon ); - - PerRayData_radiance prd; - prd.importance = 1.f; - prd.depth = 0; - - rtTrace(top_object, ray, prd); - - output_buffer[launch_index] = make_color( prd.result ); -} - - -// -// Environment map background -// -rtTextureSampler<float4, 2> envmap; -RT_PROGRAM void envmap_miss() -{ - float theta = atan2f( ray.direction.x, ray.direction.z ); - float phi = M_PIf * 0.5f - acosf( ray.direction.y ); - float u = (theta + M_PIf) * (0.5f * M_1_PIf); - float v = 0.5f * ( 1.0f + sin(phi) ); - prd_radiance.result = make_float3( tex2D(envmap, u, v) ); -} - - -// -// Terminates and fully attenuates ray after any hit -// -RT_PROGRAM void any_hit_shadow() -{ - // this material is opaque, so it fully attenuates all shadow rays - prd_shadow.attenuation = make_float3(0); - - rtTerminateRay(); -} - - -// -// Phong surface shading with shadows -// -rtDeclareVariable(float3, Kd, , ); -rtDeclareVariable(float3, Ka, , ); -rtDeclareVariable(float3, Ks, , ); -rtDeclareVariable(float, phong_exp, , ); -rtDeclareVariable(float3, ambient_light_color, , ); -rtBuffer<BasicLight> lights; -rtDeclareVariable(rtObject, top_shadower, , ); - -RT_PROGRAM void closest_hit_radiance3() -{ - float3 world_geo_normal = normalize( rtTransformNormal( RT_OBJECT_TO_WORLD, geometric_normal ) ); - float3 world_shade_normal = normalize( rtTransformNormal( RT_OBJECT_TO_WORLD, shading_normal ) ); - float3 ffnormal = faceforward( world_shade_normal, -ray.direction, world_geo_normal ); - float3 color = Ka * ambient_light_color; - - float3 hit_point = ray.origin + t_hit * ray.direction; - - for(int i = 0; i < lights.size(); ++i) { - BasicLight light = lights[i]; - float3 L = normalize(light.pos - hit_point); - float nDl = dot( ffnormal, L); - - if( nDl > 0.0f ){ - // cast shadow ray - PerRayData_shadow shadow_prd; - shadow_prd.attenuation = make_float3(1.0f); - float Ldist = length(light.pos - hit_point); - optix::Ray shadow_ray( hit_point, L, shadow_ray_type, scene_epsilon, Ldist ); - rtTrace(top_shadower, shadow_ray, shadow_prd); - float3 light_attenuation = shadow_prd.attenuation; - - if( fmaxf(light_attenuation) > 0.0f ){ - float3 Lc = light.color * light_attenuation; - color += Kd * nDl * Lc; - - float3 H = normalize(L - ray.direction); - float nDh = dot( ffnormal, H ); - if(nDh > 0) - color += Ks * Lc * pow(nDh, phong_exp); - } - - } - } - prd_radiance.result = color; -} - - -// -// (UPDATED) -// Phong surface shading with shadows and schlick-approximated fresnel reflections -// -rtDeclareVariable(float3, reflectivity, , ); -rtDeclareVariable(float, importance_cutoff, , ); -rtDeclareVariable(int, max_depth, , ); -rtDeclareVariable(float3, reflectivity_n, , ); - -RT_PROGRAM void floor_closest_hit_radiance5() -{ - float3 world_geo_normal = normalize( rtTransformNormal( RT_OBJECT_TO_WORLD, geometric_normal ) ); - float3 world_shade_normal = normalize( rtTransformNormal( RT_OBJECT_TO_WORLD, shading_normal ) ); - float3 ffnormal = faceforward( world_shade_normal, -ray.direction, world_geo_normal ); - float3 color = Ka * ambient_light_color; - - float3 hit_point = ray.origin + t_hit * ray.direction; - - for(int i = 0; i < lights.size(); ++i) { - BasicLight light = lights[i]; - float3 L = normalize(light.pos - hit_point); - float nDl = dot( ffnormal, L); - - if( nDl > 0.0f ){ - // cast shadow ray - PerRayData_shadow shadow_prd; - shadow_prd.attenuation = make_float3(1.0f); - float Ldist = length(light.pos - hit_point); - optix::Ray shadow_ray( hit_point, L, shadow_ray_type, scene_epsilon, Ldist ); - rtTrace(top_shadower, shadow_ray, shadow_prd); - float3 light_attenuation = shadow_prd.attenuation; - - if( fmaxf(light_attenuation) > 0.0f ){ - float3 Lc = light.color * light_attenuation; - color += Kd * nDl * Lc; - - float3 H = normalize(L - ray.direction); - float nDh = dot( ffnormal, H ); - if(nDh > 0) - color += Ks * Lc * pow(nDh, phong_exp); - } - - } - } - - float3 r = schlick(-dot(ffnormal, ray.direction), reflectivity_n); - float importance = prd_radiance.importance * optix::luminance( r ); - - // reflection ray - if( importance > importance_cutoff && prd_radiance.depth < max_depth) { - PerRayData_radiance refl_prd; - refl_prd.importance = importance; - refl_prd.depth = prd_radiance.depth+1; - float3 R = reflect( ray.direction, ffnormal ); - optix::Ray refl_ray( hit_point, R, radiance_ray_type, scene_epsilon ); - rtTrace(top_object, refl_ray, refl_prd); - color += r * refl_prd.result; - } - - prd_radiance.result = color; -} - - -// -// Set pixel to solid color upon failure -// -RT_PROGRAM void exception() -{ - output_buffer[launch_index] = make_color( bad_color ); -} diff --git a/Source/OptiX/Private/cuda/already generated - tutorial/tutorial7.cu b/Source/OptiX/Private/cuda/already generated - tutorial/tutorial7.cu deleted file mode 100644 index 6c767b22dda5740b8e38f742f63723b549863a39..0000000000000000000000000000000000000000 --- a/Source/OptiX/Private/cuda/already generated - tutorial/tutorial7.cu +++ /dev/null @@ -1,238 +0,0 @@ -/* - * Copyright (c) 2018 NVIDIA CORPORATION. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of NVIDIA CORPORATION nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "tutorial.h" - -rtDeclareVariable(float3, geometric_normal, attribute geometric_normal, ); -rtDeclareVariable(float3, shading_normal, attribute shading_normal, ); - -rtDeclareVariable(PerRayData_radiance, prd_radiance, rtPayload, ); -rtDeclareVariable(PerRayData_shadow, prd_shadow, rtPayload, ); - -rtDeclareVariable(optix::Ray, ray, rtCurrentRay, ); -rtDeclareVariable(float, t_hit, rtIntersectionDistance, ); -rtDeclareVariable(uint2, launch_index, rtLaunchIndex, ); -rtDeclareVariable(unsigned int, radiance_ray_type, , ); -rtDeclareVariable(unsigned int, shadow_ray_type , , ); -rtDeclareVariable(float, scene_epsilon, , ); -rtDeclareVariable(rtObject, top_object, , ); - - -// -// Pinhole camera implementation -// -rtDeclareVariable(float3, eye, , ); -rtDeclareVariable(float3, U, , ); -rtDeclareVariable(float3, V, , ); -rtDeclareVariable(float3, W, , ); -rtDeclareVariable(float3, bad_color, , ); -rtBuffer<uchar4, 2> output_buffer; - -RT_PROGRAM void pinhole_camera() -{ - size_t2 screen = output_buffer.size(); - - float2 d = make_float2(launch_index) / make_float2(screen) * 2.f - 1.f; - float3 ray_origin = eye; - float3 ray_direction = normalize(d.x*U + d.y*V + W); - - optix::Ray ray(ray_origin, ray_direction, radiance_ray_type, scene_epsilon ); - - PerRayData_radiance prd; - prd.importance = 1.f; - prd.depth = 0; - - rtTrace(top_object, ray, prd); - - output_buffer[launch_index] = make_color( prd.result ); -} - - -// -// Environment map background -// -rtTextureSampler<float4, 2> envmap; -RT_PROGRAM void envmap_miss() -{ - float theta = atan2f( ray.direction.x, ray.direction.z ); - float phi = M_PIf * 0.5f - acosf( ray.direction.y ); - float u = (theta + M_PIf) * (0.5f * M_1_PIf); - float v = 0.5f * ( 1.0f + sin(phi) ); - prd_radiance.result = make_float3( tex2D(envmap, u, v) ); -} - - -// -// Terminates and fully attenuates ray after any hit -// -RT_PROGRAM void any_hit_shadow() -{ - // this material is opaque, so it fully attenuates all shadow rays - prd_shadow.attenuation = make_float3(0); - - rtTerminateRay(); -} - - -// -// Phong surface shading with shadows -// -rtDeclareVariable(float3, Ka, , ); -rtDeclareVariable(float3, Ks, , ); -rtDeclareVariable(float, phong_exp, , ); -rtDeclareVariable(float3, Kd, , ); -rtDeclareVariable(float3, ambient_light_color, , ); -rtBuffer<BasicLight> lights; -rtDeclareVariable(rtObject, top_shadower, , ); - -RT_PROGRAM void closest_hit_radiance3() -{ - float3 world_geo_normal = normalize( rtTransformNormal( RT_OBJECT_TO_WORLD, geometric_normal ) ); - float3 world_shade_normal = normalize( rtTransformNormal( RT_OBJECT_TO_WORLD, shading_normal ) ); - float3 ffnormal = faceforward( world_shade_normal, -ray.direction, world_geo_normal ); - float3 color = Ka * ambient_light_color; - - float3 hit_point = ray.origin + t_hit * ray.direction; - - for(int i = 0; i < lights.size(); ++i) { - BasicLight light = lights[i]; - float3 L = normalize(light.pos - hit_point); - float nDl = dot( ffnormal, L); - - if( nDl > 0.0f ){ - // cast shadow ray - PerRayData_shadow shadow_prd; - shadow_prd.attenuation = make_float3(1.0f); - float Ldist = length(light.pos - hit_point); - optix::Ray shadow_ray( hit_point, L, shadow_ray_type, scene_epsilon, Ldist ); - rtTrace(top_shadower, shadow_ray, shadow_prd); - float3 light_attenuation = shadow_prd.attenuation; - - if( fmaxf(light_attenuation) > 0.0f ){ - float3 Lc = light.color * light_attenuation; - color += Kd * nDl * Lc; - - float3 H = normalize(L - ray.direction); - float nDh = dot( ffnormal, H ); - if(nDh > 0) - color += Ks * Lc * pow(nDh, phong_exp); - } - - } - } - prd_radiance.result = color; -} - - -// -// (UPDATED) -// Phong surface shading with shadows and schlick-approximated fresnel reflections. -// Uses procedural texture to determine diffuse response. -// -rtDeclareVariable(float3, reflectivity, , ); -rtDeclareVariable(float, importance_cutoff, , ); -rtDeclareVariable(int, max_depth, , ); -rtDeclareVariable(float3, reflectivity_n, , ); -rtDeclareVariable(float3, tile_v0, , ); -rtDeclareVariable(float3, tile_v1, , ); -rtDeclareVariable(float3, crack_color, , ); -rtDeclareVariable(float, crack_width, , ); - -RT_PROGRAM void floor_closest_hit_radiance() -{ - float3 world_geo_normal = normalize( rtTransformNormal( RT_OBJECT_TO_WORLD, geometric_normal ) ); - float3 world_shade_normal = normalize( rtTransformNormal( RT_OBJECT_TO_WORLD, shading_normal ) ); - float3 ffnormal = faceforward( world_shade_normal, -ray.direction, world_geo_normal ); - float3 color = Ka * ambient_light_color; - - float3 hit_point = ray.origin + t_hit * ray.direction; - - float v0 = dot(tile_v0, hit_point); - float v1 = dot(tile_v1, hit_point); - v0 = v0 - floor(v0); - v1 = v1 - floor(v1); - - float3 local_Kd; - if( v0 > crack_width && v1 > crack_width ){ - local_Kd = Kd; - } else { - local_Kd = crack_color; - } - - for(int i = 0; i < lights.size(); ++i) { - BasicLight light = lights[i]; - float3 L = normalize(light.pos - hit_point); - float nDl = dot( ffnormal, L); - - if( nDl > 0.0f ){ - // cast shadow ray - PerRayData_shadow shadow_prd; - shadow_prd.attenuation = make_float3(1.0f); - float Ldist = length(light.pos - hit_point); - optix::Ray shadow_ray( hit_point, L, shadow_ray_type, scene_epsilon, Ldist ); - rtTrace(top_shadower, shadow_ray, shadow_prd); - float3 light_attenuation = shadow_prd.attenuation; - - if( fmaxf(light_attenuation) > 0.0f ){ - float3 Lc = light.color * light_attenuation; - color += local_Kd * nDl * Lc; - - float3 H = normalize(L - ray.direction); - float nDh = dot( ffnormal, H ); - if(nDh > 0) - color += Ks * Lc * pow(nDh, phong_exp); - } - - } - } - - float3 r = schlick(-dot(ffnormal, ray.direction), reflectivity_n); - float importance = prd_radiance.importance * optix::luminance( r ); - - // reflection ray - if( importance > importance_cutoff && prd_radiance.depth < max_depth) { - PerRayData_radiance refl_prd; - refl_prd.importance = importance; - refl_prd.depth = prd_radiance.depth+1; - float3 R = reflect( ray.direction, ffnormal ); - optix::Ray refl_ray( hit_point, R, radiance_ray_type, scene_epsilon ); - rtTrace(top_object, refl_ray, refl_prd); - color += r * refl_prd.result; - } - - prd_radiance.result = color; -} - - -// -// Set pixel to solid color upon failure -// -RT_PROGRAM void exception() -{ - output_buffer[launch_index] = make_color( bad_color ); -} diff --git a/Source/OptiX/Private/cuda/already generated - tutorial/tutorial8.cu b/Source/OptiX/Private/cuda/already generated - tutorial/tutorial8.cu deleted file mode 100644 index 58bcd972f7549ae83f0de65e8b8df7f2b853317e..0000000000000000000000000000000000000000 --- a/Source/OptiX/Private/cuda/already generated - tutorial/tutorial8.cu +++ /dev/null @@ -1,314 +0,0 @@ -/* - * Copyright (c) 2018 NVIDIA CORPORATION. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of NVIDIA CORPORATION nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "tutorial.h" - -rtDeclareVariable(float3, geometric_normal, attribute geometric_normal, ); -rtDeclareVariable(float3, shading_normal, attribute shading_normal, ); - -rtDeclareVariable(PerRayData_radiance, prd_radiance, rtPayload, ); -rtDeclareVariable(PerRayData_shadow, prd_shadow, rtPayload, ); - -rtDeclareVariable(optix::Ray, ray, rtCurrentRay, ); -rtDeclareVariable(float, t_hit, rtIntersectionDistance, ); -rtDeclareVariable(uint2, launch_index, rtLaunchIndex, ); - -rtDeclareVariable(unsigned int, radiance_ray_type, , ); -rtDeclareVariable(unsigned int, shadow_ray_type , , ); -rtDeclareVariable(float, scene_epsilon, , ); -rtDeclareVariable(rtObject, top_object, , ); - - -// -// Pinhole camera implementation -// -rtDeclareVariable(float3, eye, , ); -rtDeclareVariable(float3, U, , ); -rtDeclareVariable(float3, V, , ); -rtDeclareVariable(float3, W, , ); -rtDeclareVariable(float3, bad_color, , ); -rtBuffer<uchar4, 2> output_buffer; - -RT_PROGRAM void pinhole_camera() -{ - size_t2 screen = output_buffer.size(); - - float2 d = make_float2(launch_index) / make_float2(screen) * 2.f - 1.f; - float3 ray_origin = eye; - float3 ray_direction = normalize(d.x*U + d.y*V + W); - - optix::Ray ray(ray_origin, ray_direction, radiance_ray_type, scene_epsilon ); - - PerRayData_radiance prd; - prd.importance = 1.f; - prd.depth = 0; - - rtTrace(top_object, ray, prd); - - output_buffer[launch_index] = make_color( prd.result ); -} - - -// -// Environment map background -// -rtTextureSampler<float4, 2> envmap; -RT_PROGRAM void envmap_miss() -{ - float theta = atan2f( ray.direction.x, ray.direction.z ); - float phi = M_PIf * 0.5f - acosf( ray.direction.y ); - float u = (theta + M_PIf) * (0.5f * M_1_PIf); - float v = 0.5f * ( 1.0f + sin(phi) ); - prd_radiance.result = make_float3( tex2D(envmap, u, v) ); -} - - -// -// Terminates and fully attenuates ray after any hit -// -RT_PROGRAM void any_hit_shadow() -{ - // this material is opaque, so it fully attenuates all shadow rays - prd_shadow.attenuation = make_float3(0); - - rtTerminateRay(); -} - - -// -// (NEW) -// Procedural rusted metal surface shader -// - -/* - * Translated to CUDA C from Larry Gritz's LGRustyMetal.sl shader found at: - * http://renderman.org/RMR/Shaders/LGShaders/LGRustyMetal.sl - * - * Used with permission from tal AT renderman DOT org. - */ - -rtDeclareVariable(float, metalKa, , ) = 1; -rtDeclareVariable(float, metalKs, , ) = 1; -rtDeclareVariable(float, metalroughness, , ) = .1; -rtDeclareVariable(float, rustKa, , ) = 1; -rtDeclareVariable(float, rustKd, , ) = 1; -rtDeclareVariable(float3, rustcolor, , ) = {.437, .084, 0}; -rtDeclareVariable(float3, metalcolor, , ) = {.7, .7, .7}; -rtDeclareVariable(float, txtscale, , ) = .02; -rtDeclareVariable(float, rusty, , ) = 0.2; -rtDeclareVariable(float, rustbump, , ) = 0.85; -rtDeclareVariable(float3, ambient_light_color, , ); -rtBuffer<BasicLight> lights; -rtDeclareVariable(rtObject, top_shadower, , ); -rtDeclareVariable(float, importance_cutoff, , ); -rtDeclareVariable(int, max_depth, , ); -rtDeclareVariable(float3, reflectivity_n, , ); -#define MAXOCTAVES 6 - -rtTextureSampler<float, 3> noise_texture; -static __device__ __inline__ float snoise(float3 p) -{ - return tex3D(noise_texture, p.x, p.y, p.z) * 2 -1; -} - - -RT_PROGRAM void box_closest_hit_radiance() -{ - float3 world_geo_normal = normalize( rtTransformNormal( RT_OBJECT_TO_WORLD, geometric_normal ) ); - float3 world_shade_normal = normalize( rtTransformNormal( RT_OBJECT_TO_WORLD, shading_normal ) ); - float3 ffnormal = faceforward( world_shade_normal, -ray.direction, world_geo_normal ); - float3 hit_point = ray.origin + t_hit * ray.direction; - - /* Sum several octaves of abs(snoise), i.e. turbulence. Limit the - * number of octaves by the estimated change in PP between adjacent - * shading samples. - */ - float3 PP = txtscale * hit_point; - float a = 1; - float sum = 0; - for(int i = 0; i < MAXOCTAVES; i++ ){ - sum += a * fabs(snoise(PP)); - PP *= 2.0f; - a *= 0.5f; - } - - /* Scale the rust appropriately, modulate it by another noise - * computation, then sharpen it by squaring its value. - */ - float rustiness = step (1-rusty, clamp (sum,0.0f,1.0f)); - rustiness *= clamp (abs(snoise(PP)), 0.0f, .08f) / 0.08f; - rustiness *= rustiness; - - /* If we have any rust, calculate the color of the rust, taking into - * account the perturbed normal and shading like matte. - */ - float3 Nrust = ffnormal; - if (rustiness > 0) { - /* If it's rusty, also add a high frequency bumpiness to the normal */ - Nrust = normalize(ffnormal + rustbump * snoise(PP)); - Nrust = faceforward (Nrust, -ray.direction, world_geo_normal); - } - - float3 color = mix(metalcolor * metalKa, rustcolor * rustKa, rustiness) * ambient_light_color; - for(int i = 0; i < lights.size(); ++i) { - BasicLight light = lights[i]; - float3 L = normalize(light.pos - hit_point); - float nmDl = dot( ffnormal, L); - float nrDl = dot( Nrust, L); - - if( nmDl > 0.0f || nrDl > 0.0f ){ - // cast shadow ray - PerRayData_shadow shadow_prd; - shadow_prd.attenuation = make_float3(1.0f); - float Ldist = length(light.pos - hit_point); - optix::Ray shadow_ray( hit_point, L, shadow_ray_type, scene_epsilon, Ldist ); - rtTrace(top_shadower, shadow_ray, shadow_prd); - float3 light_attenuation = shadow_prd.attenuation; - - if( fmaxf(light_attenuation) > 0.0f ){ - float3 Lc = light.color * light_attenuation; - nrDl = max(nrDl * rustiness, 0.0f); - color += rustKd * rustcolor * nrDl * Lc; - - float r = nmDl * (1.0f-rustiness); - if(nmDl > 0.0f){ - float3 H = normalize(L - ray.direction); - float nmDh = dot( ffnormal, H ); - if(nmDh > 0) - color += r * metalKs * Lc * pow(nmDh, 1.f/metalroughness); - } - } - - } - } - - float3 r = schlick(-dot(ffnormal, ray.direction), reflectivity_n * (1-rustiness)); - float importance = prd_radiance.importance * optix::luminance( r ); - - // reflection ray - if( importance > importance_cutoff && prd_radiance.depth < max_depth) { - PerRayData_radiance refl_prd; - refl_prd.importance = importance; - refl_prd.depth = prd_radiance.depth+1; - float3 R = reflect( ray.direction, ffnormal ); - optix::Ray refl_ray( hit_point, R, radiance_ray_type, scene_epsilon ); - rtTrace(top_object, refl_ray, refl_prd); - color += r * refl_prd.result; - } - - prd_radiance.result = color; -} - - -// -// Phong surface shading with shadows and schlick-approximated fresnel reflections. -// Uses procedural texture to determine diffuse response. -// -rtDeclareVariable(float3, Ka, , ); -rtDeclareVariable(float3, Ks, , ); -rtDeclareVariable(float3, Kd, , ); -rtDeclareVariable(float, phong_exp, , ); -rtDeclareVariable(float3, reflectivity, , ); -rtDeclareVariable(float3, tile_v0, , ); -rtDeclareVariable(float3, tile_v1, , ); -rtDeclareVariable(float3, crack_color, , ); -rtDeclareVariable(float, crack_width, , ); - -RT_PROGRAM void floor_closest_hit_radiance() -{ - float3 world_geo_normal = normalize( rtTransformNormal( RT_OBJECT_TO_WORLD, geometric_normal ) ); - float3 world_shade_normal = normalize( rtTransformNormal( RT_OBJECT_TO_WORLD, shading_normal ) ); - float3 ffnormal = faceforward( world_shade_normal, -ray.direction, world_geo_normal ); - float3 color = Ka * ambient_light_color; - - float3 hit_point = ray.origin + t_hit * ray.direction; - - float v0 = dot(tile_v0, hit_point); - float v1 = dot(tile_v1, hit_point); - v0 = v0 - floor(v0); - v1 = v1 - floor(v1); - - float3 local_Kd; - if( v0 > crack_width && v1 > crack_width ){ - local_Kd = Kd; - } else { - local_Kd = crack_color; - } - - for(int i = 0; i < lights.size(); ++i) { - BasicLight light = lights[i]; - float3 L = normalize(light.pos - hit_point); - float nDl = dot( ffnormal, L); - - if( nDl > 0.0f ){ - // cast shadow ray - PerRayData_shadow shadow_prd; - shadow_prd.attenuation = make_float3(1.0f); - float Ldist = length(light.pos - hit_point); - optix::Ray shadow_ray( hit_point, L, shadow_ray_type, scene_epsilon, Ldist ); - rtTrace(top_shadower, shadow_ray, shadow_prd); - float3 light_attenuation = shadow_prd.attenuation; - - if( fmaxf(light_attenuation) > 0.0f ){ - float3 Lc = light.color * light_attenuation; - color += local_Kd * nDl * Lc; - - float3 H = normalize(L - ray.direction); - float nDh = dot( ffnormal, H ); - if(nDh > 0) - color += Ks * Lc * pow(nDh, phong_exp); - } - - } - } - - float3 r = schlick(-dot(ffnormal, ray.direction), reflectivity_n); - float importance = prd_radiance.importance * optix::luminance( r ); - - // reflection ray - if( importance > importance_cutoff && prd_radiance.depth < max_depth) { - PerRayData_radiance refl_prd; - refl_prd.importance = importance; - refl_prd.depth = prd_radiance.depth+1; - float3 R = reflect( ray.direction, ffnormal ); - optix::Ray refl_ray( hit_point, R, radiance_ray_type, scene_epsilon ); - rtTrace(top_object, refl_ray, refl_prd); - color += r * refl_prd.result; - } - - prd_radiance.result = color; -} - - -// -// Set pixel to solid color upon failure -// -RT_PROGRAM void exception() -{ - output_buffer[launch_index] = make_color( bad_color ); -} diff --git a/Source/OptiX/Private/cuda/already generated - tutorial/tutorial9.cu b/Source/OptiX/Private/cuda/already generated - tutorial/tutorial9.cu deleted file mode 100644 index cb12f8a9c970ee6231900e2972f225e4affb993c..0000000000000000000000000000000000000000 --- a/Source/OptiX/Private/cuda/already generated - tutorial/tutorial9.cu +++ /dev/null @@ -1,463 +0,0 @@ -/* - * Copyright (c) 2018 NVIDIA CORPORATION. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of NVIDIA CORPORATION nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "tutorial.h" -#include <optixu/optixu_aabb.h> - -rtDeclareVariable(float3, geometric_normal, attribute geometric_normal, ); -rtDeclareVariable(float3, shading_normal, attribute shading_normal, ); - -rtDeclareVariable(PerRayData_radiance, prd_radiance, rtPayload, ); -rtDeclareVariable(PerRayData_shadow, prd_shadow, rtPayload, ); - -rtDeclareVariable(optix::Ray, ray, rtCurrentRay, ); -rtDeclareVariable(float, t_hit, rtIntersectionDistance, ); -rtDeclareVariable(uint2, launch_index, rtLaunchIndex, ); - -rtDeclareVariable(unsigned int, radiance_ray_type, , ); -rtDeclareVariable(unsigned int, shadow_ray_type , , ); -rtDeclareVariable(float, scene_epsilon, , ); -rtDeclareVariable(rtObject, top_object, , ); - - -// -// Pinhole camera implementation -// -rtDeclareVariable(float3, eye, , ); -rtDeclareVariable(float3, U, , ); -rtDeclareVariable(float3, V, , ); -rtDeclareVariable(float3, W, , ); -rtDeclareVariable(float3, bad_color, , ); -rtBuffer<uchar4, 2> output_buffer; - -RT_PROGRAM void pinhole_camera() -{ - size_t2 screen = output_buffer.size(); - - float2 d = make_float2(launch_index) / make_float2(screen) * 2.f - 1.f; - float3 ray_origin = eye; - float3 ray_direction = normalize(d.x*U + d.y*V + W); - - optix::Ray ray(ray_origin, ray_direction, radiance_ray_type, scene_epsilon ); - - PerRayData_radiance prd; - prd.importance = 1.f; - prd.depth = 0; - - rtTrace(top_object, ray, prd); - - output_buffer[launch_index] = make_color( prd.result ); -} - - -// -// Environment map background -// -rtTextureSampler<float4, 2> envmap; -RT_PROGRAM void envmap_miss() -{ - float theta = atan2f( ray.direction.x, ray.direction.z ); - float phi = M_PIf * 0.5f - acosf( ray.direction.y ); - float u = (theta + M_PIf) * (0.5f * M_1_PIf); - float v = 0.5f * ( 1.0f + sin(phi) ); - prd_radiance.result = make_float3( tex2D(envmap, u, v) ); -} - - -// -// Terminates and fully attenuates ray after any hit -// -RT_PROGRAM void any_hit_shadow() -{ - // this material is opaque, so it fully attenuates all shadow rays - prd_shadow.attenuation = make_float3(0); - - rtTerminateRay(); -} - - -// -// Procedural rusted metal surface shader -// - -/* - * Translated to CUDA C from Larry Gritz's LGRustyMetal.sl shader found at: - * http://renderman.org/RMR/Shaders/LGShaders/LGRustyMetal.sl - * - * Used with permission from tal AT renderman DOT org. - */ - -rtDeclareVariable(float3, ambient_light_color, , ); -rtBuffer<BasicLight> lights; -rtDeclareVariable(rtObject, top_shadower, , ); -rtDeclareVariable(float, importance_cutoff, , ); -rtDeclareVariable(int, max_depth, , ); -rtDeclareVariable(float3, reflectivity_n, , ); - -rtDeclareVariable(float, metalKa, , ) = 1; -rtDeclareVariable(float, metalKs, , ) = 1; -rtDeclareVariable(float, metalroughness, , ) = .1; -rtDeclareVariable(float, rustKa, , ) = 1; -rtDeclareVariable(float, rustKd, , ) = 1; -rtDeclareVariable(float3, rustcolor, , ) = {.437, .084, 0}; -rtDeclareVariable(float3, metalcolor, , ) = {.7, .7, .7}; -rtDeclareVariable(float, txtscale, , ) = .02; -rtDeclareVariable(float, rusty, , ) = 0.2; -rtDeclareVariable(float, rustbump, , ) = 0.85; -#define MAXOCTAVES 6 - -rtTextureSampler<float, 3> noise_texture; -static __device__ __inline__ float snoise(float3 p) -{ - return tex3D(noise_texture, p.x, p.y, p.z) * 2 -1; -} - -RT_PROGRAM void box_closest_hit_radiance() -{ - float3 world_geo_normal = normalize( rtTransformNormal( RT_OBJECT_TO_WORLD, geometric_normal ) ); - float3 world_shade_normal = normalize( rtTransformNormal( RT_OBJECT_TO_WORLD, shading_normal ) ); - float3 ffnormal = faceforward( world_shade_normal, -ray.direction, world_geo_normal ); - float3 hit_point = ray.origin + t_hit * ray.direction; - - /* Sum several octaves of abs(snoise), i.e. turbulence. Limit the - * number of octaves by the estimated change in PP between adjacent - * shading samples. - */ - float3 PP = txtscale * hit_point; - float a = 1; - float sum = 0; - for(int i = 0; i < MAXOCTAVES; i++ ){ - sum += a * fabs(snoise(PP)); - PP *= 2.0f; - a *= 0.5f; - } - - /* Scale the rust appropriately, modulate it by another noise - * computation, then sharpen it by squaring its value. - */ - float rustiness = step (1-rusty, clamp (sum,0.0f,1.0f)); - rustiness *= clamp (abs(snoise(PP)), 0.0f, .08f) / 0.08f; - rustiness *= rustiness; - - /* If we have any rust, calculate the color of the rust, taking into - * account the perturbed normal and shading like matte. - */ - float3 Nrust = ffnormal; - if (rustiness > 0) { - /* If it's rusty, also add a high frequency bumpiness to the normal */ - Nrust = normalize(ffnormal + rustbump * snoise(PP)); - Nrust = faceforward (Nrust, -ray.direction, world_geo_normal); - } - - float3 color = mix(metalcolor * metalKa, rustcolor * rustKa, rustiness) * ambient_light_color; - for(int i = 0; i < lights.size(); ++i) { - BasicLight light = lights[i]; - float3 L = normalize(light.pos - hit_point); - float nmDl = dot( ffnormal, L); - float nrDl = dot( Nrust, L); - - if( nmDl > 0.0f || nrDl > 0.0f ){ - // cast shadow ray - PerRayData_shadow shadow_prd; - shadow_prd.attenuation = make_float3(1.0f); - float Ldist = length(light.pos - hit_point); - optix::Ray shadow_ray( hit_point, L, shadow_ray_type, scene_epsilon, Ldist ); - rtTrace(top_shadower, shadow_ray, shadow_prd); - float3 light_attenuation = shadow_prd.attenuation; - - if( fmaxf(light_attenuation) > 0.0f ){ - float3 Lc = light.color * light_attenuation; - nrDl = max(nrDl * rustiness, 0.0f); - color += rustKd * rustcolor * nrDl * Lc; - - float r = nmDl * (1.0f-rustiness); - if(nmDl > 0.0f){ - float3 H = normalize(L - ray.direction); - float nmDh = dot( ffnormal, H ); - if(nmDh > 0) - color += r * metalKs * Lc * pow(nmDh, 1.f/metalroughness); - } - } - - } - } - - float3 r = schlick(-dot(ffnormal, ray.direction), reflectivity_n * (1-rustiness)); - float importance = prd_radiance.importance * optix::luminance( r ); - - // reflection ray - if( importance > importance_cutoff && prd_radiance.depth < max_depth) { - PerRayData_radiance refl_prd; - refl_prd.importance = importance; - refl_prd.depth = prd_radiance.depth+1; - float3 R = reflect( ray.direction, ffnormal ); - optix::Ray refl_ray( hit_point, R, radiance_ray_type, scene_epsilon ); - rtTrace(top_object, refl_ray, refl_prd); - color += r * refl_prd.result; - } - - prd_radiance.result = color; -} - - -// -// Phong surface shading with shadows and schlick-approximated fresnel reflections. -// Uses procedural texture to determine diffuse response. -// -rtDeclareVariable(float, phong_exp, , ); -rtDeclareVariable(float3, tile_v0, , ); -rtDeclareVariable(float3, tile_v1, , ); -rtDeclareVariable(float3, crack_color, , ); -rtDeclareVariable(float, crack_width, , ); -rtDeclareVariable(float3, Ka, , ); -rtDeclareVariable(float3, Ks, , ); -rtDeclareVariable(float3, Kd, , ); - -RT_PROGRAM void floor_closest_hit_radiance() -{ - float3 world_geo_normal = normalize( rtTransformNormal( RT_OBJECT_TO_WORLD, geometric_normal ) ); - float3 world_shade_normal = normalize( rtTransformNormal( RT_OBJECT_TO_WORLD, shading_normal ) ); - float3 ffnormal = faceforward( world_shade_normal, -ray.direction, world_geo_normal ); - float3 color = Ka * ambient_light_color; - - float3 hit_point = ray.origin + t_hit * ray.direction; - - float v0 = dot(tile_v0, hit_point); - float v1 = dot(tile_v1, hit_point); - v0 = v0 - floor(v0); - v1 = v1 - floor(v1); - - float3 local_Kd; - if( v0 > crack_width && v1 > crack_width ){ - local_Kd = Kd; - } else { - local_Kd = crack_color; - } - - for(int i = 0; i < lights.size(); ++i) { - BasicLight light = lights[i]; - float3 L = normalize(light.pos - hit_point); - float nDl = dot( ffnormal, L); - - if( nDl > 0.0f ){ - // cast shadow ray - PerRayData_shadow shadow_prd; - shadow_prd.attenuation = make_float3(1.0f); - float Ldist = length(light.pos - hit_point); - optix::Ray shadow_ray( hit_point, L, shadow_ray_type, scene_epsilon, Ldist ); - rtTrace(top_shadower, shadow_ray, shadow_prd); - float3 light_attenuation = shadow_prd.attenuation; - - if( fmaxf(light_attenuation) > 0.0f ){ - float3 Lc = light.color * light_attenuation; - color += local_Kd * nDl * Lc; - - float3 H = normalize(L - ray.direction); - float nDh = dot( ffnormal, H ); - if(nDh > 0) - color += Ks * Lc * pow(nDh, phong_exp); - } - - } - } - - float3 r = schlick(-dot(ffnormal, ray.direction), reflectivity_n); - float importance = prd_radiance.importance * optix::luminance( r ); - - // reflection ray - if( importance > importance_cutoff && prd_radiance.depth < max_depth) { - PerRayData_radiance refl_prd; - refl_prd.importance = importance; - refl_prd.depth = prd_radiance.depth+1; - float3 R = reflect( ray.direction, ffnormal ); - optix::Ray refl_ray( hit_point, R, radiance_ray_type, scene_epsilon ); - rtTrace(top_object, refl_ray, refl_prd); - color += r * refl_prd.result; - } - - prd_radiance.result = color; -} - - -// -// (NEW) -// Bounding box program for programmable convex hull primitive -// -rtDeclareVariable(float3, chull_bbmin, , ); -rtDeclareVariable(float3, chull_bbmax, , ); -RT_PROGRAM void chull_bounds (int primIdx, float result[6]) -{ - optix::Aabb* aabb = (optix::Aabb*)result; - aabb->m_min = chull_bbmin; - aabb->m_max = chull_bbmax; -} - - -// -// (NEW) -// Intersection program for programmable convex hull primitive -// -rtBuffer<float4> planes; -RT_PROGRAM void chull_intersect(int primIdx) -{ - int n = planes.size(); - float t0 = -FLT_MAX; - float t1 = FLT_MAX; - float3 t0_normal = make_float3(0); - float3 t1_normal = make_float3(0); - for(int i = 0; i < n && t0 < t1; ++i ) { - float4 plane = planes[i]; - float3 n = make_float3(plane); - float d = plane.w; - - float denom = dot(n, ray.direction); - float t = -(d + dot(n, ray.origin))/denom; - if( denom < 0){ - // enter - if(t > t0){ - t0 = t; - t0_normal = n; - } - } else { - //exit - if(t < t1){ - t1 = t; - t1_normal = n; - } - } - } - - if(t0 > t1) - return; - - if(rtPotentialIntersection( t0 )){ - shading_normal = geometric_normal = t0_normal; - rtReportIntersection(0); - } else if(rtPotentialIntersection( t1 )){ - shading_normal = geometric_normal = t1_normal; - rtReportIntersection(0); - } -} - - -// -// (NEW) -// Dielectric surface shader -// -rtDeclareVariable(float3, cutoff_color, , ); -rtDeclareVariable(float, fresnel_exponent, , ); -rtDeclareVariable(float, fresnel_minimum, , ); -rtDeclareVariable(float, fresnel_maximum, , ); -rtDeclareVariable(float, refraction_index, , ); -rtDeclareVariable(int, refraction_maxdepth, , ); -rtDeclareVariable(int, reflection_maxdepth, , ); -rtDeclareVariable(float3, refraction_color, , ); -rtDeclareVariable(float3, reflection_color, , ); -rtDeclareVariable(float3, extinction_constant, , ); -RT_PROGRAM void glass_closest_hit_radiance() -{ - // intersection vectors - const float3 h = ray.origin + t_hit * ray.direction; // hitpoint - const float3 n = normalize(rtTransformNormal(RT_OBJECT_TO_WORLD, shading_normal)); // normal - const float3 i = ray.direction; // incident direction - - float reflection = 1.0f; - float3 result = make_float3(0.0f); - - float3 beer_attenuation; - if(dot(n, ray.direction) > 0){ - // Beer's law attenuation - beer_attenuation = exp(extinction_constant * t_hit); - } else { - beer_attenuation = make_float3(1); - } - - // refraction - if (prd_radiance.depth < min(refraction_maxdepth, max_depth)) - { - float3 t; // transmission direction - if ( refract(t, i, n, refraction_index) ) - { - - // check for external or internal reflection - float cos_theta = dot(i, n); - if (cos_theta < 0.0f) - cos_theta = -cos_theta; - else - cos_theta = dot(t, n); - - reflection = fresnel_schlick(cos_theta, fresnel_exponent, fresnel_minimum, fresnel_maximum); - - float importance = prd_radiance.importance * (1.0f-reflection) * optix::luminance( refraction_color * beer_attenuation ); - if ( importance > importance_cutoff ) { - optix::Ray ray( h, t, radiance_ray_type, scene_epsilon ); - PerRayData_radiance refr_prd; - refr_prd.depth = prd_radiance.depth+1; - refr_prd.importance = importance; - - rtTrace( top_object, ray, refr_prd ); - result += (1.0f - reflection) * refraction_color * refr_prd.result; - } else { - result += (1.0f - reflection) * refraction_color * cutoff_color; - } - } - // else TIR - } - - // reflection - if (prd_radiance.depth < min(reflection_maxdepth, max_depth)) - { - float3 r = reflect(i, n); - - float importance = prd_radiance.importance * reflection * optix::luminance( reflection_color * beer_attenuation ); - if ( importance > importance_cutoff ) { - optix::Ray ray( h, r, radiance_ray_type, scene_epsilon ); - PerRayData_radiance refl_prd; - refl_prd.depth = prd_radiance.depth+1; - refl_prd.importance = importance; - - rtTrace( top_object, ray, refl_prd ); - result += reflection * reflection_color * refl_prd.result; - } else { - result += reflection * reflection_color * cutoff_color; - } - } - - result = result * beer_attenuation; - - prd_radiance.result = result; -} - - -// -// Set pixel to solid color upon failure -// -RT_PROGRAM void exception() -{ - output_buffer[launch_index] = make_color( bad_color ); -} diff --git a/Source/OptiX/Private/cuda/box_intersect.cu b/Source/OptiX/Private/cuda/box_intersect.cu new file mode 100644 index 0000000000000000000000000000000000000000..d6d7dbadce8f8a2d96fca5fca423ca8d142dee24 --- /dev/null +++ b/Source/OptiX/Private/cuda/box_intersect.cu @@ -0,0 +1,74 @@ +//------------------------------------------------------------------------------ +// Project Phoenix +// +// Copyright (c) 2017-2018 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualization Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed under the 3-Clause BSD License (the "License"); +// you may not use this file except in compliance with the License. +// See the file LICENSE for the full text. +// You may obtain a copy of the License at +// +// https://opensource.org/licenses/BSD-3-Clause +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//------------------------------------------------------------------------------ + +#include <optix.h> +#include <optix_world.h> +#include "lens_intersections.h" + +using namespace optix; + +rtDeclareVariable(float3, size, , ); +rtDeclareVariable(float, scene_epsilon, , ); + +rtDeclareVariable(optix::Ray, ray, rtCurrentRay, ); + +rtDeclareVariable(float2, texture_coord, attribute texture_coord, ); + +RT_PROGRAM void intersect(int primIdx) +{ + float3 bounds[] = {-size/2.0f, size/2.0f}; + float3 invDir = 1.0f / ray.direction; + uint3 sign = {invDir.x < 0, invDir.y < 0, invDir.z < 0}; + + float tmin = (bounds[sign.x].x - ray.origin.x) * invDir.x; + float tmax = (bounds[1 - sign.x].x - ray.origin.x) * invDir.x; + float tymin = (bounds[sign.y].y - ray.origin.y) * invDir.y; + float tymax = (bounds[1 - sign.y].y - ray.origin.y) * invDir.y; + + if ((tmin > tymax) || (tymin > tmax)) return; + if (tymin > tmin) tmin = tymin; + if (tymax < tmax) tmax = tymax; + + float tzmin = (bounds[sign.z].z - ray.origin.z) * invDir.z; + float tzmax = (bounds[1 - sign.z].z - ray.origin.z) * invDir.z; + + if ((tmin > tzmax) || (tzmin > tmax)) return; + if (tzmin > tmin) tmin = tzmin; + //if (tzmax < tmax) tmax = tzmax; + + if(rtPotentialIntersection(tmin)) { + float3 hit_point = ray.origin + ray.direction * tmin; + texture_coord = make_float2(-1.0f, -1.0f); + if(tmin != tzmin && tmin != tymin){ //x-side + texture_coord = (make_float2(hit_point.y, hit_point.z) - make_float2(-size.y / 2.0f, -size.z / 2.0f)) + /make_float2(size.y, size.z); + //rtPrintf("%f, %f\n", texture_coord.x, texture_coord.y); + } + rtReportIntersection(0); + } +} + +RT_PROGRAM void bounds (int, optix::Aabb* aabb) +{ + aabb->m_min = -size/2.0f; + aabb->m_max = size/2.0f; +} diff --git a/Source/OptiX/Private/cuda/laser_caster.cu b/Source/OptiX/Private/cuda/laser_caster.cu deleted file mode 100644 index 5b0e06eaa8d1be9f4e3e269717209b7f40bc76d7..0000000000000000000000000000000000000000 --- a/Source/OptiX/Private/cuda/laser_caster.cu +++ /dev/null @@ -1,105 +0,0 @@ -//------------------------------------------------------------------------------ -// Project Phoenix -// -// Copyright (c) 2017-2018 RWTH Aachen University, Germany, -// Virtual Reality & Immersive Visualization Group. -//------------------------------------------------------------------------------ -// License -// -// Licensed under the 3-Clause BSD License (the "License"); -// you may not use this file except in compliance with the License. -// See the file LICENSE for the full text. -// You may obtain a copy of the License at -// -// https://opensource.org/licenses/BSD-3-Clause -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -//------------------------------------------------------------------------------ - -#include <optix.h> -#include <optixu/optixu_math_namespace.h> -#include <optixu/optixu_matrix_namespace.h> -#include "prd.h" -#include "helpers.h" -#include "random.h" - - -#define PERCENTILE 1.47579f - -using namespace optix; - -rtDeclareVariable(uint3, launch_index, rtLaunchIndex, ); -rtDeclareVariable(uint3, launch_dim, rtLaunchDim, ); -rtDeclareVariable(rtObject, top_object, , ); -rtDeclareVariable(float, scene_epsilon, , ); -rtDeclareVariable(int, max_depth_laser, , ); - -rtDeclareVariable(unsigned int, random_frame_seed, , ); - -rtDeclareVariable(float3, laser_origin, , ); -rtDeclareVariable(float3, laser_forward, , ); -rtDeclareVariable(float3, laser_right, , ); -rtDeclareVariable(float3, laser_up, , ); -rtDeclareVariable(Matrix4x4, laser_rot, , ); - -rtDeclareVariable(float, laserBeamWidth, , ); -rtDeclareVariable(float, laserSize, , ); - -rtBuffer<int, 2> laserIndex; -rtBuffer<float3, 2> laserDir; -rtBuffer<float4, 1> result_laser; - - -RT_PROGRAM void laser_caster(){ - - float2 d = make_float2(launch_index.x, launch_index.y) / make_float2(launch_dim.x, launch_dim.y) - make_float2(0.5f, 0.5f); - float3 ray_origin = laser_origin + laser_right * laserSize * d.x + laser_up * laserSize * d.y; - - //Uniform random - unsigned int seed = tea<16>(launch_dim.x*launch_index.y+launch_index.x*launch_index.z, random_frame_seed); - float2 random = make_float2(rnd(seed), rnd(seed)); - //convert to normal distrubution - float r = sqrtf(-2*log(random.x)); - float theta = 2*3.141592654f*random.y; - random = clamp(make_float2(r*cosf(theta), r*sinf(theta)), -4.5f, 4.5f) * laserBeamWidth * 0.5 /PERCENTILE; - ray_origin += (launch_index.z != 0) * (laser_right * random.x + laser_up * random.y); - - PerRayData_radiance_iterative prd; - optix::Ray ray(ray_origin, laser_forward, /*ray type*/ 1, scene_epsilon ); - prd.depth = 0; - prd.done = false; - prd.hit_lens = false; //track if the ray ever hit the lens - prd.power = (launch_index.z > 0) * 1; //No power for launch index 0 - - // next ray to be traced - prd.origin = ray_origin; - - Matrix3x3 laser_rot3x3 = make_matrix3x3(laser_rot); - - prd.direction = laser_rot3x3 * normalize(make_float3(1,1,-1)*laserDir[make_uint2(launch_index)]); - - unsigned int startIndex = (launch_index.y * 50 + launch_index.x) * max_depth_laser * 2; - - bool cast_ray = laserIndex[make_uint2(launch_index)] < 0; - for(int i = 0; i < max_depth_laser * 2; i += 2){ - //Determine if this launch_index, depth or last ray should trigger new cast - if(cast_ray || prd.done || prd.depth >= max_depth_laser){ // just write rest of data as "invalid" - if(launch_index.z == 0) result_laser[startIndex + i] = make_float4(0,-1,0,1); - if(launch_index.z == 0) result_laser[startIndex + i + 1] = make_float4(0,-1,0,1); - continue; - } - if(launch_index.z == 0) result_laser[startIndex + i] = make_float4(prd.origin,1); - - ray.origin = prd.origin; - ray.direction = prd.direction; - rtTrace(top_object, ray, prd); - - // Update ray data for the next path segment - prd.depth++; - if(launch_index.z == 0) result_laser[startIndex + i + 1] = make_float4(prd.origin,1); - } -} \ No newline at end of file diff --git a/Source/OptiX/Private/cuda/laser_target.cu b/Source/OptiX/Private/cuda/laser_target.cu deleted file mode 100644 index 324156314b7bbf79e98e11c8782917846b2f5e3c..0000000000000000000000000000000000000000 --- a/Source/OptiX/Private/cuda/laser_target.cu +++ /dev/null @@ -1,80 +0,0 @@ -//------------------------------------------------------------------------------ -// Project Phoenix -// -// Copyright (c) 2017-2018 RWTH Aachen University, Germany, -// Virtual Reality & Immersive Visualization Group. -//------------------------------------------------------------------------------ -// License -// -// Licensed under the 3-Clause BSD License (the "License"); -// you may not use this file except in compliance with the License. -// See the file LICENSE for the full text. -// You may obtain a copy of the License at -// -// https://opensource.org/licenses/BSD-3-Clause -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -//------------------------------------------------------------------------------ - -#include <optix.h> -#include <optix_world.h> - -using namespace optix; - -rtDeclareVariable(float3, p1, , ); -rtDeclareVariable(float3, p2, , ); -rtDeclareVariable(float2, stretchXY1, , ); -rtDeclareVariable(float2, stretchXZ2, , ); - -rtDeclareVariable(float, scene_epsilon, , ); - -rtDeclareVariable(optix::Ray, ray, rtCurrentRay, ); - -rtDeclareVariable(float2, texture_coord, attribute texture_coord, ); -rtDeclareVariable(int, writeable_surface, attribute writeable_surface, ); - -RT_PROGRAM void intersect(int primIdx) -{ - //Hit Z? - float t_1 = (p1.x - ray.origin.x) * (1.0f / ray.direction.x); - float3 hp = ray.origin + ray.direction * t_1; - float2 rel_size_z = (make_float2(hp.y, hp.z) - (make_float2(p1.y, p1.z) - stretchXY1/2))/stretchXY1; - bool hit_z = rel_size_z.x < 1 && rel_size_z.y < 1 && rel_size_z.x >= 0 && rel_size_z.y >= 0; - - //Hit X? - ignore this for now - //float t_2 = (p2.x - ray.origin.x) * (1.0f / ray.direction.x); - //float3 hp = ray.origin + ray.direction * t_2; - //float2 rel_size_x = (make_float2(hp.z, hp.y) - (make_float2(p2.z, p2.y) - stretchXZ2/2))/stretchXZ2; - //bool hit_x = rel_size_x.x < 1 && rel_size_x.y < 1 && rel_size_x.x >= 0 && rel_size_x.y >= 0; - - //Which one is closer - //float tmin = fminf(t_1 + (!hit_z > 0)*0x7f800000 , t_2 + (!hit_x > 0)*100000); //0x7f800000 == +INFINITY - //float2 rel_size = (tmin == t_1) * rel_size_z + (tmin == t_2) * rel_size_x; - if((hit_z) && rtPotentialIntersection(t_1)) { - texture_coord = make_float2(1 - rel_size_z.x, 1 - rel_size_z.y); - writeable_surface = 1; // don't need this as well - rtReportIntersection(0); - } -} - -RT_PROGRAM void bounds (int, optix::Aabb* aabb) -{ - - // Make this a plane with x == 0 - - //float min_x = fminf(p1.x - stretchXY1.x/2, p2.x); - //float min_y = fminf(p1.y, p2.y - stretchXY1.x / 2); - //float min_z = fminf(p1.z - stretchXY1.y / 2, p2.z - stretchXZ2.y / 2); - //// - //float max_x = fmaxf(p1.x + stretchXY1.x/2, p2.x); - //float max_y = fmaxf(p1.y, p2.y - stretchXY1.y / 2); - //float max_z = fmaxf(p1.z - stretchXY1.y / 2, p2.z - stretchXZ2.y / 2); - - - aabb->m_min = make_float3(-0.01, p1.y - stretchXY1.x / 2, p1.z - stretchXY1.y / 2); - aabb->m_max = make_float3(0.01, p1.y + stretchXY1.x / 2, p1.z + stretchXY1.y / 2); -} diff --git a/Source/OptiX/Private/cuda/lens_parametric.cu b/Source/OptiX/Private/cuda/lens_parametric.cu new file mode 100644 index 0000000000000000000000000000000000000000..b85ba9fa40ba31dffb9375b7689decc9bbe39c09 --- /dev/null +++ b/Source/OptiX/Private/cuda/lens_parametric.cu @@ -0,0 +1,110 @@ +//------------------------------------------------------------------------------ +// Project Phoenix +// +// Copyright (c) 2017-2018 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualization Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed under the 3-Clause BSD License (the "License"); +// you may not use this file except in compliance with the License. +// See the file LICENSE for the full text. +// You may obtain a copy of the License at +// +// https://opensource.org/licenses/BSD-3-Clause +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//------------------------------------------------------------------------------ + +#include <optix.h> +#include <optix_world.h> +#include "lens_intersections.h" + +using namespace optix; + +rtDeclareVariable(float, lensRadius, , ); +rtDeclareVariable(float3, orientation, , ); +rtDeclareVariable(float3, center, , ); +rtDeclareVariable(float, radius, , ); +rtDeclareVariable(float, radius2, , ); +rtDeclareVariable(float, halfCylinderLength, , ); +rtDeclareVariable(float, scene_epsilon, , ); + +//1==convex, 2==concave, 0==plane +rtDeclareVariable(int, side1Type, , ); +rtDeclareVariable(int, side2Type, , ); + +rtDeclareVariable(optix::Ray, ray, rtCurrentRay, ); + +rtDeclareVariable(float3, geometric_normal, attribute geometric_normal, ); +rtDeclareVariable(float3, shading_normal, attribute shading_normal, ); +rtDeclareVariable(float3, front_hit_point, attribute front_hit_point, ); +rtDeclareVariable(float3, back_hit_point, attribute back_hit_point, ); + +RT_PROGRAM void intersect(int primIdx) +{ + perHitData h1; + if(side1Type != 0){ + int mult = side1Type; + if (side1Type == 2) mult = -1; + + float dist = -sqrtf(radius*radius - powf(lensRadius,2)) + mult*halfCylinderLength; + float3 nCenter = center + mult *orientation*dist; + h1.t = circleIntersect(radius, nCenter, ray, mult*orientation, lensRadius, scene_epsilon); + h1.p = ray.origin + h1.t*ray.direction; + h1.normal = mult *(h1.p - nCenter) / radius; + } else{ + h1.t = intersectPlane(center + orientation*(halfCylinderLength), ray, -orientation, lensRadius, scene_epsilon); + h1.p = ray.origin + h1.t*ray.direction; + h1.normal = orientation; + } + + perHitData h2; + if(side2Type != 0){ + int mult = side2Type; + if (side2Type == 2) mult = -1; + float dist = -sqrtf(radius2*radius2 - powf(lensRadius,2)) + mult *halfCylinderLength; + float3 nCenter = center - mult *orientation*dist; + h2.t = circleIntersect(radius2, nCenter, ray, -mult *orientation, lensRadius, scene_epsilon); + h2.p = ray.origin + h2.t*ray.direction; + h2.normal = mult *(h2.p - nCenter) / radius2; + } else{ + h2.t = intersectPlane(center - orientation*(halfCylinderLength), ray, orientation, lensRadius, scene_epsilon); + h2.p = ray.origin + h2.t*ray.direction; + h2.normal = -orientation; + } + + perHitData h3; + h3.t = cylinderIntersect(halfCylinderLength*2, center, ray, orientation, lensRadius, scene_epsilon); + h3.p = ray.origin + h3.t*ray.direction; + float3 inner = dot(h3.p - center, orientation) * orientation + center; + h3.normal = normalize(h3.p - inner); + + perHitData closest = nearestButPositivHit(h1, h2, scene_epsilon); + closest = nearestButPositivHit(closest, h3, scene_epsilon); + + if(rtPotentialIntersection(closest.t) ) { + int b = (dot(closest.p - ray.origin, closest.normal) > 0.0f) * 2 - 1; //look from inside out yes == 1, no == -1 + + front_hit_point = closest.p + -b * closest.normal * scene_epsilon; + back_hit_point = closest.p + b * closest.normal * scene_epsilon; + + shading_normal = geometric_normal = closest.normal; + rtReportIntersection( 0 ); + } +} + +RT_PROGRAM void bounds (int, optix::Aabb* aabb) +{ + //Size for double convex case should be the biggest + float halfSphere1 = (radius - sqrtf(radius*radius - lensRadius*lensRadius))*(side1Type == 1); + float halfSphere2 = (radius2 - sqrtf(radius2*radius2 - lensRadius*lensRadius))*(side2Type == 1); + maxMinSet res = getAABBFromCylinder(center, orientation, halfCylinderLength + halfSphere1 + scene_epsilon, halfCylinderLength + halfSphere2 + scene_epsilon, lensRadius); + + aabb->m_min = res.min; + aabb->m_max = res.max; +} diff --git a/Source/OptiX/Private/cuda/optical bench/helpers.h b/Source/OptiX/Private/cuda/optical bench/helpers.h deleted file mode 100644 index 8f54c0a2438d8a3cf6bc014d83efed6f3a4d6077..0000000000000000000000000000000000000000 --- a/Source/OptiX/Private/cuda/optical bench/helpers.h +++ /dev/null @@ -1,267 +0,0 @@ -/* - * Copyright (c) 2017 NVIDIA CORPORATION. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of NVIDIA CORPORATION nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#pragma once - -#include <optixu/optixu_math_namespace.h> - -// Convert a float3 in [0,1)^3 to a uchar4 in [0,255]^4 -- 4th channel is set to 255 -#ifdef __CUDACC__ -static __device__ __inline__ optix::uchar4 make_color(const optix::float3& c) -{ - return optix::make_uchar4( static_cast<unsigned char>(__saturatef(c.z)*255.99f), /* B */ - static_cast<unsigned char>(__saturatef(c.y)*255.99f), /* G */ - static_cast<unsigned char>(__saturatef(c.x)*255.99f), /* R */ - 255u); /* A */ -} -#endif - -// Convert a float4 in [0,1)^4 to a uchar4 in [0,255]^4 -#ifdef __CUDACC__ -static __device__ __inline__ optix::uchar4 make_color(const optix::float4& c) -{ - return optix::make_uchar4( static_cast<unsigned char>(__saturatef(c.z)*255.99f), /* B */ - static_cast<unsigned char>(__saturatef(c.y)*255.99f), /* G */ - static_cast<unsigned char>(__saturatef(c.x)*255.99f), /* R */ - static_cast<unsigned char>(__saturatef(c.w)*255.99f)); /* A */ -} -#endif - -// Sample Phong lobe relative to U, V, W frame -static -__host__ __device__ __inline__ optix::float3 sample_phong_lobe( optix::float2 sample, float exponent, - optix::float3 U, optix::float3 V, optix::float3 W ) -{ - const float power = expf( logf(sample.y)/(exponent+1.0f) ); - const float phi = sample.x * 2.0f * (float)M_PIf; - const float scale = sqrtf(1.0f - power*power); - - const float x = cosf(phi)*scale; - const float y = sinf(phi)*scale; - const float z = power; - - return x*U + y*V + z*W; -} - -// Sample Phong lobe relative to U, V, W frame -static -__host__ __device__ __inline__ optix::float3 sample_phong_lobe( const optix::float2 &sample, float exponent, - const optix::float3 &U, const optix::float3 &V, const optix::float3 &W, - float &pdf, float &bdf_val ) -{ - const float cos_theta = powf(sample.y, 1.0f/(exponent+1.0f) ); - - const float phi = sample.x * 2.0f * M_PIf; - const float sin_theta = sqrtf(1.0f - cos_theta*cos_theta); - - const float x = cosf(phi)*sin_theta; - const float y = sinf(phi)*sin_theta; - const float z = cos_theta; - - const float powered_cos = powf( cos_theta, exponent ); - pdf = (exponent+1.0f) / (2.0f*M_PIf) * powered_cos; - bdf_val = (exponent+2.0f) / (2.0f*M_PIf) * powered_cos; - - return x*U + y*V + z*W; -} - -// Get Phong lobe PDF for local frame -static -__host__ __device__ __inline__ float get_phong_lobe_pdf( float exponent, const optix::float3 &normal, const optix::float3 &dir_out, - const optix::float3 &dir_in, float &bdf_val) -{ - using namespace optix; - - float3 r = -reflect(dir_out, normal); - const float cos_theta = fabs(dot(r, dir_in)); - const float powered_cos = powf(cos_theta, exponent ); - - bdf_val = (exponent+2.0f) / (2.0f*M_PIf) * powered_cos; - return (exponent+1.0f) / (2.0f*M_PIf) * powered_cos; -} - -// Create ONB from normal. Resulting W is parallel to normal -static -__host__ __device__ __inline__ void create_onb( const optix::float3& n, optix::float3& U, optix::float3& V, optix::float3& W ) -{ - using namespace optix; - - W = normalize( n ); - U = cross( W, optix::make_float3( 0.0f, 1.0f, 0.0f ) ); - - if ( fabs( U.x ) < 0.001f && fabs( U.y ) < 0.001f && fabs( U.z ) < 0.001f ) - U = cross( W, make_float3( 1.0f, 0.0f, 0.0f ) ); - - U = normalize( U ); - V = cross( W, U ); -} - -// Create ONB from normalized vector -static -__device__ __inline__ void create_onb( const optix::float3& n, optix::float3& U, optix::float3& V) -{ - using namespace optix; - - U = cross( n, make_float3( 0.0f, 1.0f, 0.0f ) ); - - if ( dot( U, U ) < 1e-3f ) - U = cross( n, make_float3( 1.0f, 0.0f, 0.0f ) ); - - U = normalize( U ); - V = cross( n, U ); -} - -// Compute the origin ray differential for transfer -static -__host__ __device__ __inline__ optix::float3 differential_transfer_origin(optix::float3 dPdx, optix::float3 dDdx, float t, optix::float3 direction, optix::float3 normal) -{ - float dtdx = -optix::dot((dPdx + t*dDdx), normal)/optix::dot(direction, normal); - return (dPdx + t*dDdx)+dtdx*direction; -} - -// Compute the direction ray differential for a pinhole camera -static -__host__ __device__ __inline__ optix::float3 differential_generation_direction(optix::float3 d, optix::float3 basis) -{ - float dd = optix::dot(d,d); - return (dd*basis-optix::dot(d,basis)*d)/(dd*sqrtf(dd)); -} - -// Compute the direction ray differential for reflection -static -__host__ __device__ __inline__ -optix::float3 differential_reflect_direction(optix::float3 dPdx, optix::float3 dDdx, optix::float3 dNdP, - optix::float3 D, optix::float3 N) -{ - using namespace optix; - - float3 dNdx = dNdP*dPdx; - float dDNdx = dot(dDdx,N) + dot(D,dNdx); - return dDdx - 2*(dot(D,N)*dNdx + dDNdx*N); -} - -// Compute the direction ray differential for refraction -static __host__ __device__ __inline__ -optix::float3 differential_refract_direction(optix::float3 dPdx, optix::float3 dDdx, optix::float3 dNdP, - optix::float3 D, optix::float3 N, float ior, optix::float3 T) -{ - using namespace optix; - - float eta; - if(dot(D,N) > 0.f) { - eta = ior; - N = -N; - } else { - eta = 1.f / ior; - } - - float3 dNdx = dNdP*dPdx; - float mu = eta*dot(D,N)-dot(T,N); - float TN = -sqrtf(1-eta*eta*(1-dot(D,N)*dot(D,N))); - float dDNdx = dot(dDdx,N) + dot(D,dNdx); - float dmudx = (eta - (eta*eta*dot(D,N))/TN)*dDNdx; - return eta*dDdx - (mu*dNdx+dmudx*N); -} - -// Color space conversions -static __host__ __device__ __inline__ optix::float3 Yxy2XYZ( const optix::float3& Yxy ) -{ - // avoid division by zero - if( Yxy.z < 1e-4 ) - return optix::make_float3( 0.0f, 0.0f, 0.0f ); - - return optix::make_float3( Yxy.y * ( Yxy.x / Yxy.z ), - Yxy.x, - ( 1.0f - Yxy.y - Yxy.z ) * ( Yxy.x / Yxy.z ) ); -} - -static __host__ __device__ __inline__ optix::float3 XYZ2rgb( const optix::float3& xyz) -{ - const float R = optix::dot( xyz, optix::make_float3( 3.2410f, -1.5374f, -0.4986f ) ); - const float G = optix::dot( xyz, optix::make_float3( -0.9692f, 1.8760f, 0.0416f ) ); - const float B = optix::dot( xyz, optix::make_float3( 0.0556f, -0.2040f, 1.0570f ) ); - return optix::make_float3( R, G, B ); -} - -static __host__ __device__ __inline__ optix::float3 Yxy2rgb( optix::float3 Yxy ) -{ - using namespace optix; - - // avoid division by zero - if( Yxy.z < 1e-4 ) - return make_float3( 0.0f, 0.0f, 0.0f ); - - // First convert to xyz - float3 xyz = make_float3( Yxy.y * ( Yxy.x / Yxy.z ), - Yxy.x, - ( 1.0f - Yxy.y - Yxy.z ) * ( Yxy.x / Yxy.z ) ); - - const float R = dot( xyz, make_float3( 3.2410f, -1.5374f, -0.4986f ) ); - const float G = dot( xyz, make_float3( -0.9692f, 1.8760f, 0.0416f ) ); - const float B = dot( xyz, make_float3( 0.0556f, -0.2040f, 1.0570f ) ); - return make_float3( R, G, B ); -} - -static __host__ __device__ __inline__ optix::float3 rgb2Yxy( optix::float3 rgb) -{ - using namespace optix; - - // convert to xyz - const float X = dot( rgb, make_float3( 0.4124f, 0.3576f, 0.1805f ) ); - const float Y = dot( rgb, make_float3( 0.2126f, 0.7152f, 0.0722f ) ); - const float Z = dot( rgb, make_float3( 0.0193f, 0.1192f, 0.9505f ) ); - - // avoid division by zero - // here we make the simplifying assumption that X, Y, Z are positive - float denominator = X + Y + Z; - if ( denominator < 1e-4 ) - return make_float3( 0.0f, 0.0f, 0.0f ); - - // convert xyz to Yxy - return make_float3( Y, - X / ( denominator ), - Y / ( denominator ) ); -} - -static __host__ __device__ __inline__ optix::float3 tonemap( const optix::float3 &hdr_value, float Y_log_av, float Y_max) -{ - using namespace optix; - - float3 val_Yxy = rgb2Yxy( hdr_value ); - - float Y = val_Yxy.x; // Y channel is luminance - const float a = 0.04f; - float Y_rel = a * Y / Y_log_av; - float mapped_Y = Y_rel * (1.0f + Y_rel / (Y_max * Y_max)) / (1.0f + Y_rel); - - float3 mapped_Yxy = make_float3( mapped_Y, val_Yxy.y, val_Yxy.z ); - float3 mapped_rgb = Yxy2rgb( mapped_Yxy ); - - return mapped_rgb; -} - diff --git a/Source/OptiX/Private/cuda/optical bench/lens_intersections.h b/Source/OptiX/Private/cuda/optical bench/lens_intersections.h deleted file mode 100644 index 02c4f489675d9a7b7de8069d0f2599719f0e98b6..0000000000000000000000000000000000000000 --- a/Source/OptiX/Private/cuda/optical bench/lens_intersections.h +++ /dev/null @@ -1,175 +0,0 @@ -//------------------------------------------------------------------------------ -// Project Phoenix -// -// Copyright (c) 2017-2018 RWTH Aachen University, Germany, -// Virtual Reality & Immersive Visualization Group. -//------------------------------------------------------------------------------ -// License -// -// Licensed under the 3-Clause BSD License (the "License"); -// you may not use this file except in compliance with the License. -// See the file LICENSE for the full text. -// You may obtain a copy of the License at -// -// https://opensource.org/licenses/BSD-3-Clause -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -//------------------------------------------------------------------------------ - -#ifndef OPTICAL_BENCH_LENS_INTERSECTIONS_H_ -#define OPTICAL_BENCH_LENS_INTERSECTIONS_H_ - -#include <optix.h> -#include <optix_world.h> - -struct perHitData{ - float t; - float3 normal; - float3 p; -}; - -struct maxMinSet{ - float3 max; - float3 min; -}; - -__device__ perHitData operator*(perHitData a, const int& b){ - a.t *= b; - a.normal *= b; - a.p *= b; - return a; -} - -__device__ perHitData operator*(const int& b, perHitData a){ - a.t *= b; - a.normal *= b; - a.p *= b; - return a; -} - -__device__ perHitData operator+(perHitData a, const perHitData& b){ - a.t += b.t; - a.normal += b.normal; - a.p += b.p; - return a; -} - -static __device__ float smallerButPositiv(float a, float b, float scene_epsilon){ - return (a > scene_epsilon && b > scene_epsilon) * fminf(a,b) + - (a > scene_epsilon && b < -scene_epsilon) * a + - (a < -scene_epsilon && b > scene_epsilon) * b + - (a < scene_epsilon && b < scene_epsilon) * -1.0f; // all rest -} - -static __device__ perHitData nearestButPositivHit(perHitData h1, perHitData h2, float scene_epsilon){ - perHitData r; - r.t = -1.0f; - - return (h1.t > scene_epsilon && h2.t > scene_epsilon) * (h1 * (h1.t <= h2.t) + h2 * (h1.t > h2.t)) - + (h1.t > scene_epsilon && h2.t < -scene_epsilon) * h1 - + (h1.t < -scene_epsilon && h2.t > scene_epsilon) * h2 - + (h1.t < -scene_epsilon && h2.t < -scene_epsilon) * r; -} - -static __device__ float circleIntersect(float radius, float3 center, optix::Ray ray, float3 orientation, float lensRadius, float scene_epsilon){ - using namespace optix; - - float3 L = ray.origin - center; - float3 D = ray.direction; - - float tca = dot(L, D); - - float tch2 = tca*tca - dot(L, L) + radius*radius; - - if(tch2 > 0.0f){ - float t1 = -tca - sqrtf(tch2); - if(t1 > 0.0f){ //check for actual hit in lens front, else discard hit - float3 p1 = ray.origin + t1*ray.direction; - float projection1 = dot(p1 - center, orientation); - float3 belowP1 = projection1 * orientation + center; - if(projection1 < 0.0f || length(p1 - belowP1) >= lensRadius) t1 = -1.0f; - } - float t2 = -tca + sqrtf(tch2); - if(t2 > 0.0f){ //check for actual hit in lens front, else discard hit - float3 p2 = ray.origin + t2*ray.direction; - float projection2 = dot(p2 - center, orientation); - float3 belowP2 = projection2 * orientation + center; - if(projection2 < 0.0f || length(p2 - belowP2) >= lensRadius) t2 = -1.0f; - } - - float t = smallerButPositiv(t1, t2, scene_epsilon); - return (t < 0.0f) * -1.0f + (t >= 0.0f) * t; - } - return -1.0f; -} - -static __device__ float cylinderIntersect(float length, float3 center, optix::Ray ray, float3 orientation, float lensRadius, float scene_epsilon){ - using namespace optix; - - float3 dp = ray.origin - center; - - float3 A = ray.direction - dot(ray.direction, orientation) * orientation; - float a = dot(A,A); - float b = dot(ray.direction - dot(ray.direction, orientation)*orientation, dp - dot(dp, orientation)*orientation); - float3 C = (dp - dot(dp, orientation)*orientation); - float c = dot(C,C) - lensRadius*lensRadius; - - float discriminant = b*b - a*c; - if(discriminant > 0.0f){ - float t1 = (-b - sqrtf(discriminant))/a; - if(fabs(dot((ray.origin + t1 * ray.direction) - center, orientation)) > length / 2) t1 = -1.0f; - float t2 = (-b + sqrtf(discriminant))/a; - if(fabs(dot((ray.origin + t2 * ray.direction) - center, orientation)) > length / 2) t2 = -1.0f; - - return smallerButPositiv(t1, t2, scene_epsilon); - } - - return -1.0f; -} - -static __device__ float intersectPlane(float3 center, optix::Ray ray, float3 orientation, float lensRadius, float scene_epsilon){ - using namespace optix; - - float denom = dot(orientation, ray.direction); - - if(fabs(denom) > scene_epsilon){ - float t = dot(center - ray.origin, orientation) / denom; - float3 p = ray.origin + t*ray.direction; - return (length(p - center) <= lensRadius) * t + (length(p - center) > lensRadius) * -1.0f; - } - - return -1.0f; -} - -static __device__ maxMinSet getAABBFromCylinder(float3 center, float3 orientation, float halfLength1, float halfLength2, float radius){ - using namespace optix; - - float3 sideVector = normalize(cross(orientation, make_float3(0.0f, 1.0f, 0.0f))); - float3 newUp = normalize(cross(sideVector, orientation)); - sideVector = sideVector * radius; - newUp = newUp * radius; - float3 depthVector = normalize(orientation); - - maxMinSet r; - r.min = make_float3(+10000000000); //+INFINITY - r.max = make_float3(-10000000000); //-INFINITY - float3 testVector = make_float3(0.0f); - - testVector = center + depthVector*halfLength1 + sideVector + newUp; r.max = fmaxf(r.max, testVector); r.min = fminf(r.min, testVector); - testVector = center + depthVector*halfLength1 + sideVector - newUp; r.max = fmaxf(r.max, testVector); r.min = fminf(r.min, testVector); - testVector = center + depthVector*halfLength1 - sideVector + newUp; r.max = fmaxf(r.max, testVector); r.min = fminf(r.min, testVector); - testVector = center + depthVector*halfLength1 - sideVector - newUp; r.max = fmaxf(r.max, testVector); r.min = fminf(r.min, testVector); - - testVector = center - depthVector*halfLength2 + sideVector + newUp; r.max = fmaxf(r.max, testVector); r.min = fminf(r.min, testVector); - testVector = center - depthVector*halfLength2 + sideVector - newUp; r.max = fmaxf(r.max, testVector); r.min = fminf(r.min, testVector); - testVector = center - depthVector*halfLength2 - sideVector + newUp; r.max = fmaxf(r.max, testVector); r.min = fminf(r.min, testVector); - testVector = center - depthVector*halfLength2 - sideVector - newUp; r.max = fmaxf(r.max, testVector); r.min = fminf(r.min, testVector); - - return r; -} - -#endif // OPTICAL_BENCH_LENS_INTERSECTIONS_H_ \ No newline at end of file diff --git a/Source/OptiX/Private/cuda/optical bench/prd.h b/Source/OptiX/Private/cuda/optical bench/prd.h deleted file mode 100644 index 64928a935fc43d8758b3363c33c4c514ee763a0c..0000000000000000000000000000000000000000 --- a/Source/OptiX/Private/cuda/optical bench/prd.h +++ /dev/null @@ -1,48 +0,0 @@ -//------------------------------------------------------------------------------ -// Project Phoenix -// -// Copyright (c) 2017-2018 RWTH Aachen University, Germany, -// Virtual Reality & Immersive Visualization Group. -//------------------------------------------------------------------------------ -// License -// -// Licensed under the 3-Clause BSD License (the "License"); -// you may not use this file except in compliance with the License. -// See the file LICENSE for the full text. -// You may obtain a copy of the License at -// -// https://opensource.org/licenses/BSD-3-Clause -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -//------------------------------------------------------------------------------ - -#ifndef OPTICAL_BENCH_PRD_H_ -#define OPTICAL_BENCH_PRD_H_ - -#include <optixu/optixu_vector_types.h> - -struct PerRayData_radiance_iterative{ - float3 origin; - float3 direction; - float power; - int depth; - - bool done; - bool hit_lens; -}; - -struct PerRayData_radiance{ - float3 result; - float hit_depth; - float importance; - int depth; - - bool miss; - bool hit_lens; -}; - -#endif // OPTICAL_BENCH_PRD_H_ diff --git a/Source/OptiX/Private/cuda/optical bench/random.h b/Source/OptiX/Private/cuda/optical bench/random.h deleted file mode 100644 index c9ff0ac6b03135263c6c1357cc74af45ca738551..0000000000000000000000000000000000000000 --- a/Source/OptiX/Private/cuda/optical bench/random.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2017 NVIDIA CORPORATION. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of NVIDIA CORPORATION nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <optixu/optixu_math_namespace.h> - -template<unsigned int N> -static __host__ __device__ __inline__ unsigned int tea( unsigned int val0, unsigned int val1 ) -{ - unsigned int v0 = val0; - unsigned int v1 = val1; - unsigned int s0 = 0; - - for( unsigned int n = 0; n < N; n++ ) - { - s0 += 0x9e3779b9; - v0 += ((v1<<4)+0xa341316c)^(v1+s0)^((v1>>5)+0xc8013ea4); - v1 += ((v0<<4)+0xad90777d)^(v0+s0)^((v0>>5)+0x7e95761e); - } - - return v0; -} - -// Generate random unsigned int in [0, 2^24) -static __host__ __device__ __inline__ unsigned int lcg(unsigned int &prev) -{ - const unsigned int LCG_A = 1664525u; - const unsigned int LCG_C = 1013904223u; - prev = (LCG_A * prev + LCG_C); - return prev & 0x00FFFFFF; -} - -static __host__ __device__ __inline__ unsigned int lcg2(unsigned int &prev) -{ - prev = (prev*8121 + 28411) % 134456; - return prev; -} - -// Generate random float in [0, 1) -static __host__ __device__ __inline__ float rnd(unsigned int &prev) -{ - return ((float) lcg(prev) / (float) 0x01000000); -} - -static __host__ __device__ __inline__ unsigned int rot_seed( unsigned int seed, unsigned int frame ) -{ - return seed ^ frame; -} diff --git a/Source/OptiX/Public/OptiXLaserComponent.h b/Source/OptiX/Public/OptiXLaserComponent.h index 4de1db018804912697fe19a75cae09497988b969..2fad4ab92a9153674ed5781f6f557a0ab41911aa 100644 --- a/Source/OptiX/Public/OptiXLaserComponent.h +++ b/Source/OptiX/Public/OptiXLaserComponent.h @@ -119,6 +119,9 @@ public: UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = OptiX) int32 LaserMaxDepth; + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = OptiX) + int32 LaserBufferSize; + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = OptiX) int32 LaserTracesPerFrame; diff --git a/Source/OptiX/Public/OptiXLaserDetectorActor.h b/Source/OptiX/Public/OptiXLaserDetectorActor.h index e3f0e06d2d50dd24fb7838f0ee2a43ab047ec25c..2e305332c286ae9555dcb34c69c72ddaf6414b01 100644 --- a/Source/OptiX/Public/OptiXLaserDetectorActor.h +++ b/Source/OptiX/Public/OptiXLaserDetectorActor.h @@ -44,7 +44,7 @@ public: UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "OptiX") UOptiXLaserTargetComponent* OptiXLaserTargetComponent; - UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "OptiX") + UPROPERTY(BlueprintReadOnly, Category = "OptiX") UTexture2D* DetectorResultTexture; UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "OptiX") diff --git a/Source/OptiX/Public/OptiXLensActor.h b/Source/OptiX/Public/OptiXLensActor.h new file mode 100644 index 0000000000000000000000000000000000000000..b4b99a917a8a1dbd9ccc37d262cc030254309888 --- /dev/null +++ b/Source/OptiX/Public/OptiXLensActor.h @@ -0,0 +1,33 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "Engine/StaticMeshActor.h" + +#include "OptiXLensComponent.h" + +#include "OptiXLensActor.generated.h" + +/** + * + */ +UCLASS() +class OPTIX_API AOptiXLensActor : public AStaticMeshActor +{ + GENERATED_BODY() + +public: + + AOptiXLensActor(const FObjectInitializer& ObjectInitializer); + + //virtual void BeginPlay() override; + //virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override; + + +public: + + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "OptiX") + UOptiXLensComponent* OptiXLensComponent; +}; + diff --git a/Source/OptiX/Public/OptiXTargetActor.h b/Source/OptiX/Public/OptiXTargetActor.h new file mode 100644 index 0000000000000000000000000000000000000000..a130318e48f85efcbcc91fd6a7d139fcd4bf6d04 --- /dev/null +++ b/Source/OptiX/Public/OptiXTargetActor.h @@ -0,0 +1,33 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "Engine/StaticMeshActor.h" + +#include "OptiXTargetComponent.h" + +#include "OptiXTargetActor.generated.h" + +/** + * + */ +UCLASS() +class OPTIX_API AOptiXTargetActor : public AStaticMeshActor +{ + GENERATED_BODY() + +public: + + AOptiXTargetActor(const FObjectInitializer& ObjectInitializer); + + //virtual void BeginPlay() override; + //virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override; + + +public: + + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "OptiX") + UOptiXTargetComponent* OptiXTargetComponent; +}; + diff --git a/Source/OptiX/Public/OptiXTargetComponent.h b/Source/OptiX/Public/OptiXTargetComponent.h index d2e220efb76af1a43cf615650f3a84dcae16a74e..970214acb8ece2969d601cc7a958975330d8aa44 100644 --- a/Source/OptiX/Public/OptiXTargetComponent.h +++ b/Source/OptiX/Public/OptiXTargetComponent.h @@ -16,6 +16,9 @@ class OPTIX_API UOptiXTargetComponent : public UOptiXObjectComponent public: + UOptiXTargetComponent(const FObjectInitializer& ObjectInitializer); + + UFUNCTION(BlueprintCallable, /*meta = (BlueprintProtected)*/ Category = "OptiXComponent") virtual void UpdateOptiXComponent() override; @@ -30,10 +33,26 @@ public: virtual void CleanOptiXComponent() override; + UFUNCTION(BlueprintCallable, /*meta = (BlueprintProtected)*/ Category = "OptiXComponent") + void SetSize(FVector NewSize); + + UFUNCTION(BlueprintCallable, /*meta = (BlueprintProtected)*/ Category = "OptiXComponent") + FVector GetSize(); + +public: + + FIntPoint TextureSize; + + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "OptiXComponent") + FVector TargetSize; + private: UPROPERTY() UOptiXTransform* OptiXTransform; UPROPERTY() UOptiXAcceleration* OptiXAcceleration; + + UPROPERTY() + UTexture2D* Texture; };