Skip to content

Commit ee4509b

Browse files
more GLSL header refactoring
1 parent 56b3134 commit ee4509b

File tree

3 files changed

+113
-91
lines changed

3 files changed

+113
-91
lines changed
Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,20 @@
1-
#ifndef _NBL_BUILTIN_SHADERS_LOADERS_MITSUBA_INSTANCE_DATA_STRUCT_GLSL_INCLUDED_
2-
#define _NBL_BUILTIN_SHADERS_LOADERS_MITSUBA_INSTANCE_DATA_STRUCT_GLSL_INCLUDED_
1+
#ifndef _NBL_BUILTIN_GLSL_EXT_MITSUBA_LOADER_INSTANCE_DATA_STRUCT_INCLUDED_
2+
#define _NBL_BUILTIN_GLSL_EXT_MITSUBA_LOADER_INSTANCE_DATA_STRUCT_INCLUDED_
33

44

5-
// split in two, DefaultInstanceData which contains irr_glsl_MC_MaterialData (all the instruction offsets and emissive stuff)
6-
struct InstanceData
5+
#include <nbl/builtin/glsl/material_compiler/common_invariant_declarations.glsl>
6+
7+
struct nbl_glsl_ext_Mitsuba_Loader_instance_data_t
78
{
89
mat4x3 tform;
910
vec3 normalMatrixRow0;
10-
uint front_instr_offset;
11+
uint padding0;
1112
vec3 normalMatrixRow1;
12-
uint front_rem_pdf_count;
13+
uint padding1;
1314
vec3 normalMatrixRow2;
14-
uint _padding;//not needed
15-
uvec2 emissive;
1615
float determinant;
17-
uint front_prefetch_count;
18-
uint front_nprecomp_count;
19-
uint front_genchoice_count;
20-
uint front_prefetch_offset;
21-
uint back_instr_offset;
22-
uint back_rem_pdf_count;
23-
uint back_prefetch_count;
24-
uint back_nprecomp_count;
25-
uint back_genchoice_count;
26-
uint back_prefetch_offset;
16+
nbl_glsl_MC_MaterialData material;
2717
};
2818

19+
2920
#endif
Lines changed: 5 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,16 @@
1-
// Copyright (C) 2018-2020 - DevSH Graphics Programming Sp. z O.O.
1+
// Copyright (C) 2018-2021 - DevSH Graphics Programming Sp. z O.O.
22
// This file is part of the "Nabla Engine".
33
// For conditions of distribution and use, see copyright notice in nabla.h
44

5-
#ifndef _NBL_BUILTIN_MATERIAL_COMPILER_GLSL_COMMON_DECLARATIONS_INCLUDED_
6-
#define _NBL_BUILTIN_MATERIAL_COMPILER_GLSL_COMMON_DECLARATIONS_INCLUDED_
5+
#ifndef _NBL_BUILTIN_GLSL_MATERIAL_COMPILER_COMMON_DECLARATIONS_INCLUDED_
6+
#define _NBL_BUILTIN_GLSL_MATERIAL_COMPILER_COMMON_DECLARATIONS_INCLUDED_
77

88
#include <nbl/builtin/glsl/virtual_texturing/extensions.glsl>
9-
#include <nbl/builtin/glsl/colorspace/encodeCIEXYZ.glsl>
10-
#include <nbl/builtin/glsl/bxdf/common.glsl>
9+
#include <nbl/builtin/glsl/material_compiler/common_invariant_declarations.glsl>
1110

12-
#define nbl_glsl_instr_t uvec2
13-
#define nbl_glsl_prefetch_instr_t uvec4
14-
#define nbl_glsl_reg_t uint
15-
#define nbl_glsl_params_t mat2x3
16-
#define nbl_glsl_bxdf_eval_t vec3
17-
#define nbl_glsl_eval_and_pdf_t vec4
18-
19-
struct nbl_glsl_bsdf_data_t
11+
struct nbl_glsl_MC_bsdf_data_t
2012
{
2113
uvec4 data[sizeof_bsdf_data];
2214
};
2315

