Fermat
renderer_impl.h
1 /*
2  * Fermat
3  *
4  * Copyright (c) 2016-2019, NVIDIA CORPORATION. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the NVIDIA CORPORATION nor the
14  * names of its contributors may be used to endorse or promote products
15  * derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #pragma once
30 
31 #include <renderer.h>
32 #include <buffers.h>
33 #include <framebuffer.h>
34 #include <texture.h>
35 #include <camera.h>
36 #include <ray.h>
37 #include <lights.h>
38 #include <mesh_lights.h>
39 #include <mesh/MeshStorage.h>
40 #include <vector>
41 #include <renderer_view.h>
42 #include <renderer_interface.h>
43 #include <tiled_sequence.h>
44 #include <dll.h>
45 
48 
49 struct RenderingContext;
50 
54 {
55  typedef RenderingContext::HostMipMapStoragePtr HostMipMapStoragePtr;
56  typedef RenderingContext::DeviceMipMapStoragePtr DeviceMipMapStoragePtr;
59 
62  RenderingContextImpl(RenderingContext* _context) : m_this( _context ) {}
63 
66  void init(int argc, char** argv);
67 
71  void render(const uint32 instance);
72 
75  void clear();
76 
79  void multiply_frame(const float scale);
80 
84  void rescale_frame(const uint32 instance);
85 
89  void clamp_frame(const float max_value);
90 
94  void update_variances(const uint32 instance);
95 
98  void update_model();
99 
103  void filter(const uint32 instance);
104 
107  uint2 res() const { return make_uint2(m_res_x, m_res_y); }
108 
111  RenderingContextView view(const uint32 instance);
112 
115  Camera& get_camera() { return m_camera; }
116 
119  uint2 get_res() const { return make_uint2(m_res_x, m_res_y); }
120 
123  float get_aspect_ratio() const { return m_aspect; }
124 
127  float get_exposure() const { return m_exposure; }
128 
131  float get_gamma() const { return m_gamma; }
132 
136 
139  std::vector<HostMipMapStoragePtr>& get_host_textures() { return m_textures_h; }
140 
143  std::vector<DeviceMipMapStoragePtr>& get_device_textures() { return m_textures_d; }
144 
148 
152 
156 
160 
164 
167  RTContext* get_rt_context() const { return m_rt_context; }
168 
172 
175  uint32 register_renderer(const char* name, RendererFactoryFunction factory);
176 
179  uint32 load_plugin(const char* plugin_name);
180 
184 
185  RenderingContext* m_this;
186 
187  unsigned int m_res_x;
188  unsigned int m_res_y;
189  float m_aspect;
190  float m_exposure;
191  float m_gamma;
193  ShadingMode m_shading_mode;
194 
199  //DeviceUVBvh m_uv_bvh;
200 
202  DirectionalLight m_light;
203  HostDirectionalLightVector m_dir_lights_h;
204  DeviceDirectionalLightVector m_dir_lights_d;
205 
208 
209  std::vector<HostMipMapStoragePtr> m_textures_h;
210  std::vector<DeviceMipMapStoragePtr> m_textures_d;
216  uint32 m_ltc_size;
218 
223 
225 
226  std::vector<std::string> m_renderer_names;
227  std::vector<RendererFactoryFunction> m_renderer_factories;
228  std::vector<DLL> m_plugins;
229 };
230 
DomainBuffer< HOST_BUFFER, MipMapView > m_texture_views_h
host-side texture views
Definition: renderer_impl.h:211
RenderingContextImpl(RenderingContext *_context)
Definition: renderer_impl.h:62
Definition: framebuffer.h:205
MipMapView * get_host_texture_views()
Definition: renderer_impl.h:147
DomainBuffer< CUDA_BUFFER, float4 > m_ltc_M
LTC coefficients.
Definition: renderer_impl.h:213
MeshLightsStorage & get_mesh_lights()
Definition: renderer_impl.h:163
std::vector< DLL > m_plugins
plugin DLLs
Definition: renderer_impl.h:228
Camera m_camera
camera
Definition: renderer_impl.h:201
uint2 res() const
Definition: renderer_impl.h:107
DomainBuffer< CUDA_BUFFER, float > m_var
variance framebuffer storage
Definition: renderer_impl.h:221
DomainBuffer< CUDA_BUFFER, float4 > m_ltc_Minv
LTC coefficients.
Definition: renderer_impl.h:214
std::vector< DeviceMipMapStoragePtr > m_textures_d
device-side textures
Definition: renderer_impl.h:210
FBufferStorage m_fb
output framebuffer storage
Definition: renderer_impl.h:219
unsigned int m_res_y
Y resolution.
Definition: renderer_impl.h:188
unsigned int m_res_x
X resolution.
Definition: renderer_impl.h:187
float m_aspect
aspect ratio
Definition: renderer_impl.h:189
std::vector< HostMipMapStoragePtr > m_textures_h
host-side textures
Definition: renderer_impl.h:209
std::vector< RendererFactoryFunction > m_renderer_factories
plugin renderer factories
Definition: renderer_impl.h:227
Definition: lights.h:249
DomainBuffer< CUDA_BUFFER, uint8 > m_rgba
output 8-bit rgba storage
Definition: renderer_impl.h:222
Definition: framebuffer.h:295
DeviceDirectionalLightVector m_dir_lights_d
device-side directional lights
Definition: renderer_impl.h:204
DeviceMeshStorage & get_device_mesh()
Definition: renderer_impl.h:159
RTContext * get_rt_context() const
Definition: renderer_impl.h:167
Definition: renderer_impl.h:53
Definition: rt.h:55
DomainBuffer< CUDA_BUFFER, float > m_ltc_A
LTC coefficients.
Definition: renderer_impl.h:215
float m_gamma
gamma
Definition: renderer_impl.h:191
FBufferChannelStorage m_fb_temp[4]
temporary framebuffer storage
Definition: renderer_impl.h:220
float get_exposure() const
Definition: renderer_impl.h:127
std::vector< DeviceMipMapStoragePtr > & get_device_textures()
Definition: renderer_impl.h:143
DomainBuffer< CUDA_BUFFER, float > m_glossy_reflectance
glossy reflectance/albedo profile
Definition: renderer_impl.h:217
HostDirectionalLightVector m_dir_lights_h
host-side directional lights
Definition: renderer_impl.h:203
void multiply_frame(const float scale)
uint32 m_ltc_size
LTC coefficients.
Definition: renderer_impl.h:216
Camera & get_camera()
Definition: renderer_impl.h:115
MeshLightsStorage m_mesh_lights
mesh lights
Definition: renderer_impl.h:197
DomainBuffer< CUDA_BUFFER, MipMapView > m_texture_views_d
device-side texture views
Definition: renderer_impl.h:212
float m_shading_rate
shading rate
Definition: renderer_impl.h:192
uint32 load_plugin(const char *plugin_name)
RendererInterface * m_renderer
rendering engine
Definition: renderer_impl.h:207
Definition: mesh_lights.h:35
uint32 m_renderer_type
rendering engine type
Definition: renderer_impl.h:206
Definition: MeshStorage.h:44
void filter(const uint32 instance)
Definition: tiled_sequence.h:131
DeviceMeshStorage m_mesh_d
device-side scene mesh representation
Definition: renderer_impl.h:196
void rescale_frame(const uint32 instance)
uint32 register_renderer(const char *name, RendererFactoryFunction factory)
Definition: camera.h:46
Definition: renderer_interface.h:45
void clamp_frame(const float max_value)
std::vector< HostMipMapStoragePtr > & get_host_textures()
Definition: renderer_impl.h:139
cugar::Bbox3f compute_bbox()
FBufferStorage & get_frame_buffer()
Definition: renderer_impl.h:135
MipMapView * get_device_texture_views()
Definition: renderer_impl.h:151
std::vector< std::string > m_renderer_names
plugin renderer names
Definition: renderer_impl.h:226
TiledSequence m_sequence
a tiled sequence
Definition: renderer_impl.h:224
ShadingMode m_shading_mode
shading mode
Definition: renderer_impl.h:193
void update_variances(const uint32 instance)
void init(int argc, char **argv)
Definition: renderer.h:52
Definition: texture_view.h:73
float m_exposure
exposure
Definition: renderer_impl.h:190
RTContext * m_rt_context
internal optix ray tracing context
Definition: renderer_impl.h:198
float get_gamma() const
Definition: renderer_impl.h:131
void render(const uint32 instance)
MeshStorage m_mesh
host-side scene mesh representation
Definition: renderer_impl.h:195
Definition: renderer_view.h:80
uint2 get_res() const
Definition: renderer_impl.h:119
RendererInterface * get_renderer() const
Definition: renderer_impl.h:171
float get_aspect_ratio() const
Definition: renderer_impl.h:123
RenderingContextView view(const uint32 instance)
CUGAR_HOST_DEVICE Matrix< T, 4, 4 > scale(const Vector< T, 3 > &vec)
build a 3d scaling matrix
Definition: matrix_inline.h:539
Definition: MeshStorage.h:273
MeshStorage & get_host_mesh()
Definition: renderer_impl.h:155