1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_surface_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_bsdf_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_gbuffer_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_nodetree_eval_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_sampling_lib.glsl)
/* TODO(fclem): Renderpasses. */
#define output_renderpass(a, b, c, d)
void main(void)
{
g_data = init_globals();
float noise_offset = sampling_rng_1D_get(sampling_buf, SAMPLING_CLOSURE);
float noise = utility_tx_fetch(utility_tx, gl_FragCoord.xy, UTIL_BLUE_NOISE_LAYER).r;
g_data.closure_rand = fract(noise + noise_offset);
/* TODO(fclem) other RNG. */
g_data.transmit_rand = fract(g_data.closure_rand * 6.1803398875);
float thickness = nodetree_thickness();
nodetree_surface();
out_transmittance = vec4(1.0 - g_transparency_data.holdout);
float transmittance_mono = saturate(avg(g_transparency_data.transmittance));
#if 1 /* TODO(fclem): Alpha clipped materials. */
/* Apply transmittance. */
out_transmittance *= vec4(g_transparency_data.transmittance, transmittance_mono);
#else
/* Stochastique monochromatic transmittance.
* Pixels are discarded based on alpha. We need to compensate the applied transmittance
* term on all radiance channels. */
if (transmittance_mono < 1.0) {
float alpha = 1.0 - transmittance_mono;
g_diffuse_data.color /= alpha;
g_reflection_data.color /= alpha;
g_refraction_data.color /= alpha;
g_emission_data.emission /= alpha;
}
#endif
out_radiance = vec4(g_emission_data.emission, g_transparency_data.holdout);
#ifdef MATERIAL_EMISSION
output_renderpass(rpass_emission, transmittance, vec4(g_emission_data.emission, 0.0));
#endif
#ifdef MATERIAL_VOLUME
output_renderpass(rpass_volume_light, transmittance, vec4(, 0.0));
#endif
if (gl_FrontFacing) {
g_refraction_data.ior = safe_rcp(g_refraction_data.ior);
}
vec3 V = cameraVec(g_data.P);
g_reflection_data.N = ensure_valid_reflection(g_data.Ng, V, g_reflection_data.N);
ivec2 out_texel = ivec2(gl_FragCoord.xy);
if (true) {
vec4 out_color;
out_color.xyz = g_reflection_data.color;
imageStore(gbuff_reflection_color, out_texel, out_color);
vec4 out_normal;
out_normal.xy = gbuffer_encode_normal(g_reflection_data.N);
out_normal.z = max(1e-4, g_reflection_data.roughness);
imageStore(gbuff_reflection_normal, out_texel, out_normal);
}
if (g_data.transmit_rand == 0.0) {
vec4 out_color;
out_color.xyz = g_refraction_data.color;
imageStore(gbuff_transmit_color, out_texel, out_color);
vec4 out_normal;
out_normal.xy = gbuffer_encode_normal(g_refraction_data.N);
out_normal.z = -1.0;
out_normal.w = thickness;
imageStore(gbuff_transmit_normal, out_texel, out_normal);
vec4 out_data;
out_data.x = g_refraction_data.ior;
out_data.y = g_refraction_data.roughness;
imageStore(gbuff_transmit_data, out_texel, out_data);
}
else {
/* Output diffuse / SSS in transmit data. */
vec4 out_color;
out_color.xyz = g_diffuse_data.color;
imageStore(gbuff_transmit_color, out_texel, out_color);
vec4 out_normal;
out_normal.xy = gbuffer_encode_normal(g_diffuse_data.N);
out_normal.z = (g_diffuse_data.sss_id == 1u) ? fract(float(resource_handle + 1) / 1024.0) : 0;
out_normal.w = thickness;
imageStore(gbuff_transmit_normal, out_texel, out_normal);
vec4 out_data;
out_data.xyz = g_diffuse_data.sss_radius;
imageStore(gbuff_transmit_data, out_texel, out_data);
}
}
|