24-
struct nbl_glsl_instr_stream_t
25-
{
26-
uint offset;
27-
uint count;
28-
};
29-
30-
// all vectors (and dot products) have untouched orientation relatively to shader inputs
31-
// therefore MC_precomputed_t::NdotV can be used to determine if we are inside a material
32-
// (in case of precomp.NdotV<0.0, currInteraction will be set with -precomp.N)
33-
struct nbl_glsl_MC_precomputed_t
34-
{
35-
vec3 N;
36-
vec3 V;
37-
vec3 pos;
38-
bool frontface;
39-
};
40-
41-
struct nbl_glsl_MC_microfacet_t
42-
{
43-
nbl_glsl_AnisotropicMicrofacetCache inner;
44-
float TdotH2;
45-
float BdotH2;
46-
};
47-
void nbl_glsl_finalizeMicrofacet(inout nbl_glsl_MC_microfacet_t mf)
48-
{
49-
mf.TdotH2 = mf.inner.TdotH * mf.inner.TdotH;
50-
mf.BdotH2 = mf.inner.BdotH * mf.inner.BdotH;
51-
}
52-
53-
struct nbl_glsl_MC_interaction_t
54-
{
55-
nbl_glsl_AnisotropicViewSurfaceInteraction inner;
56-
float TdotV2;
57-
float BdotV2;
58-
};
59-
void nbl_glsl_finalizeInteraction(inout nbl_glsl_MC_interaction_t i)
60-
{
61-
i.TdotV2 = i.inner.TdotV * i.inner.TdotV;
62-
i.BdotV2 = i.inner.BdotV * i.inner.BdotV;
63-
}
64-
65-
#define NBL_GLSL_MC_ALPHA_EPSILON 1.0e-08
66-
67-
#define NBL_GLSL_MC_CIE_XYZ_Luma_Y_coeffs transpose(nbl_glsl_sRGBtoXYZ)[1]
68-
69-
//#define MATERIAL_COMPILER_USE_SWTICH
70-
#ifdef MATERIAL_COMPILER_USE_SWTICH
71-
#define BEGIN_CASES(X) switch (X) {
72-
#define CASE_BEGIN(X,C) case C:
73-
#define CASE_END break;
74-
#define CASE_OTHERWISE default:
75-
#define END_CASES break; }
76-
#else
77-
#define BEGIN_CASES(X)
78-
#define CASE_BEGIN(X,C) if (X==C)
79-
#define CASE_END else
80-
#define CASE_OTHERWISE
81-
#define END_CASES
82-
#endif
83-
8416
#endif
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// Copyright (C) 2020-2021 - DevSH Graphics Programming Sp. z O.O.
2+
// This file is part of the "Nabla Engine".
3+
// For conditions of distribution and use, see copyright notice in nabla.h
4+
5+
#ifndef _NBL_BUILTIN_GLSL_MATERIAL_COMPILER_COMMON_INVARIANT_DECLARATIONS_INCLUDED_
6+
#define _NBL_BUILTIN_GLSL_MATERIAL_COMPILER_COMMON_INVARIANT_DECLARATIONS_INCLUDED_
7+
8+
//#define MATERIAL_COMPILER_USE_SWTICH
9+
#ifdef MATERIAL_COMPILER_USE_SWTICH
10+
#define BEGIN_CASES(X) switch (X) {
11+
#define CASE_BEGIN(X,C) case C:
12+
#define CASE_END break;
13+
#define CASE_OTHERWISE default:
14+
#define END_CASES break; }
15+
#else
16+
#define BEGIN_CASES(X)
17+
#define CASE_BEGIN(X,C) if (X==C)
18+
#define CASE_END else
19+
#define CASE_OTHERWISE
20+
#define END_CASES
21+
#endif
22+
23+
#define nbl_glsl_MC_instr_t uvec2
24+
#define nbl_glsl_MC_prefetch_instr_t uvec4
25+
#define nbl_glsl_MC_reg_t uint
26+
#define nbl_glsl_MC_params_t mat2x3
27+
#define nbl_glsl_MC_bxdf_eval_t vec3
28+
#define nbl_glsl_MC_eval_and_pdf_t vec4
29+
30+
struct nbl_glsl_MC_instr_stream_t
31+
{
32+
uint offset;
33+
uint count;
34+
};
35+
36+
// all vectors (and dot products) have untouched orientation relatively to shader inputs
37+
// therefore MC_precomputed_t::NdotV can be used to determine if we are inside a material
38+
// (in case of precomp.NdotV<0.0, currInteraction will be set with -precomp.N)
39+
struct nbl_glsl_MC_precomputed_t
40+
{
41+
vec3 N;
42+
vec3 V;
43+
vec3 pos;
44+
bool frontface;
45+
};
46+
47+
48+
#include <nbl/builtin/glsl/colorspace/encodeCIEXYZ.glsl>
49+
50+
#define NBL_GLSL_MC_CIE_XYZ_Luma_Y_coeffs transpose(nbl_glsl_sRGBtoXYZ)[1]
51+
52+
53+
#include <nbl/builtin/glsl/bxdf/common.glsl>
54+
55+
#define NBL_GLSL_MC_ALPHA_EPSILON 1.0e-08
56+
57+
struct nbl_glsl_MC_interaction_t
58+
{
59+
nbl_glsl_AnisotropicViewSurfaceInteraction inner;
60+
float TdotV2;
61+
float BdotV2;
62+
};
63+
void nbl_glsl_finalizeInteraction(inout nbl_glsl_MC_interaction_t i)
64+
{
65+
i.TdotV2 = i.inner.TdotV * i.inner.TdotV;
66+
i.BdotV2 = i.inner.BdotV * i.inner.BdotV;
67+
}
68+
69+
struct nbl_glsl_MC_microfacet_t
70+
{
71+
nbl_glsl_AnisotropicMicrofacetCache inner;
72+
float TdotH2;
73+
float BdotH2;
74+
};
75+
76+
void nbl_glsl_MC_finalizeMicrofacet(inout nbl_glsl_MC_microfacet_t mf)
77+
{
78+
mf.TdotH2 = mf.inner.TdotH * mf.inner.TdotH;
79+
mf.BdotH2 = mf.inner.BdotH * mf.inner.BdotH;
80+
}
81+
82+
83+
struct nbl_glsl_MC_instruction_ranges_t
84+
{
85+
uvec2 emissive;
86+
uint prefetch_offset;
87+
uint prefetch_count;
88+
uint instr_offset;
89+
uint rem_pdf_count;
90+
uint nprecomp_count;
91+
uint genchoice_count;
92+
};
93+
struct nbl_glsl_MC_material_data_t
94+
{
95+
nbl_glsl_MC_instruction_ranges_t front;
96+
nbl_glsl_MC_instruction_ranges_t back;
97+
};
98+
99+
#endif

0 commit comments

Comments
 (0)