00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef TOXIC_RENDERER_RENDERER_H
00024 #define TOXIC_RENDERER_RENDERER_H
00025
00026 #include "common/math/point3.h"
00027 #include "common/math/real.h"
00028 #include "common/math/vector3.h"
00029 #include "framebuffer.h"
00030 #include "globals.h"
00031 #include "ilight.h"
00032
00033 #include <cassert>
00034
00035 namespace toxic {
00036
00037 class Context;
00038 class Framebuffer;
00039 class Hit;
00040 class ICamera;
00041 class ISurfaceSampler;
00042 class ISurfaceShader;
00043 class PhotonMap;
00044 class Ray;
00045 class Scene;
00046 class ShadingData;
00047
00048 class Renderer {
00049 public:
00050 Renderer();
00051 virtual ~Renderer();
00052
00053
00054 void SetScene(const Scene *scene);
00055
00056
00057 void SetCamera(const ICamera *camera);
00058
00059
00060 void SetGlobalPhotonMap(const PhotonMap *global_pm);
00061
00062
00063 void SetCausticsPhotonMap(const PhotonMap *cautics_pm);
00064
00065
00066 void SetFramebuffer(Framebuffer *framebuffer);
00067
00068
00069
00070
00071
00072
00073
00074 void SetRenderArea(int x0, int y0, int x1, int y1);
00075
00076
00077 void ResetRenderArea();
00078
00079
00080
00081
00082 void Restart(const Context &context);
00083
00084
00085 void RenderNextPixel(const Context &context);
00086
00087
00088 bool IsRenderComplete() const;
00089 int GetCompletedLines() const;
00090 sheep::Real GetProgress() const;
00091
00092 void Annotate(const Context &context);
00093
00094 private:
00095 const Scene *m_scene;
00096 const ICamera *m_camera;
00097
00098
00099
00100
00101
00102 const PhotonMap *m_global_pm;
00103
00104
00105
00106
00107 const PhotonMap *m_caustics_pm;
00108
00109 Framebuffer *m_framebuffer;
00110
00111 int m_area_x0, m_area_y0;
00112 int m_area_x1, m_area_y1;
00113
00114 int m_x, m_y;
00115 int m_completed_pixels;
00116
00117
00118 int m_area_pixels;
00119 sheep::Real m_inv_area_pixels;
00120
00121
00122 ISurfaceSampler *m_pixel_ss;
00123 ISurfaceSampler *m_arealight_ss;
00124 ISurfaceSampler *m_primary_fg_hss;
00125 ISurfaceSampler *m_secondary_fg_hss;
00126
00127
00128 ILight::IrradianceSampleVector m_irradiance_samples;
00129
00130 #ifdef ENABLE_WHITTED_SAMPLING_CACHE
00131 Color3 *m_prev_pixels;
00132 #endif // ENABLE_WHITTED_SAMPLING_CACHE
00133
00134 void cleanup();
00135
00136
00137
00138 void render_pixel(const Context &context);
00139
00140 void render_pixel_supersampling(const Context &context);
00141 void render_pixel_whitted(const Context &context);
00142
00143 Color3 whitted_recursive_sampling(
00144 const Context &context,
00145 const sheep::Point2 ¢er,
00146 const sheep::Point2 &v0,
00147 const sheep::Point2 &v1,
00148 const sheep::Point2 &v2,
00149 const sheep::Point2 &v3,
00150 const Color3 &r0,
00151 const Color3 &r1,
00152 const Color3 &r2,
00153 const Color3 &r3,
00154 int recursion_level
00155 );
00156
00157
00158
00159
00160 Color3 trace(
00161 const Context &context,
00162 const Ray &ray,
00163 int recursion_level
00164 );
00165
00166
00167
00168
00169
00170
00171 Color3 compute_direct_illumination(
00172 const Context &context,
00173 const sheep::Point3 &point,
00174 const sheep::Vector3 &geometric_normal,
00175 const sheep::Vector3 &shading_normal,
00176 const sheep::Vector3 &outgoing,
00177 const ISurfaceShader *surface_shader,
00178 const ShadingData &shadingdata
00179 );
00180
00181
00182 Color3 compute_specular_reflections(
00183 const Context &context,
00184 const sheep::Point3 &point,
00185 const sheep::Vector3 &geometric_normal,
00186 const sheep::Vector3 &shading_normal,
00187 const sheep::Vector3 &outgoing,
00188 const ShadingData &shadingdata,
00189 int recursion_level
00190 );
00191
00192
00193 Color3 final_gathering(
00194 const Context &context,
00195 const sheep::Point3 &point,
00196 const sheep::Vector3 &geometric_normal,
00197 const sheep::Vector3 &shading_normal,
00198 const sheep::Vector3 &outgoing,
00199 const ShadingData &shadingdata,
00200 bool is_secondary = false
00201 ) const;
00202
00203
00204 Color3 compute_caustics(
00205 const Context &context,
00206 const sheep::Point3 &point,
00207 const sheep::Vector3 &geometric_normal,
00208 const sheep::Vector3 &shading_normal,
00209 const sheep::Vector3 &outgoing,
00210 const ShadingData &shadingdata
00211 ) const;
00212
00213
00214
00215
00216
00217
00218
00219 Color3 compute_indirect_illumination(
00220 const Context &context,
00221 const sheep::Point3 &point,
00222 const sheep::Vector3 &geometric_normal,
00223 const sheep::Vector3 &shading_normal,
00224 const sheep::Vector3 &outgoing,
00225 const ShadingData &shadingdata
00226 ) const;
00227 };
00228
00229 #include "renderer.inl"
00230
00231 }
00232
00233 #endif // !TOXIC_RENDERER_RENDERER_H