@@ -28,16 +28,30 @@ layout (location = 0) out vec4 OutColor;
28
28
29
29
#include < nbl/ builtin/ glsl/ bxdf/ common.glsl> // change to bxdf/common.glsl
30
30
31
- #ifndef _NBL_FRAG_PUSH_CONSTANTS_DEFINED_
32
- #define _NBL_FRAG_PUSH_CONSTANTS_DEFINED_
31
+ #ifndef _NBL_FRAG_MATERIAL_PARAMETERS_STRUCT_DEFINED_
32
+ #define _NBL_FRAG_MATERIAL_PARAMETERS_STRUCT_DEFINED_
33
33
34
34
#include < nbl/ builtin/ glsl/ loader/ mtl/ common.glsl>
35
+ #define nbl_glsl_MaterialParametersStruct nbl_glsl_MTLMaterialParameters
36
+ #endif // _NBL_FRAG_MATERIAL_PARAMETERS_STRUCT_DEFINED_
37
+
38
+ #ifndef _NBL_FRAG_PUSH_CONSTANTS_DEFINED_
39
+ #define _NBL_FRAG_PUSH_CONSTANTS_DEFINED_
35
40
36
41
layout (push_constant) uniform Block {
37
- nbl_glsl_MTLMaterialParameters params;
42
+ nbl_glsl_MaterialParametersStruct params;
38
43
} PC;
39
44
#endif // _NBL_FRAG_PUSH_CONSTANTS_DEFINED_
40
45
46
+ #ifndef _NBL_FRAG_GET_MATERIAL_PARAMETERS_FUNCTION_DEFINED_
47
+ #define _NBL_FRAG_GET_MATERIAL_PARAMETERS_FUNCTION_DEFINED_
48
+
49
+ nbl_glsl_MaterialParametersStruct nbl_glsl_getMaterialParameters()
50
+ {
51
+ return PC.params;
52
+ }
53
+ #endif // _NBL_FRAG_RETRIVE_MATERIAL_PARAMETERS_FUNCTION_DEFINED_
54
+
41
55
#if ! defined(_NBL_FRAG_SET3_BINDINGS_DEFINED_) && ! defined(_NO_UV)
42
56
#define _NBL_FRAG_SET3_BINDINGS_DEFINED_
43
57
layout (set = 3 , binding = 0 ) uniform sampler2D map_Ka;
@@ -85,39 +99,41 @@ vec4 nbl_sample_bump(in vec2 uv, in mat2 dUV) { return texture(map_bump, uv); }
85
99
// params can be either BSDFIsotropicParams or BSDFAnisotropicParams
86
100
Spectrum nbl_bsdf_cos_eval(in nbl_glsl_LightSample _sample, in nbl_glsl_IsotropicViewSurfaceInteraction inter, in mat2 dUV)
87
101
{
102
+ nbl_glsl_MaterialParametersStruct mtParams = nbl_glsl_getMaterialParameters();
103
+
88
104
vec3 Kd;
89
105
#ifndef _NO_UV
90
- if ((PC.params .extra& (map_Kd_MASK)) == (map_Kd_MASK))
106
+ if ((mtParams .extra& (map_Kd_MASK)) == (map_Kd_MASK))
91
107
Kd = nbl_sample_Kd(UV, dUV).rgb;
92
108
else
93
109
#endif
94
- Kd = PC.params .Kd;
110
+ Kd = mtParams .Kd;
95
111
96
112
vec3 color = vec3 (0.0 );
97
113
vec3 Ks;
98
114
float Ns;
99
115
100
116
#ifndef _NO_UV
101
- if ((PC.params .extra& (map_Ks_MASK)) == (map_Ks_MASK))
117
+ if ((mtParams .extra& (map_Ks_MASK)) == (map_Ks_MASK))
102
118
Ks = nbl_sample_Ks(UV, dUV).rgb;
103
119
else
104
120
#endif
105
- Ks = PC.params .Ks;
121
+ Ks = mtParams .Ks;
106
122
#ifndef _NO_UV
107
- if ((PC.params .extra& (map_Ns_MASK)) == (map_Ns_MASK))
123
+ if ((mtParams .extra& (map_Ns_MASK)) == (map_Ns_MASK))
108
124
Ns = nbl_sample_Ns(UV, dUV).x;
109
125
else
110
126
#endif
111
- Ns = PC.params .Ns;
127
+ Ns = mtParams .Ns;
112
128
113
- vec3 Ni = vec3 (PC.params .Ni);
129
+ vec3 Ni = vec3 (mtParams .Ni);
114
130
115
131
116
132
vec3 diff = nbl_glsl_lambertian_cos_eval(_sample) * Kd * (1.0 - nbl_glsl_fresnel_dielectric(Ni,_sample.NdotL)) * (1.0 - nbl_glsl_fresnel_dielectric(Ni,inter.NdotV));
117
133
diff *= nbl_glsl_diffuseFresnelCorrectionFactor(Ni, Ni* Ni);
118
134
119
135
nbl_glsl_IsotropicMicrofacetCache _cache = nbl_glsl_calcIsotropicMicrofacetCache(inter,_sample);
120
- switch (PC.params .extra& ILLUM_MODEL_MASK)
136
+ switch (mtParams .extra& ILLUM_MODEL_MASK)
121
137
{
122
138
case 0 :
123
139
color = vec3 (0.0 );
@@ -160,9 +176,10 @@ Spectrum nbl_bsdf_cos_eval(in nbl_glsl_LightSample _sample, in nbl_glsl_Isotropi
160
176
vec3 nbl_computeLighting(out nbl_glsl_IsotropicViewSurfaceInteraction out_interaction, in mat2 dUV)
161
177
{
162
178
nbl_glsl_IsotropicViewSurfaceInteraction interaction = nbl_glsl_calcSurfaceInteraction(vec3 (0.0 ), ViewPos, Normal, mat2x3 (dFdx (ViewPos),dFdy (ViewPos)));
179
+ nbl_glsl_MaterialParametersStruct mtParams = nbl_glsl_getMaterialParameters();
163
180
164
181
#ifndef _NO_UV
165
- if ((PC.params .extra& map_bump_MASK) == map_bump_MASK)
182
+ if ((mtParams .extra& map_bump_MASK) == map_bump_MASK)
166
183
{
167
184
interaction.N = normalize (interaction.N);
168
185
@@ -177,27 +194,27 @@ vec3 nbl_computeLighting(out nbl_glsl_IsotropicViewSurfaceInteraction out_intera
177
194
nbl_glsl_LightSample _sample = nbl_glsl_createLightSample(L* invLenL, interaction);
178
195
179
196
vec3 Ka;
180
- switch ((PC.params .extra& ILLUM_MODEL_MASK))
197
+ switch ((mtParams .extra& ILLUM_MODEL_MASK))
181
198
{
182
199
case 0 :
183
200
{
184
201
#ifndef _NO_UV
185
- if ((PC.params .extra& (map_Kd_MASK)) == (map_Kd_MASK))
202
+ if ((mtParams .extra& (map_Kd_MASK)) == (map_Kd_MASK))
186
203
Ka = nbl_sample_bump(UV, dUV).rgb;
187
204
else
188
205
#endif
189
- Ka = PC.params .Kd;
206
+ Ka = mtParams .Kd;
190
207
}
191
208
break ;
192
209
default :
193
210
#define Ia 0.1
194
211
{
195
212
#ifndef _NO_UV
196
- if ((PC.params .extra& (map_Ka_MASK)) == (map_Ka_MASK))
213
+ if ((mtParams .extra& (map_Ka_MASK)) == (map_Ka_MASK))
197
214
Ka = nbl_sample_Ka(UV, dUV).rgb;
198
215
else
199
216
#endif
200
- Ka = PC.params .Ka;
217
+ Ka = mtParams .Ka;
201
218
Ka *= Ia;
202
219
}
203
220
#undef Ia
@@ -222,26 +239,27 @@ void main()
222
239
#else
223
240
mat2 dUV = mat2 (vec2 (0 ,0 ),vec2 (0 ,0 ));
224
241
#endif
242
+ nbl_glsl_MaterialParametersStruct mtParams = nbl_glsl_getMaterialParameters();
225
243
nbl_glsl_IsotropicViewSurfaceInteraction interaction;
226
244
vec3 color = nbl_computeLighting(interaction, dUV);
227
245
228
- float d = PC.params .d;
246
+ float d = mtParams .d;
229
247
230
248
// another illum model switch, required for illum=4,6,7,9 to compute alpha from fresnel (taken from opacity map or constant otherwise)
231
- switch (PC.params .extra& ILLUM_MODEL_MASK)
249
+ switch (mtParams .extra& ILLUM_MODEL_MASK)
232
250
{
233
251
case 4 :
234
252
case 6 :
235
253
case 7 :
236
254
case 9 :
237
255
{
238
256
float VdotN = dot (interaction.N, interaction.V.dir);
239
- d = nbl_glsl_fresnel_dielectric(vec3 (PC.params .Ni), VdotN).x;
257
+ d = nbl_glsl_fresnel_dielectric(vec3 (mtParams .Ni), VdotN).x;
240
258
}
241
259
break ;
242
260
default :
243
261
#ifndef _NO_UV
244
- if ((PC.params .extra& (map_d_MASK)) == (map_d_MASK))
262
+ if ((mtParams .extra& (map_d_MASK)) == (map_d_MASK))
245
263
{
246
264
d = nbl_sample_d(UV, dUV).r;
247
265
color *= d;
0 commit comments