[Bf-blender-cvs] [ce62cc1] bake-cycles: Cycles-Bake: Several fixes:
Brecht Van Lommel
noreply at git.blender.org
Wed Apr 23 02:46:57 CEST 2014
Commit: ce62cc1c7ab319676ec9918d4b245575dd3bee78
Author: Brecht Van Lommel
Date: Tue Feb 4 14:22:22 2014 +0100
https://developer.blender.org/rBce62cc1c7ab319676ec9918d4b245575dd3bee78
Cycles-Bake: Several fixes:
* Add code for summing multiple AA samples in PathRadiance, see path_radiance_accum_sample.
* Move #includes out of namespace to avoid having to use ::ccl::ccl
* Fix wrong initialization of RNG with hash,
* Fix light computation loop.
* Initialize incoming vector with Ng instead of zero, better not have degenerate value here.
* Use shader_emissive_eval to simplify emission pass code.
* Write files in PNG instead of JPEG format.
* Also enable linear => sRGB conversion. It should actually check if it's a
non-color data pass and avoid conversion then, but this is needed for inspecting
light passes.
===================================================================
M intern/cycles/kernel/kernel_accumulate.h
M intern/cycles/kernel/kernel_displace.h
M intern/cycles/kernel/kernel_path.h
M source/blender/editors/object/object_bake_new.c
===================================================================
diff --git a/intern/cycles/kernel/kernel_accumulate.h b/intern/cycles/kernel/kernel_accumulate.h
index 582a220..82450b7 100644
--- a/intern/cycles/kernel/kernel_accumulate.h
+++ b/intern/cycles/kernel/kernel_accumulate.h
@@ -407,5 +407,26 @@ ccl_device_inline float3 path_radiance_clamp_and_sum(KernelGlobals *kg, PathRadi
return L_sum;
}
+ccl_device_inline void path_radiance_accum_sample(PathRadiance *L, PathRadiance *L_sample, int num_samples)
+{
+ float fac = 1.0f/num_samples;
+
+ L->direct_diffuse += L_sample->direct_diffuse*fac;
+ L->direct_glossy += L_sample->direct_glossy*fac;
+ L->direct_transmission += L_sample->direct_transmission*fac;
+ L->direct_subsurface += L_sample->direct_subsurface*fac;
+
+ L->indirect_diffuse += L_sample->indirect_diffuse*fac;
+ L->indirect_glossy += L_sample->indirect_glossy*fac;
+ L->indirect_transmission += L_sample->indirect_transmission*fac;
+ L->indirect_subsurface += L_sample->indirect_subsurface*fac;
+
+ L->emission += L_sample->emission*fac;
+ L->background += L_sample->background*fac;
+ L->ao += L_sample->ao*fac;
+ L->shadow += L_sample->shadow*fac;
+ L->mist += L_sample->mist*fac;
+}
+
CCL_NAMESPACE_END
diff --git a/intern/cycles/kernel/kernel_displace.h b/intern/cycles/kernel/kernel_displace.h
index be87318..2a41d19 100644
--- a/intern/cycles/kernel/kernel_displace.h
+++ b/intern/cycles/kernel/kernel_displace.h
@@ -14,54 +14,53 @@
* limitations under the License
*/
-CCL_NAMESPACE_BEGIN
-
#include "util_hash.h"
#include "kernel_primitive.h"
-ccl_device void compute_light_pass(KernelGlobals *kg, ShaderData *sd, PathRadiance *L, uint xy_hash)
+CCL_NAMESPACE_BEGIN
+
+ccl_device void compute_light_pass(KernelGlobals *kg, ShaderData *sd, PathRadiance *L, RNG rng)
{
int samples = kernel_data.integrator.samples;
- RNG rng = lcg_init(xy_hash);
- PathState state;
- Ray ray;
-
- /* initialize */
- float3 throughput = make_float3(1.0f, 1.0f, 1.0f);
+ /* initialize master radiance accumulator */
assert(kernel_data.film.use_light_pass);
- path_radiance_init(L, true);
+ path_radiance_init(L, kernel_data.film.use_light_pass);
- path_state_init(kg, &state, &rng, 0);
- state.num_samples = samples;
+ /* take multiple samples */
+ for(int sample = 0; sample < samples; sample++) {
+ PathRadiance L_sample;
+ PathState state;
+ Ray ray;
+ float3 throughput = make_float3(1.0f, 1.0f, 1.0f);
- float rbsdf = path_state_rng_1D(kg, &rng, &state, PRNG_BSDF);
+ /* init radiance */
+ path_radiance_init(&L_sample, kernel_data.film.use_light_pass);
- shader_eval_surface(kg, sd, rbsdf, 0, SHADER_CONTEXT_MAIN);
- for(int i = 0; i < kernel_data.integrator.max_bounce; i++) {
- if (kernel_path_integrate_lighting(kg, &rng, sd, &throughput, &state, L, &ray) == false)
- break;
- }
+ /* init path state */
+ path_state_init(kg, &state, &rng, sample);
+ state.num_samples = samples;
+ /* evaluate surface shader */
+ float rbsdf = path_state_rng_1D(kg, &rng, &state, PRNG_BSDF);
+ shader_eval_surface(kg, sd, rbsdf, state.flag, SHADER_CONTEXT_MAIN);
- /** XXX
- hack to see something (only runs for odd samples values, so you can turn it on/off
- here it starts showing something if I multiply the value by 11
- (i.e., set the scene render samples to 11)
- */
- if (samples % 2){
- float3 factor = make_float3(samples);
-
- L->direct_diffuse *= factor;
- L->direct_emission *= factor;
- L->direct_glossy *= factor;
- L->direct_subsurface *= factor;
- L->direct_transmission *= factor;
-
- L->indirect_diffuse *= factor;
- L->indirect_glossy *= factor;
- L->indirect_subsurface *= factor;
- L->indirect_transmission *= factor;
+ /* sample light and BSDF */
+ if(kernel_path_integrate_lighting(kg, &rng, sd, &throughput, &state, &L_sample, &ray)) {
+#ifdef __LAMP_MIS__
+ state.ray_t = 0.0f;
+#endif
+
+ /* compute indirect light */
+ kernel_path_indirect(kg, &rng, ray, throughput, state.num_samples, state, &L_sample);
+
+ /* sum and reset indirect light pass variables for the next samples */
+ path_radiance_sum_indirect(&L_sample);
+ path_radiance_reset_indirect(&L_sample);
+ }
+
+ /* accumulate into master L */
+ path_radiance_accum_sample(L, &L_sample, samples);
}
}
@@ -109,8 +108,8 @@ ccl_device void kernel_bake_evaluate(KernelGlobals *kg, ccl_global uint4 *input,
float3 Ng = triangle_normal_MT(kg, prim, &shader);
/* dummy initilizations copied from SHADER_EVAL_DISPLACE */
- float3 I = make_float3(0.f);
- float t = 0.f;
+ float3 I = Ng;
+ float t = 0.0f;
float time = TIME_INVALID;
int bounce = 0;
int segment = ~0;
@@ -122,8 +121,8 @@ ccl_device void kernel_bake_evaluate(KernelGlobals *kg, ccl_global uint4 *input,
shader_setup_from_sample(kg, &sd, P, Ng, I, shader, object, prim, u, v, t, time, bounce, segment);
if (is_light_pass(type)){
- uint xy_hash = ::ccl::ccl::hash_int_2d(in.x, in.y);
- compute_light_pass(kg, &sd, &L, xy_hash);
+ RNG rng = hash_int(i);
+ compute_light_pass(kg, &sd, &L, rng);
}
switch (type) {
@@ -166,23 +165,7 @@ ccl_device void kernel_bake_evaluate(KernelGlobals *kg, ccl_global uint4 *input,
case SHADER_EVAL_EMISSION:
{
shader_eval_surface(kg, &sd, 0.f, 0, SHADER_CONTEXT_EMISSION);
-
-#ifdef __MULTI_CLOSURE__
- float3 eval = make_float3(0.0f, 0.0f, 0.0f);
-
- for(int i = 0; i< sd.num_closure; i++) {
- const ShaderClosure *sc = &sd.closure[i];
- if(sc->type == CLOSURE_EMISSION_ID)
- eval += sc->weight;
- }
-
- out = eval;
-#else
- if(sd.closure.type == CLOSURE_EMISSION_ID)
- out = sd.closure.weight;
- else
- out = make_float3(0.0f, 0.0f, 0.0f);
-#endif
+ out = shader_emissive_eval(kg, &sd);
break;
}
diff --git a/intern/cycles/kernel/kernel_path.h b/intern/cycles/kernel/kernel_path.h
index 0c4d15d..bf49922 100644
--- a/intern/cycles/kernel/kernel_path.h
+++ b/intern/cycles/kernel/kernel_path.h
@@ -212,7 +212,7 @@ ccl_device void kernel_branched_path_integrate_direct_lighting(KernelGlobals *kg
}
}
-ccl_device void kernel_path_indirect(KernelGlobals *kg, RNG *rng, Ray ray, ccl_global float *buffer,
+ccl_device void kernel_path_indirect(KernelGlobals *kg, RNG *rng, Ray ray,
float3 throughput, int num_samples, PathState state, PathRadiance *L)
{
/* path iteration */
@@ -805,7 +805,7 @@ ccl_device float4 kernel_path_integrate(KernelGlobals *kg, RNG *rng, int sample,
hit_state.ray_t = 0.0f;
#endif
- kernel_path_indirect(kg, rng, hit_ray, buffer, tp, state.num_samples, hit_state, &L);
+ kernel_path_indirect(kg, rng, hit_ray, tp, state.num_samples, hit_state, &L);
/* for render passes, sum and reset indirect light pass variables
* for the next samples */
@@ -1024,7 +1024,7 @@ ccl_device_noinline void kernel_branched_path_integrate_lighting(KernelGlobals *
ps.ray_t = 0.0f;
#endif
- kernel_path_indirect(kg, rng, bsdf_ray, buffer, tp*num_samples_inv, num_samples, ps, L);
+ kernel_path_indirect(kg, rng, bsdf_ray, tp*num_samples_inv, num_samples, ps, L);
/* for render passes, sum and reset indirect light pass variables
* for the next samples */
@@ -1112,7 +1112,7 @@ ccl_device float4 kernel_branched_path_integrate(KernelGlobals *kg, RNG *rng, in
if(result == VOLUME_PATH_SCATTERED) {
/* todo: use all-light sampling */
if(kernel_path_integrate_scatter_lighting(kg, rng, &volume_sd, &tp, &ps, &L, &pray, num_samples_inv)) {
- kernel_path_indirect(kg, rng, pray, buffer, tp*num_samples_inv, num_samples, ps, &L);
+ kernel_path_indirect(kg, rng, pray, tp*num_samples_inv, num_samples, ps, &L);
/* for render passes, sum and reset indirect light pass variables
* for the next samples */
diff --git a/source/blender/editors/object/object_bake_new.c b/source/blender/editors/object/object_bake_new.c
index f3b588d..7170806 100644
--- a/source/blender/editors/object/object_bake_new.c
+++ b/source/blender/editors/object/object_bake_new.c
@@ -147,11 +147,12 @@ static bool write_external_bake_pixels(const char *filepath, float *buffer, cons
if (!ibuf) return NULL;
/* populates the ImBuf */
- IMB_buffer_byte_from_float((unsigned char *) ibuf->rect, buffer, ibuf->channels, ibuf->dither, IB_PROFILE_SRGB, IB_PROFILE_SRGB,
+ /* TODO it now does linear => sRGB, but should not do that for non-color data passes */
+ IMB_buffer_byte_from_float((unsigned char *) ibuf->rect, buffer, ibuf->channels, ibuf->dither, IB_PROFILE_SRGB, IB_PROFILE_LINEAR_RGB,
FALSE, ibuf->x, ibuf->y, ibuf->x, ibuf->x);
/* setup the Imbuf*/
- ibuf->ftype = JPG;
+ ibuf->ftype = PNG;
if ((ok=IMB_saveiff(ibuf, filepath, IB_rect))) {
#ifndef WIN32
More information about the Bf-blender-cvs
mailing list