Paste P526

Fix for T52433
ActivePublic

Authored by Sergey Sharybin (sergey) on Sep 5 2017, 1:31 PM.
Tags
None
Subscribers
None
1diff --git a/intern/cycles/kernel/kernel_path.h b/intern/cycles/kernel/kernel_path.h
2index ec8c297fbd5..3319e2c2435 100644
3--- a/intern/cycles/kernel/kernel_path.h
4+++ b/intern/cycles/kernel/kernel_path.h
5@@ -84,7 +84,7 @@ ccl_device_noinline void kernel_path_ao(KernelGlobals *kg,
6​ light_ray.dP = sd->dP;
7​ light_ray.dD = differential3_zero();
8
9- if(!shadow_blocked(kg, emission_sd, state, &light_ray, &ao_shadow)) {
10+ if(!shadow_blocked(kg, sd, emission_sd, state, &light_ray, &ao_shadow)) {
11​ path_radiance_accum_ao(L, state, throughput, ao_alpha, ao_bsdf, ao_shadow);
12​ }
13​ else {
14diff --git a/intern/cycles/kernel/kernel_path_branched.h b/intern/cycles/kernel/kernel_path_branched.h
15index c62c3a25405..dde40674ee6 100644
16--- a/intern/cycles/kernel/kernel_path_branched.h
17+++ b/intern/cycles/kernel/kernel_path_branched.h
18@@ -54,7 +54,7 @@ ccl_device_inline void kernel_branched_path_ao(KernelGlobals *kg,
19​ light_ray.dP = sd->dP;
20​ light_ray.dD = differential3_zero();
21
22- if(!shadow_blocked(kg, emission_sd, state, &light_ray, &ao_shadow)) {
23+ if(!shadow_blocked(kg, sd, emission_sd, state, &light_ray, &ao_shadow)) {
24​ path_radiance_accum_ao(L, state, throughput*num_samples_inv, ao_alpha, ao_bsdf, ao_shadow);
25​ }
26​ else {
27diff --git a/intern/cycles/kernel/kernel_path_surface.h b/intern/cycles/kernel/kernel_path_surface.h
28index 3d10736e90c..6c3a444e48a 100644
29--- a/intern/cycles/kernel/kernel_path_surface.h
30+++ b/intern/cycles/kernel/kernel_path_surface.h
31@@ -67,7 +67,7 @@ ccl_device_noinline void kernel_branched_path_surface_connect_light(
32​ /* trace shadow ray */
33​ float3 shadow;
34
35- if(!shadow_blocked(kg, emission_sd, state, &light_ray, &shadow)) {
36+ if(!shadow_blocked(kg, sd, emission_sd, state, &light_ray, &shadow)) {
37​ /* accumulate */
38​ path_radiance_accum_light(L, state, throughput*num_samples_inv, &L_light, shadow, num_samples_inv, is_lamp);
39​ }
40@@ -104,7 +104,7 @@ ccl_device_noinline void kernel_branched_path_surface_connect_light(
41​ /* trace shadow ray */
42​ float3 shadow;
43
44- if(!shadow_blocked(kg, emission_sd, state, &light_ray, &shadow)) {
45+ if(!shadow_blocked(kg, sd, emission_sd, state, &light_ray, &shadow)) {
46​ /* accumulate */
47​ path_radiance_accum_light(L, state, throughput*num_samples_inv, &L_light, shadow, num_samples_inv, is_lamp);
48​ }
49@@ -130,7 +130,7 @@ ccl_device_noinline void kernel_branched_path_surface_connect_light(
50​ /* trace shadow ray */
51​ float3 shadow;
52
53- if(!shadow_blocked(kg, emission_sd, state, &light_ray, &shadow)) {
54+ if(!shadow_blocked(kg, sd, emission_sd, state, &light_ray, &shadow)) {
55​ /* accumulate */
56​ path_radiance_accum_light(L, state, throughput*num_samples_adjust, &L_light, shadow, num_samples_adjust, is_lamp);
57​ }
58@@ -257,7 +257,7 @@ ccl_device_inline void kernel_path_surface_connect_light(KernelGlobals *kg,
59​ /* trace shadow ray */
60​ float3 shadow;
61
62- if(!shadow_blocked(kg, emission_sd, state, &light_ray, &shadow)) {
63+ if(!shadow_blocked(kg, sd, emission_sd, state, &light_ray, &shadow)) {
64​ /* accumulate */
65​ path_radiance_accum_light(L, state, throughput, &L_light, shadow, 1.0f, is_lamp);
66​ }
67diff --git a/intern/cycles/kernel/kernel_path_volume.h b/intern/cycles/kernel/kernel_path_volume.h
68index 3661432f0b7..c9c7f447c42 100644
69--- a/intern/cycles/kernel/kernel_path_volume.h
70+++ b/intern/cycles/kernel/kernel_path_volume.h
71@@ -52,7 +52,7 @@ ccl_device_inline void kernel_path_volume_connect_light(
72​ /* trace shadow ray */
73​ float3 shadow;
74
75- if(!shadow_blocked(kg, emission_sd, state, &light_ray, &shadow)) {
76+ if(!shadow_blocked(kg, sd, emission_sd, state, &light_ray, &shadow)) {
77​ /* accumulate */
78​ path_radiance_accum_light(L, state, throughput, &L_light, shadow, 1.0f, is_lamp);
79​ }
80@@ -179,7 +179,7 @@ ccl_device void kernel_branched_path_volume_connect_light(
81​ /* trace shadow ray */
82​ float3 shadow;
83
84- if(!shadow_blocked(kg, emission_sd, state, &light_ray, &shadow)) {
85+ if(!shadow_blocked(kg, sd, emission_sd, state, &light_ray, &shadow)) {
86​ /* accumulate */
87​ path_radiance_accum_light(L, state, tp*num_samples_inv, &L_light, shadow, num_samples_inv, is_lamp);
88​ }
89@@ -228,7 +228,7 @@ ccl_device void kernel_branched_path_volume_connect_light(
90​ /* trace shadow ray */
91​ float3 shadow;
92
93- if(!shadow_blocked(kg, emission_sd, state, &light_ray, &shadow)) {
94+ if(!shadow_blocked(kg, sd, emission_sd, state, &light_ray, &shadow)) {
95​ /* accumulate */
96​ path_radiance_accum_light(L, state, tp*num_samples_inv, &L_light, shadow, num_samples_inv, is_lamp);
97​ }
98@@ -266,7 +266,7 @@ ccl_device void kernel_branched_path_volume_connect_light(
99​ /* trace shadow ray */
100​ float3 shadow;
101
102- if(!shadow_blocked(kg, emission_sd, state, &light_ray, &shadow)) {
103+ if(!shadow_blocked(kg, sd, emission_sd, state, &light_ray, &shadow)) {
104​ /* accumulate */
105​ path_radiance_accum_light(L, state, tp, &L_light, shadow, 1.0f, is_lamp);
106​ }
107diff --git a/intern/cycles/kernel/kernel_shadow.h b/intern/cycles/kernel/kernel_shadow.h
108index bb6bdc7fbd0..c53ca6135f8 100644
109--- a/intern/cycles/kernel/kernel_shadow.h
110+++ b/intern/cycles/kernel/kernel_shadow.h
111@@ -119,12 +119,43 @@ ccl_device bool shadow_blocked_opaque(KernelGlobals *kg,
112
113​ # define SHADOW_STACK_MAX_HITS 64
114
115+# ifdef __VOLUME__
116+struct VolumeState {
117+# ifdef __SPLIT_KERNEL__
118+# else
119+ PathState ps;
120+# endif
121+};
122+
123+/* Get PathState ready for use for volume stack evaluation. */
124+ccl_device_inline PathState *shadow_blocked_volume_path_state(
125+ KernelGlobals *kg,
126+ VolumeState *volume_state,
127+ ccl_addr_space PathState *state,
128+ ShaderData *sd)
129+{
130+# ifdef __SPLIT_KERNEL__
131+ ccl_addr_space PathState *ps =
132+ &kernel_split_state.state_shadow[ccl_global_id(1) * ccl_global_size(0) + ccl_global_id(0)];
133+# else
134+ PathState *ps = &volume_state->ps;
135+# endif
136+ *ps = *state;
137+ /* We are checking for shadow on the "other" side of the surface, so need
138+ * to discard volume we are currently at.
139+ */
140+ kernel_volume_stack_enter_exit(kg, sd, ps->volume_stack);
141+ return ps;
142+}
143+#endif // __VOLUME__
144+
145​ /* Actual logic with traversal loop implementation which is free from device
146​ * specific tweaks.
147​ *
148​ * Note that hits array should be as big as max_hits+1.
149​ */
150​ ccl_device bool shadow_blocked_transparent_all_loop(KernelGlobals *kg,
151+ ShaderData *sd,
152​ ShaderData *shadow_sd,
153​ ccl_addr_space PathState *state,
154​ const uint visibility,
155@@ -143,6 +174,9 @@ ccl_device bool shadow_blocked_transparent_all_loop(KernelGlobals *kg,
156​ visibility,
157​ max_hits,
158​ &num_hits);
159+# ifdef __VOLUME__
160+ VolumeState volume_state;
161+# endif
162​ /* If no opaque surface found but we did find transparent hits,
163​ * shade them.
164​ */
165@@ -153,13 +187,10 @@ ccl_device bool shadow_blocked_transparent_all_loop(KernelGlobals *kg,
166​ int bounce = state->transparent_bounce;
167​ Intersection *isect = hits;
168​ # ifdef __VOLUME__
169-# ifdef __SPLIT_KERNEL__
170- ccl_addr_space PathState *ps = &kernel_split_state.state_shadow[ccl_global_id(1) * ccl_global_size(0) + ccl_global_id(0)];
171-# else
172- PathState ps_object;
173- PathState *ps = &ps_object;
174-# endif
175- *ps = *state;
176+ PathState *ps = shadow_blocked_volume_path_state(kg,
177+ &volume_state,
178+ state,
179+ sd);
180​ # endif
181​ sort_intersections(hits, num_hits);
182​ for(int hit = 0; hit < num_hits; hit++, isect++) {
183@@ -205,7 +236,11 @@ ccl_device bool shadow_blocked_transparent_all_loop(KernelGlobals *kg,
184​ # ifdef __VOLUME__
185​ if(!blocked && state->volume_stack[0].shader != SHADER_NONE) {
186​ /* Apply attenuation from current volume shader. */
187- kernel_volume_shadow(kg, shadow_sd, state, ray, shadow);
188+ PathState *ps = shadow_blocked_volume_path_state(kg,
189+ &volume_state,
190+ state,
191+ sd);
192+ kernel_volume_shadow(kg, shadow_sd, ps, ray, shadow);
193​ }
194​ # endif
195​ return blocked;
196@@ -215,6 +250,7 @@ ccl_device bool shadow_blocked_transparent_all_loop(KernelGlobals *kg,
197​ * loop to help readability of the actual logic.
198​ */
199​ ccl_device bool shadow_blocked_transparent_all(KernelGlobals *kg,
200+ ShaderData *sd,
201​ ShaderData *shadow_sd,
202​ ccl_addr_space PathState *state,
203​ const uint visibility,
204@@ -250,6 +286,7 @@ ccl_device bool shadow_blocked_transparent_all(KernelGlobals *kg,
205​ # endif /* __KERNEL_GPU__ */
206​ /* Invoke actual traversal. */
207​ return shadow_blocked_transparent_all_loop(kg,
208+ sd,
209​ shadow_sd,
210​ state,
211​ visibility,
212@@ -275,6 +312,7 @@ ccl_device bool shadow_blocked_transparent_all(KernelGlobals *kg,
213​ */
214​ ccl_device bool shadow_blocked_transparent_stepped_loop(
215​ KernelGlobals *kg,
216+ ShaderData *sd,
217​ ShaderData *shadow_sd,
218​ ccl_addr_space PathState *state,
219​ const uint visibility,
220@@ -284,18 +322,18 @@ ccl_device bool shadow_blocked_transparent_stepped_loop(
221​ const bool is_transparent_isect,
222​ float3 *shadow)
223​ {
224+# ifdef __VOLUME__
225+ VolumeState volume_state;
226+# endif
227​ if(blocked && is_transparent_isect) {
228​ float3 throughput = make_float3(1.0f, 1.0f, 1.0f);
229​ float3 Pend = ray->P + ray->D*ray->t;
230​ int bounce = state->transparent_bounce;
231​ # ifdef __VOLUME__
232-# ifdef __SPLIT_KERNEL__
233- ccl_addr_space PathState *ps = &kernel_split_state.state_shadow[ccl_global_id(1) * ccl_global_size(0) + ccl_global_id(0)];
234-# else
235- PathState ps_object;
236- PathState *ps = &ps_object;
237-# endif
238- *ps = *state;
239+ PathState *ps = shadow_blocked_volume_path_state(kg,
240+ &volume_state,
241+ state,
242+ sd);
243​ # endif
244​ for(;;) {
245​ if(bounce >= kernel_data.integrator.transparent_max_bounce) {
246@@ -345,7 +383,11 @@ ccl_device bool shadow_blocked_transparent_stepped_loop(
247​ # ifdef __VOLUME__
248​ if(!blocked && state->volume_stack[0].shader != SHADER_NONE) {
249​ /* Apply attenuation from current volume shader. */
250- kernel_volume_shadow(kg, shadow_sd, state, ray, shadow);
251+ PathState *ps = shadow_blocked_volume_path_state(kg,
252+ &volume_state,
253+ state,
254+ sd);
255+ kernel_volume_shadow(kg, shadow_sd, ps, ray, shadow);
256​ }
257​ # endif
258​ return blocked;
259@@ -353,6 +395,7 @@ ccl_device bool shadow_blocked_transparent_stepped_loop(
260
261​ ccl_device bool shadow_blocked_transparent_stepped(
262​ KernelGlobals *kg,
263+ ShaderData *sd,
264​ ShaderData *shadow_sd,
265​ ccl_addr_space PathState *state,
266​ const uint visibility,
267@@ -370,6 +413,7 @@ ccl_device bool shadow_blocked_transparent_stepped(
268​ ? shader_transparent_shadow(kg, isect)
269​ : false;
270​ return shadow_blocked_transparent_stepped_loop(kg,
271+ sd,
272​ shadow_sd,
273​ state,
274​ visibility,
275@@ -384,6 +428,7 @@ ccl_device bool shadow_blocked_transparent_stepped(
276​ #endif /* __TRANSPARENT_SHADOWS__ */
277
278​ ccl_device_inline bool shadow_blocked(KernelGlobals *kg,
279+ ShaderData *sd,
280​ ShaderData *shadow_sd,
281​ ccl_addr_space PathState *state,
282​ Ray *ray_input,
283@@ -452,6 +497,7 @@ ccl_device_inline bool shadow_blocked(KernelGlobals *kg,
284​ max_hits + 1 >= SHADOW_STACK_MAX_HITS)
285​ {
286​ return shadow_blocked_transparent_stepped_loop(kg,
287+ sd,
288​ shadow_sd,
289​ state,
290​ visibility,
291@@ -463,6 +509,7 @@ ccl_device_inline bool shadow_blocked(KernelGlobals *kg,
292​ }
293​ # endif /* __KERNEL_GPU__ */
294​ return shadow_blocked_transparent_all(kg,
295+ sd,
296​ shadow_sd,
297​ state,
298​ visibility,
299diff --git a/intern/cycles/kernel/split/kernel_shadow_blocked_dl.h b/intern/cycles/kernel/split/kernel_shadow_blocked_dl.h
300index 19bfee6d039..b52f9a5eb81 100644
301--- a/intern/cycles/kernel/split/kernel_shadow_blocked_dl.h
302+++ b/intern/cycles/kernel/split/kernel_shadow_blocked_dl.h
303@@ -89,6 +89,7 @@ ccl_device void kernel_shadow_blocked_dl(KernelGlobals *kg)
304​ float3 shadow;
305
306​ if(!shadow_blocked(kg,
307+ sd,
308​ emission_sd,
309​ state,
310​ &ray,