@@ -87,11 +87,49 @@ namespace GLSLPT
87
87
// Shaders
88
88
// ----------------------------------------------------------
89
89
90
- pathTraceShader = LoadShaders (shadersDirectory + " common/vertex.glsl" , shadersDirectory + " tiled.glsl" );
91
- pathTraceShaderLowRes = LoadShaders (shadersDirectory + " common/vertex.glsl" , shadersDirectory + " progressive.glsl" );
92
- accumShader = LoadShaders (shadersDirectory + " common/vertex.glsl" , shadersDirectory + " accumulation.glsl" );
93
- tileOutputShader = LoadShaders (shadersDirectory + " common/vertex.glsl" , shadersDirectory + " tileOutput.glsl" );
94
- outputShader = LoadShaders (shadersDirectory + " common/vertex.glsl" , shadersDirectory + " output.glsl" );
90
+ ShaderInclude::ShaderSource vertexShaderSrcObj = ShaderInclude::load (shadersDirectory + " common/vertex.glsl" );
91
+ ShaderInclude::ShaderSource pathTraceShaderSrcObj = ShaderInclude::load (shadersDirectory + " tiled.glsl" );
92
+ ShaderInclude::ShaderSource pathTraceShaderLowResSrcObj = ShaderInclude::load (shadersDirectory + " progressive.glsl" );
93
+ ShaderInclude::ShaderSource accumShaderSrcObj = ShaderInclude::load (shadersDirectory + " accumulation.glsl" );
94
+ ShaderInclude::ShaderSource tileOutputShaderSrcObj = ShaderInclude::load (shadersDirectory + " tileOutput.glsl" );
95
+ ShaderInclude::ShaderSource outputShaderSrcObj = ShaderInclude::load (shadersDirectory + " output.glsl" );
96
+
97
+ // Add preprocessor defines for conditional compilation
98
+ std::string defines = " " ;
99
+ if (scene->renderOptions .useEnvMap && scene->hdrData != nullptr )
100
+ defines += " #define ENVMAP\n " ;
101
+ if (!scene->lights .empty ())
102
+ defines += " #define LIGHTS\n " ;
103
+ if (scene->renderOptions .enableRR )
104
+ {
105
+ defines += " #define RR\n " ;
106
+ defines += " #define RR_DEPTH " + std::to_string (scene->renderOptions .RRDepth ) + " \n " ;
107
+ }
108
+ if (scene->renderOptions .useConstantBg )
109
+ defines += " #define CONSTANT_BG\n " ;
110
+
111
+ if (defines.size () > 0 )
112
+ {
113
+ size_t idx = pathTraceShaderSrcObj.src .find (" #version" );
114
+ if (idx != -1 )
115
+ idx = pathTraceShaderSrcObj.src .find (" \n " , idx);
116
+ else
117
+ idx = 0 ;
118
+ pathTraceShaderSrcObj.src .insert (idx + 1 , defines);
119
+
120
+ idx = pathTraceShaderLowResSrcObj.src .find (" #version" );
121
+ if (idx != -1 )
122
+ idx = pathTraceShaderLowResSrcObj.src .find (" \n " , idx);
123
+ else
124
+ idx = 0 ;
125
+ pathTraceShaderLowResSrcObj.src .insert (idx + 1 , defines);
126
+ }
127
+
128
+ pathTraceShader = LoadShaders (vertexShaderSrcObj, pathTraceShaderSrcObj);
129
+ pathTraceShaderLowRes = LoadShaders (vertexShaderSrcObj, pathTraceShaderLowResSrcObj);
130
+ accumShader = LoadShaders (vertexShaderSrcObj, accumShaderSrcObj);
131
+ tileOutputShader = LoadShaders (vertexShaderSrcObj, tileOutputShaderSrcObj);
132
+ outputShader = LoadShaders (vertexShaderSrcObj, outputShaderSrcObj);
95
133
96
134
printf (" Debug sizes : %d %d - %d %d\n " , tileWidth, tileHeight, screenSize.x , screenSize.y );
97
135
// ----------------------------------------------------------
@@ -414,6 +452,7 @@ namespace GLSLPT
414
452
glUniform1i (glGetUniformLocation (shaderObject, " maxDepth" ), scene->renderOptions .maxDepth );
415
453
glUniform1i (glGetUniformLocation (shaderObject, " tileX" ), tileX);
416
454
glUniform1i (glGetUniformLocation (shaderObject, " tileY" ), tileY);
455
+ glUniform3f (glGetUniformLocation (shaderObject, " bgColor" ), scene->renderOptions .bgColor .x , scene->renderOptions .bgColor .y , scene->renderOptions .bgColor .z );
417
456
pathTraceShader->StopUsing ();
418
457
419
458
pathTraceShaderLowRes->Use ();
@@ -428,6 +467,8 @@ namespace GLSLPT
428
467
glUniform1i (glGetUniformLocation (shaderObject, " useEnvMap" ), scene->hdrData == nullptr ? false : scene->renderOptions .useEnvMap );
429
468
glUniform1f (glGetUniformLocation (shaderObject, " hdrMultiplier" ), scene->renderOptions .hdrMultiplier );
430
469
glUniform1i (glGetUniformLocation (shaderObject, " maxDepth" ), scene->camera ->isMoving || scene->instancesModified ? 2 : scene->renderOptions .maxDepth );
470
+ glUniform3f (glGetUniformLocation (shaderObject, " camera.position" ), scene->camera ->position .x , scene->camera ->position .y , scene->camera ->position .z );
471
+ glUniform3f (glGetUniformLocation (shaderObject, " bgColor" ), scene->renderOptions .bgColor .x , scene->renderOptions .bgColor .y , scene->renderOptions .bgColor .z );
431
472
pathTraceShaderLowRes->StopUsing ();
432
473
433
474
outputShader->Use ();
0 commit comments