From 238f3a7d343875992f5b9c2ad657f2bc6f148938 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Sat, 29 Oct 2011 14:27:24 +0000 Subject: Cycles: seed value to get different noise values from renders, there was a patch for this but I've implemented it differently. --- intern/cycles/blender/addon/properties.py | 3 +++ intern/cycles/blender/addon/ui.py | 3 ++- intern/cycles/blender/blender_sync.cpp | 2 ++ intern/cycles/kernel/kernel_random.h | 6 ++++++ intern/cycles/kernel/kernel_types.h | 4 +++- intern/cycles/render/integrator.cpp | 9 ++++++++- intern/cycles/render/integrator.h | 3 +++ intern/cycles/util/util_hash.h | 5 +++++ 8 files changed, 32 insertions(+), 3 deletions(-) diff --git a/intern/cycles/blender/addon/properties.py b/intern/cycles/blender/addon/properties.py index 6fab3ecaa68..0d30307fc73 100644 --- a/intern/cycles/blender/addon/properties.py +++ b/intern/cycles/blender/addon/properties.py @@ -78,6 +78,9 @@ class CyclesRenderSettings(bpy.types.PropertyGroup): cls.filter_width = FloatProperty(name="Filter Width", description="Pixel filter width", default=1.5, min=0.01, max=10.0) + cls.seed = IntProperty(name="Seed", description="Seed value for integrator to get different noise patterns", + default=0, min=0, max=2147483647) + cls.debug_tile_size = IntProperty(name="Tile Size", description="", default=1024, min=1, max=4096) cls.debug_min_size = IntProperty(name="Min Size", description="", diff --git a/intern/cycles/blender/addon/ui.py b/intern/cycles/blender/addon/ui.py index f9e178a2d3a..ca077a50ad6 100644 --- a/intern/cycles/blender/addon/ui.py +++ b/intern/cycles/blender/addon/ui.py @@ -62,13 +62,13 @@ class CyclesRender_PT_integrator(CyclesButtonsPanel, Panel): sub.label(text="Samples:") sub.prop(cscene, "samples", text="Render") sub.prop(cscene, "preview_samples", text="Preview") + sub.prop(cscene, "seed") sub = col.column(align=True) sub.label("Transparency:") sub.prop(cscene, "transparent_max_bounces", text="Max") sub.prop(cscene, "transparent_min_bounces", text="Min") sub.prop(cscene, "use_transparent_shadows", text="Shadows") - sub.prop(cscene, "no_caustics") col = split.column() @@ -82,6 +82,7 @@ class CyclesRender_PT_integrator(CyclesButtonsPanel, Panel): sub.prop(cscene, "diffuse_bounces", text="Diffuse") sub.prop(cscene, "glossy_bounces", text="Glossy") sub.prop(cscene, "transmission_bounces", text="Transmission") + sub.prop(cscene, "no_caustics") #row = col.row() #row.prop(cscene, "blur_caustics") diff --git a/intern/cycles/blender/blender_sync.cpp b/intern/cycles/blender/blender_sync.cpp index 4babb612bdd..3a9514efa3c 100644 --- a/intern/cycles/blender/blender_sync.cpp +++ b/intern/cycles/blender/blender_sync.cpp @@ -151,6 +151,8 @@ void BlenderSync::sync_integrator() integrator->no_caustics = get_boolean(cscene, "no_caustics"); integrator->blur_caustics = get_float(cscene, "blur_caustics"); + integrator->seed = get_int(cscene, "seed"); + if(integrator->modified(previntegrator)) integrator->tag_update(scene); } diff --git a/intern/cycles/kernel/kernel_random.h b/intern/cycles/kernel/kernel_random.h index 13cf4df8b8c..df876e6f726 100644 --- a/intern/cycles/kernel/kernel_random.h +++ b/intern/cycles/kernel/kernel_random.h @@ -128,11 +128,15 @@ __device_inline void path_rng_init(KernelGlobals *kg, __global uint *rng_state, *rng = sobol_lookup(bits, frame, x, y, &px, &py); + *rng ^= kernel_data.integrator.seed; + *fx = size * (float)px * (1.0f/(float)0xFFFFFFFF) - x; *fy = size * (float)py * (1.0f/(float)0xFFFFFFFF) - y; #else *rng = rng_state[x + y*kernel_data.cam.width]; + *rng ^= kernel_data.integrator.seed; + *fx = path_rng(kg, rng, sample, PRNG_FILTER_U); *fy = path_rng(kg, rng, sample, PRNG_FILTER_V); #endif @@ -159,6 +163,8 @@ __device void path_rng_init(KernelGlobals *kg, __global uint *rng_state, int sam /* load state */ *rng = rng_state[x + y*kernel_data.cam.width]; + *rng ^= kernel_data.integrator.seed; + *fx = path_rng(kg, rng, sample, PRNG_FILTER_U); *fy = path_rng(kg, rng, sample, PRNG_FILTER_V); } diff --git a/intern/cycles/kernel/kernel_types.h b/intern/cycles/kernel/kernel_types.h index d8270b2cd71..46cdcd1151e 100644 --- a/intern/cycles/kernel/kernel_types.h +++ b/intern/cycles/kernel/kernel_types.h @@ -362,7 +362,6 @@ typedef struct KernelIntegrator { int num_all_lights; float pdf_triangles; float pdf_lights; - float pdf_pad; /* bounces */ int min_bounce; @@ -380,6 +379,9 @@ typedef struct KernelIntegrator { /* caustics */ int no_caustics; float blur_caustics; + + /* seed */ + int seed; } KernelIntegrator; typedef struct KernelBVH { diff --git a/intern/cycles/render/integrator.cpp b/intern/cycles/render/integrator.cpp index 78ea464d836..9d129d8e8db 100644 --- a/intern/cycles/render/integrator.cpp +++ b/intern/cycles/render/integrator.cpp @@ -21,6 +21,8 @@ #include "scene.h" #include "sobol.h" +#include "util_hash.h" + CCL_NAMESPACE_BEGIN Integrator::Integrator() @@ -41,6 +43,8 @@ Integrator::Integrator() no_caustics = false; blur_caustics = 0.0f; + seed = 0; + need_update = true; } @@ -79,6 +83,8 @@ void Integrator::device_update(Device *device, DeviceScene *dscene) kintegrator->no_caustics = no_caustics; kintegrator->blur_caustics = blur_caustics; + kintegrator->seed = hash_int(seed); + /* sobol directions table */ int dimensions = PRNG_BASE_NUM + (max_bounce + transparent_max_bounce + 2)*PRNG_BOUNCE_NUM; uint *directions = dscene->sobol_directions.resize(SOBOL_BITS*dimensions); @@ -109,7 +115,8 @@ bool Integrator::modified(const Integrator& integrator) transparent_probalistic == integrator.transparent_probalistic && transparent_shadows == integrator.transparent_shadows && no_caustics == integrator.no_caustics && - blur_caustics == integrator.blur_caustics); + blur_caustics == integrator.blur_caustics && + seed == integrator.seed); } void Integrator::tag_update(Scene *scene) diff --git a/intern/cycles/render/integrator.h b/intern/cycles/render/integrator.h index 5bab4470089..52032fa1a26 100644 --- a/intern/cycles/render/integrator.h +++ b/intern/cycles/render/integrator.h @@ -42,6 +42,9 @@ public: bool no_caustics; float blur_caustics; + + int seed; + bool need_update; Integrator(); diff --git a/intern/cycles/util/util_hash.h b/intern/cycles/util/util_hash.h index 0b7164403f2..af7ad7e06a1 100644 --- a/intern/cycles/util/util_hash.h +++ b/intern/cycles/util/util_hash.h @@ -44,6 +44,11 @@ static unsigned int hash_int_2d(unsigned int kx, unsigned int ky) #undef rot } +static unsigned int hash_int(unsigned int k) +{ + return hash_int_2d(k, 0); +} + CCL_NAMESPACE_END #endif /* __UTIL_HASH_H__ */ -- cgit v1.2.3