Skip to content

Commit

Permalink
soft area lights working
Browse files Browse the repository at this point in the history
  • Loading branch information
ingowald committed Jul 23, 2019
1 parent eb53747 commit 2448009
Show file tree
Hide file tree
Showing 11 changed files with 1,837 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,6 @@ add_subdirectory(example06_multipleObjects)
add_subdirectory(example07_firstRealModel)
add_subdirectory(example08_addingTextures)
add_subdirectory(example09_shadowRays)
add_subdirectory(example10_softShadows)


47 changes: 47 additions & 0 deletions example10_softShadows/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# ======================================================================================
# Copyright (c) 2019 NVIDIA Corporation. All rights reserved.
#
# NVIDIA Corporation and its licensors retain all intellectual property and proprietary
# rights in and to this software, related documentation and any modifications thereto.
# Any use, reproduction, disclosure or distribution of this software and related
# documentation without an express license agreement from NVIDIA Corporation is strictly
# prohibited.
#
# TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED *AS IS*
# AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS OR IMPLIED,
# INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE. IN NO EVENT SHALL NVIDIA OR ITS SUPPLIERS BE LIABLE FOR ANY
# SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT
# LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF
# BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
# INABILITY TO USE THIS SOFTWARE, EVEN IF NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGES
# ======================================================================================

find_package(OpenGL REQUIRED)

include_directories(${OptiX_INCLUDE})

cuda_compile_and_embed(embedded_ptx_code devicePrograms.cu)

add_executable(ex10_softShadows
${embedded_ptx_code}
optix7.h
CUDABuffer.h
SampleRenderer.h
SampleRenderer.cpp
Model.cpp
main.cpp
)

target_link_libraries(ex10_softShadows
gdt
# optix dependencies, for rendering
${optix_LIBRARY}
${CUDA_LIBRARIES}
${CUDA_CUDA_LIBRARY}
# glfw and opengl, for display
glfWindow
glfw
${OPENGL_gl_LIBRARY}
)
89 changes: 89 additions & 0 deletions example10_softShadows/CUDABuffer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// ======================================================================================
// Copyright (c) 2019 NVIDIA Corporation. All rights reserved.
//
// NVIDIA Corporation and its licensors retain all intellectual property and proprietary
// rights in and to this software, related documentation and any modifications thereto.
// Any use, reproduction, disclosure or distribution of this software and related
// documentation without an express license agreement from NVIDIA Corporation is strictly
// prohibited.
//
// TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED *AS IS*
// AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS OR IMPLIED,
// INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
// PARTICULAR PURPOSE. IN NO EVENT SHALL NVIDIA OR ITS SUPPLIERS BE LIABLE FOR ANY
// SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT
// LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF
// BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
// INABILITY TO USE THIS SOFTWARE, EVEN IF NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF
// SUCH DAMAGES
// ======================================================================================

#pragma once

#include "optix7.h"
// common std stuff
#include <vector>
#include <assert.h>

/*! \namespace osc - Optix Siggraph Course */
namespace osc {

/*! simple wrapper for creating, and managing a device-side CUDA
buffer */
struct CUDABuffer {
inline CUdeviceptr d_pointer() const
{ return (CUdeviceptr)d_ptr; }

//! re-size buffer to given number of bytes
void resize(size_t size)
{
if (d_ptr) free();
alloc(size);
}

//! allocate to given number of bytes
void alloc(size_t size)
{
assert(d_ptr == nullptr);
this->sizeInBytes = size;
CUDA_CHECK(Malloc( (void**)&d_ptr, sizeInBytes));
}

//! free allocated memory
void free()
{
CUDA_CHECK(Free(d_ptr));
d_ptr = nullptr;
sizeInBytes = 0;
}

template<typename T>
void alloc_and_upload(const std::vector<T> &vt)
{
alloc(vt.size()*sizeof(T));
upload((const T*)vt.data(),vt.size());
}

template<typename T>
void upload(const T *t, size_t count)
{
assert(d_ptr != nullptr);
assert(sizeInBytes == count*sizeof(T));
CUDA_CHECK(Memcpy(d_ptr, (void *)t,
count*sizeof(T), cudaMemcpyHostToDevice));
}

template<typename T>
void download(T *t, size_t count)
{
assert(d_ptr != nullptr);
assert(sizeInBytes == count*sizeof(T));
CUDA_CHECK(Memcpy((void *)t, d_ptr,
count*sizeof(T), cudaMemcpyDeviceToHost));
}

size_t sizeInBytes { 0 };
void *d_ptr { nullptr };
};

} // ::osc
64 changes: 64 additions & 0 deletions example10_softShadows/LaunchParams.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// ======================================================================================
// Copyright (c) 2019 NVIDIA Corporation. All rights reserved.
//
// NVIDIA Corporation and its licensors retain all intellectual property and proprietary
// rights in and to this software, related documentation and any modifications thereto.
// Any use, reproduction, disclosure or distribution of this software and related
// documentation without an express license agreement from NVIDIA Corporation is strictly
// prohibited.
//
// TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED *AS IS*
// AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS OR IMPLIED,
// INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
// PARTICULAR PURPOSE. IN NO EVENT SHALL NVIDIA OR ITS SUPPLIERS BE LIABLE FOR ANY
// SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT
// LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF
// BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
// INABILITY TO USE THIS SOFTWARE, EVEN IF NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF
// SUCH DAMAGES
// ======================================================================================

#pragma once

#include "gdt/math/vec.h"
#include "optix7.h"

namespace osc {
using namespace gdt;

// for this simple example, we have a single ray type
enum { RADIANCE_RAY_TYPE=0, SHADOW_RAY_TYPE, RAY_TYPE_COUNT };

struct TriangleMeshSBTData {
vec3f color;
vec3f *vertex;
vec3f *normal;
vec2f *texcoord;
vec3i *index;
bool hasTexture;
cudaTextureObject_t texture;
};

struct LaunchParams
{
struct {
uint32_t *colorBuffer;
vec2i size;
int accumID { 0 };
} frame;

struct {
vec3f position;
vec3f direction;
vec3f horizontal;
vec3f vertical;
} camera;

struct {
vec3f origin, du, dv, power;
} light;

OptixTraversableHandle traversable;
};

} // ::osc
Loading

0 comments on commit 2448009

Please sign in to comment.