diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2011-09-16 17:14:02 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2011-09-16 17:14:02 +0400 |
commit | 66b1dfae89cc44953bd51c5da962cab437e76972 (patch) | |
tree | e7679b3e554fb4f1bb6f68775c8619bcde0da822 /intern/cycles/kernel | |
parent | 0a5fcf3da3e82fd114095c8c2903d927f15ffc31 (diff) |
Cycles: tweaks to properties and nodes
* Passes renamed to samples
* Camera lens radius renamed to aperature size/blades/rotation
* Glass and fresnel nodes input is now index of refraction
* Glossy and velvet fresnel socket removed
* Mix/add closure node renamed to mix/add shader node
* Blend weight node added for shader mixing weights
There is some version patching code for reading existing files, but it's not
perfect, so shaders may work a bit different.
Diffstat (limited to 'intern/cycles/kernel')
23 files changed, 237 insertions, 135 deletions
diff --git a/intern/cycles/kernel/kernel.cl b/intern/cycles/kernel/kernel.cl index 007a5f6de6a..48bee8eef97 100644 --- a/intern/cycles/kernel/kernel.cl +++ b/intern/cycles/kernel/kernel.cl @@ -37,7 +37,7 @@ __kernel void kernel_ocl_path_trace( int name##_width, #include "kernel_textures.h" - int pass, + int sample, int sx, int sy, int sw, int sh) { KernelGlobals kglobals, *kg = &kglobals; @@ -53,7 +53,7 @@ __kernel void kernel_ocl_path_trace( int y = sy + get_global_id(1); if(x < sx + sw && y < sy + sh) - kernel_path_trace(kg, buffer, rng_state, pass, x, y); + kernel_path_trace(kg, buffer, rng_state, sample, x, y); } __kernel void kernel_ocl_tonemap( @@ -66,7 +66,7 @@ __kernel void kernel_ocl_tonemap( int name##_width, #include "kernel_textures.h" - int pass, int resolution, + int sample, int resolution, int sx, int sy, int sw, int sh) { KernelGlobals kglobals, *kg = &kglobals; @@ -82,7 +82,7 @@ __kernel void kernel_ocl_tonemap( int y = sy + get_global_id(1); if(x < sx + sw && y < sy + sh) - kernel_film_tonemap(kg, rgba, buffer, pass, resolution, x, y); + kernel_film_tonemap(kg, rgba, buffer, sample, resolution, x, y); } /*__kernel void kernel_ocl_displace(__global uint4 *input, __global float3 *offset, int sx) diff --git a/intern/cycles/kernel/kernel.cpp b/intern/cycles/kernel/kernel.cpp index 01682d11f33..7e5fa25c662 100644 --- a/intern/cycles/kernel/kernel.cpp +++ b/intern/cycles/kernel/kernel.cpp @@ -269,16 +269,16 @@ void kernel_tex_copy(KernelGlobals *kg, const char *name, device_ptr mem, size_t /* Path Tracing */ -void kernel_cpu_path_trace(KernelGlobals *kg, float4 *buffer, unsigned int *rng_state, int pass, int x, int y) +void kernel_cpu_path_trace(KernelGlobals *kg, float4 *buffer, unsigned int *rng_state, int sample, int x, int y) { - kernel_path_trace(kg, buffer, rng_state, pass, x, y); + kernel_path_trace(kg, buffer, rng_state, sample, x, y); } /* Tonemapping */ -void kernel_cpu_tonemap(KernelGlobals *kg, uchar4 *rgba, float4 *buffer, int pass, int resolution, int x, int y) +void kernel_cpu_tonemap(KernelGlobals *kg, uchar4 *rgba, float4 *buffer, int sample, int resolution, int x, int y) { - kernel_film_tonemap(kg, rgba, buffer, pass, resolution, x, y); + kernel_film_tonemap(kg, rgba, buffer, sample, resolution, x, y); } /* Displacement */ diff --git a/intern/cycles/kernel/kernel.cu b/intern/cycles/kernel/kernel.cu index 5e5b445ac2c..75415a00b00 100644 --- a/intern/cycles/kernel/kernel.cu +++ b/intern/cycles/kernel/kernel.cu @@ -26,22 +26,22 @@ #include "kernel_path.h" #include "kernel_displace.h" -extern "C" __global__ void kernel_cuda_path_trace(float4 *buffer, uint *rng_state, int pass, int sx, int sy, int sw, int sh) +extern "C" __global__ void kernel_cuda_path_trace(float4 *buffer, uint *rng_state, int sample, int sx, int sy, int sw, int sh) { int x = sx + blockDim.x*blockIdx.x + threadIdx.x; int y = sy + blockDim.y*blockIdx.y + threadIdx.y; if(x < sx + sw && y < sy + sh) - kernel_path_trace(NULL, buffer, rng_state, pass, x, y); + kernel_path_trace(NULL, buffer, rng_state, sample, x, y); } -extern "C" __global__ void kernel_cuda_tonemap(uchar4 *rgba, float4 *buffer, int pass, int resolution, int sx, int sy, int sw, int sh) +extern "C" __global__ void kernel_cuda_tonemap(uchar4 *rgba, float4 *buffer, int sample, int resolution, int sx, int sy, int sw, int sh) { int x = sx + blockDim.x*blockIdx.x + threadIdx.x; int y = sy + blockDim.y*blockIdx.y + threadIdx.y; if(x < sx + sw && y < sy + sh) - kernel_film_tonemap(NULL, rgba, buffer, pass, resolution, x, y); + kernel_film_tonemap(NULL, rgba, buffer, sample, resolution, x, y); } extern "C" __global__ void kernel_cuda_displace(uint4 *input, float3 *offset, int sx) diff --git a/intern/cycles/kernel/kernel.h b/intern/cycles/kernel/kernel.h index 2bab585c6e6..7f60730e8bf 100644 --- a/intern/cycles/kernel/kernel.h +++ b/intern/cycles/kernel/kernel.h @@ -36,8 +36,8 @@ bool kernel_osl_use(KernelGlobals *kg); void kernel_const_copy(KernelGlobals *kg, const char *name, void *host, size_t size); void kernel_tex_copy(KernelGlobals *kg, const char *name, device_ptr mem, size_t width, size_t height); -void kernel_cpu_path_trace(KernelGlobals *kg, float4 *buffer, unsigned int *rng_state, int pass, int x, int y); -void kernel_cpu_tonemap(KernelGlobals *kg, uchar4 *rgba, float4 *buffer, int pass, int resolution, int x, int y); +void kernel_cpu_path_trace(KernelGlobals *kg, float4 *buffer, unsigned int *rng_state, int sample, int x, int y); +void kernel_cpu_tonemap(KernelGlobals *kg, uchar4 *rgba, float4 *buffer, int sample, int resolution, int x, int y); void kernel_cpu_displace(KernelGlobals *kg, uint4 *input, float3 *offset, int i); diff --git a/intern/cycles/kernel/kernel_camera.h b/intern/cycles/kernel/kernel_camera.h index 1f93394e078..c2828c20eee 100644 --- a/intern/cycles/kernel/kernel_camera.h +++ b/intern/cycles/kernel/kernel_camera.h @@ -20,6 +20,21 @@ CCL_NAMESPACE_BEGIN /* Perspective Camera */ +__device float2 camera_sample_aperture(KernelGlobals *kg, float u, float v) +{ + float blades = kernel_data.cam.blades; + + if(blades == 0.0f) { + /* sample disk */ + return concentric_sample_disk(u, v); + } + else { + /* sample polygon */ + float rotation = kernel_data.cam.bladesrotation; + return regular_polygon_sample(blades, rotation, u, v); + } +} + __device void camera_sample_perspective(KernelGlobals *kg, float raster_x, float raster_y, float lens_u, float lens_v, Ray *ray) { /* create ray form raster position */ @@ -30,14 +45,11 @@ __device void camera_sample_perspective(KernelGlobals *kg, float raster_x, float ray->D = Pcamera; /* modify ray for depth of field */ - float lensradius = kernel_data.cam.lensradius; - - if(lensradius > 0.0f) { - /* sample point on lens */ - float2 lensuv; + float aperturesize = kernel_data.cam.aperturesize; - lensuv = concentric_sample_disk(lens_u, lens_v); - lensuv *= lensradius; + if(aperturesize > 0.0f) { + /* sample point on aperture */ + float2 lensuv = camera_sample_aperture(kg, lens_u, lens_v)*aperturesize; /* compute point on plane of focus */ float ft = kernel_data.cam.focaldistance/ray->D.z; diff --git a/intern/cycles/kernel/kernel_film.h b/intern/cycles/kernel/kernel_film.h index f6351a73295..4373701452e 100644 --- a/intern/cycles/kernel/kernel_film.h +++ b/intern/cycles/kernel/kernel_film.h @@ -18,9 +18,9 @@ CCL_NAMESPACE_BEGIN -__device float4 film_map(KernelGlobals *kg, float4 irradiance, int pass) +__device float4 film_map(KernelGlobals *kg, float4 irradiance, int sample) { - float scale = 1.0f/(float)(pass+1); + float scale = 1.0f/(float)(sample+1); float exposure = kernel_data.film.exposure; float4 result = irradiance*scale; @@ -48,13 +48,13 @@ __device uchar4 film_float_to_byte(float4 color) return result; } -__device void kernel_film_tonemap(KernelGlobals *kg, __global uchar4 *rgba, __global float4 *buffer, int pass, int resolution, int x, int y) +__device void kernel_film_tonemap(KernelGlobals *kg, __global uchar4 *rgba, __global float4 *buffer, int sample, int resolution, int x, int y) { int w = kernel_data.cam.width; int index = x + y*w; float4 irradiance = buffer[index]; - float4 float_result = film_map(kg, irradiance, pass); + float4 float_result = film_map(kg, irradiance, sample); uchar4 byte_result = film_float_to_byte(float_result); rgba[index] = byte_result; diff --git a/intern/cycles/kernel/kernel_montecarlo.h b/intern/cycles/kernel/kernel_montecarlo.h index 6f3a3dd3421..5d9afb6418f 100644 --- a/intern/cycles/kernel/kernel_montecarlo.h +++ b/intern/cycles/kernel/kernel_montecarlo.h @@ -172,6 +172,30 @@ __device float2 concentric_sample_disk(float u1, float u2) return make_float2(r * cosf(theta), r * sinf(theta)); } +__device float2 regular_polygon_sample(float corners, float rotation, float u, float v) +{ + /* sample corner number and reuse u */ + float corner = floorf(u*corners); + u = u*corners - corner; + + /* uniform sampled triangle weights */ + u = sqrtf(u); + v = v*u; + u = 1.0f - u; + + /* point in triangle */ + float angle = M_PI_F/corners; + float2 p = make_float2((u + v)*cosf(angle), (u - v)*sinf(angle)); + + /* rotate */ + rotation += corner*2.0f*angle; + + float cr = cosf(rotation); + float sr = sinf(rotation); + + return make_float2(cr*p.x - sr*p.y, sr*p.x + cr*p.y); +} + /* Spherical coordinates <-> Cartesion direction */ __device float2 direction_to_spherical(float3 dir) diff --git a/intern/cycles/kernel/kernel_path.h b/intern/cycles/kernel/kernel_path.h index 815eb4a1d53..d6977c24c53 100644 --- a/intern/cycles/kernel/kernel_path.h +++ b/intern/cycles/kernel/kernel_path.h @@ -34,22 +34,22 @@ CCL_NAMESPACE_BEGIN #ifdef __MODIFY_TP__ -__device float3 path_terminate_modified_throughput(KernelGlobals *kg, __global float3 *buffer, int x, int y, int pass) +__device float3 path_terminate_modified_throughput(KernelGlobals *kg, __global float3 *buffer, int x, int y, int sample) { /* modify throughput to influence path termination probability, to avoid darker regions receiving fewer samples than lighter regions. also RGB are weighted differently. proper validation still remains to be done. */ const float3 weights = make_float3(1.0f, 1.33f, 0.66f); const float3 one = make_float3(1.0f, 1.0f, 1.0f); - const int minpass = 5; + const int minsample = 5; const float minL = 0.1f; - if(pass >= minpass) { + if(sample >= minsample) { float3 L = buffer[x + y*kernel_data.cam.width]; float3 Lmin = make_float3(minL, minL, minL); - float correct = (float)(pass+1)/(float)pass; + float correct = (float)(sample+1)/(float)sample; - L = film_map(L*correct, pass); + L = film_map(L*correct, sample); return weights/clamp(L, Lmin, one); } @@ -242,7 +242,7 @@ __device_inline bool shadow_blocked(KernelGlobals *kg, PathState *state, Ray *ra return result; } -__device float4 kernel_path_integrate(KernelGlobals *kg, RNG *rng, int pass, Ray ray, float3 throughput) +__device float4 kernel_path_integrate(KernelGlobals *kg, RNG *rng, int sample, Ray ray, float3 throughput) { /* initialize */ float3 L = make_float3(0.0f, 0.0f, 0.0f); @@ -284,7 +284,7 @@ __device float4 kernel_path_integrate(KernelGlobals *kg, RNG *rng, int pass, Ray /* setup shading */ ShaderData sd; shader_setup_from_ray(kg, &sd, &isect, &ray); - float rbsdf = path_rng(kg, rng, pass, rng_offset + PRNG_BSDF); + float rbsdf = path_rng(kg, rng, sample, rng_offset + PRNG_BSDF); shader_eval_surface(kg, &sd, rbsdf, state.flag); #ifdef __HOLDOUT__ @@ -308,7 +308,7 @@ __device float4 kernel_path_integrate(KernelGlobals *kg, RNG *rng, int pass, Ray mainly due to the mixed in MIS that we use. gives too many unneeded shader evaluations, only need emission if we are going to terminate */ float probability = path_state_terminate_probability(kg, &state, throughput); - float terminate = path_rng(kg, rng, pass, rng_offset + PRNG_TERMINATE); + float terminate = path_rng(kg, rng, sample, rng_offset + PRNG_TERMINATE); if(terminate >= probability) break; @@ -319,10 +319,10 @@ __device float4 kernel_path_integrate(KernelGlobals *kg, RNG *rng, int pass, Ray if(kernel_data.integrator.use_emission) { /* sample illumination from lights to find path contribution */ if(sd.flag & SD_BSDF_HAS_EVAL) { - float light_t = path_rng(kg, rng, pass, rng_offset + PRNG_LIGHT); - float light_o = path_rng(kg, rng, pass, rng_offset + PRNG_LIGHT_F); - float light_u = path_rng(kg, rng, pass, rng_offset + PRNG_LIGHT_U); - float light_v = path_rng(kg, rng, pass, rng_offset + PRNG_LIGHT_V); + float light_t = path_rng(kg, rng, sample, rng_offset + PRNG_LIGHT); + float light_o = path_rng(kg, rng, sample, rng_offset + PRNG_LIGHT_F); + float light_u = path_rng(kg, rng, sample, rng_offset + PRNG_LIGHT_U); + float light_v = path_rng(kg, rng, sample, rng_offset + PRNG_LIGHT_V); Ray light_ray; float3 light_L; @@ -356,8 +356,8 @@ __device float4 kernel_path_integrate(KernelGlobals *kg, RNG *rng, int pass, Ray float3 bsdf_eval; float3 bsdf_omega_in; differential3 bsdf_domega_in; - float bsdf_u = path_rng(kg, rng, pass, rng_offset + PRNG_BSDF_U); - float bsdf_v = path_rng(kg, rng, pass, rng_offset + PRNG_BSDF_V); + float bsdf_u = path_rng(kg, rng, sample, rng_offset + PRNG_BSDF_U); + float bsdf_v = path_rng(kg, rng, sample, rng_offset + PRNG_BSDF_V); int label; label = shader_bsdf_sample(kg, &sd, bsdf_u, bsdf_v, &bsdf_eval, @@ -392,7 +392,7 @@ __device float4 kernel_path_integrate(KernelGlobals *kg, RNG *rng, int pass, Ray return make_float4(L.x, L.y, L.z, 1.0f - Ltransparent); } -__device void kernel_path_trace(KernelGlobals *kg, __global float4 *buffer, __global uint *rng_state, int pass, int x, int y) +__device void kernel_path_trace(KernelGlobals *kg, __global float4 *buffer, __global uint *rng_state, int sample, int x, int y) { /* initialize random numbers */ RNG rng; @@ -400,29 +400,29 @@ __device void kernel_path_trace(KernelGlobals *kg, __global float4 *buffer, __gl float filter_u; float filter_v; - path_rng_init(kg, rng_state, pass, &rng, x, y, &filter_u, &filter_v); + path_rng_init(kg, rng_state, sample, &rng, x, y, &filter_u, &filter_v); /* sample camera ray */ Ray ray; - float lens_u = path_rng(kg, &rng, pass, PRNG_LENS_U); - float lens_v = path_rng(kg, &rng, pass, PRNG_LENS_V); + float lens_u = path_rng(kg, &rng, sample, PRNG_LENS_U); + float lens_v = path_rng(kg, &rng, sample, PRNG_LENS_V); camera_sample(kg, x, y, filter_u, filter_v, lens_u, lens_v, &ray); /* integrate */ #ifdef __MODIFY_TP__ - float3 throughput = path_terminate_modified_throughput(kg, buffer, x, y, pass); - float4 L = kernel_path_integrate(kg, &rng, pass, ray, throughput)/throughput; + float3 throughput = path_terminate_modified_throughput(kg, buffer, x, y, sample); + float4 L = kernel_path_integrate(kg, &rng, sample, ray, throughput)/throughput; #else float3 throughput = make_float3(1.0f, 1.0f, 1.0f); - float4 L = kernel_path_integrate(kg, &rng, pass, ray, throughput); + float4 L = kernel_path_integrate(kg, &rng, sample, ray, throughput); #endif /* accumulate result in output buffer */ int index = x + y*kernel_data.cam.width; - if(pass == 0) + if(sample == 0) buffer[index] = L; else buffer[index] += L; diff --git a/intern/cycles/kernel/kernel_random.h b/intern/cycles/kernel/kernel_random.h index 6c2daafb061..13cf4df8b8c 100644 --- a/intern/cycles/kernel/kernel_random.h +++ b/intern/cycles/kernel/kernel_random.h @@ -95,7 +95,7 @@ __device uint sobol_lookup(const uint m, const uint frame, const uint ex, const return index; } -__device_inline float path_rng(KernelGlobals *kg, RNG *rng, int pass, int dimension) +__device_inline float path_rng(KernelGlobals *kg, RNG *rng, int sample, int dimension) { #ifdef __SOBOL_FULL_SCREEN__ uint result = sobol_dimension(kg, *rng, dimension); @@ -103,7 +103,7 @@ __device_inline float path_rng(KernelGlobals *kg, RNG *rng, int pass, int dimens return r; #else /* compute sobol sequence value using direction vectors */ - uint result = sobol_dimension(kg, pass, dimension); + uint result = sobol_dimension(kg, sample, dimension); float r = (float)result * (1.0f/(float)0xFFFFFFFF); /* Cranly-Patterson rotation using rng seed */ @@ -118,13 +118,13 @@ __device_inline float path_rng(KernelGlobals *kg, RNG *rng, int pass, int dimens #endif } -__device_inline void path_rng_init(KernelGlobals *kg, __global uint *rng_state, int pass, RNG *rng, int x, int y, float *fx, float *fy) +__device_inline void path_rng_init(KernelGlobals *kg, __global uint *rng_state, int sample, RNG *rng, int x, int y, float *fx, float *fy) { #ifdef __SOBOL_FULL_SCREEN__ uint px, py; uint bits = 16; /* limits us to 65536x65536 and 65536 samples */ uint size = 1 << bits; - uint frame = pass; + uint frame = sample; *rng = sobol_lookup(bits, frame, x, y, &px, &py); @@ -133,8 +133,8 @@ __device_inline void path_rng_init(KernelGlobals *kg, __global uint *rng_state, #else *rng = rng_state[x + y*kernel_data.cam.width]; - *fx = path_rng(kg, rng, pass, PRNG_FILTER_U); - *fy = path_rng(kg, rng, pass, PRNG_FILTER_V); + *fx = path_rng(kg, rng, sample, PRNG_FILTER_U); + *fy = path_rng(kg, rng, sample, PRNG_FILTER_V); #endif } @@ -147,25 +147,25 @@ __device void path_rng_end(KernelGlobals *kg, __global uint *rng_state, RNG rng, /* Linear Congruential Generator */ -__device float path_rng(KernelGlobals *kg, RNG *rng, int pass, int dimension) +__device float path_rng(KernelGlobals *kg, RNG *rng, int sample, int dimension) { /* implicit mod 2^32 */ *rng = (1103515245*(*rng) + 12345); return (float)*rng * (1.0f/(float)0xFFFFFFFF); } -__device void path_rng_init(KernelGlobals *kg, __global uint *rng_state, int pass, RNG *rng, int x, int y, float *fx, float *fy) +__device void path_rng_init(KernelGlobals *kg, __global uint *rng_state, int sample, RNG *rng, int x, int y, float *fx, float *fy) { /* load state */ *rng = rng_state[x + y*kernel_data.cam.width]; - *fx = path_rng(kg, rng, pass, PRNG_FILTER_U); - *fy = path_rng(kg, rng, pass, PRNG_FILTER_V); + *fx = path_rng(kg, rng, sample, PRNG_FILTER_U); + *fy = path_rng(kg, rng, sample, PRNG_FILTER_V); } __device void path_rng_end(KernelGlobals *kg, __global uint *rng_state, RNG rng, int x, int y) { - /* store state for next pass */ + /* store state for next sample */ rng_state[x + y*kernel_data.cam.width] = rng; } diff --git a/intern/cycles/kernel/kernel_types.h b/intern/cycles/kernel/kernel_types.h index d3012324739..8083da971ed 100644 --- a/intern/cycles/kernel/kernel_types.h +++ b/intern/cycles/kernel/kernel_types.h @@ -288,14 +288,6 @@ typedef struct KernelCamera { Transform cameratoworld; Transform rastertocamera; - /* depth of field */ - float lensradius; - float focaldistance; - - /* motion blur */ - float shutteropen; - float shutterclose; - /* differentials */ float3 dx; #ifndef WITH_OPENCL @@ -306,10 +298,19 @@ typedef struct KernelCamera { float pad2; #endif + /* depth of field */ + float aperturesize; + float blades; + float bladesrotation; + float focaldistance; + + /* motion blur */ + float shutteropen; + float shutterclose; + /* clipping */ float nearclip; float cliplength; - float pad3, pad4; /* more matrices */ Transform screentoworld; diff --git a/intern/cycles/kernel/osl/nodes/CMakeLists.txt b/intern/cycles/kernel/osl/nodes/CMakeLists.txt index 365cc42ad6b..7d37bb09d71 100644 --- a/intern/cycles/kernel/osl/nodes/CMakeLists.txt +++ b/intern/cycles/kernel/osl/nodes/CMakeLists.txt @@ -30,6 +30,7 @@ set(osl_sources node_mix.osl node_mix_closure.osl node_musgrave_texture.osl + node_blend_weight_texture.osl node_noise_texture.osl node_output_displacement.osl node_output_surface.osl diff --git a/intern/cycles/kernel/osl/nodes/node_blend_weight.osl b/intern/cycles/kernel/osl/nodes/node_blend_weight.osl new file mode 100644 index 00000000000..d834819ef3a --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_blend_weight.osl @@ -0,0 +1,42 @@ +/* + * Copyright 2011, Blender Foundation. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "stdosl.h" +#include "node_fresnel.h" + +shader node_blend_weight( + float Blend = 0.3, + normal Normal = N, + output float Fresnel = 0.0, + output float Facing = 0.0) +{ + float f = max(1.0 - Blend, 1e-5); + Fresnel = fresnel_dielectric(I, Normal, backfacing()? f: 1.0/f); + + Facing = abs(dot(I, Normal)); + + if(Blend != 0.5) { + Blend = clamp(Blend, 0.0, 1.0); + Blend = (Blend < 0.5)? 2.0*Blend: 0.5/(1.0 - Blend); + + Facing = powf(Facing, Blend); + } + + Facing = 1.0 - Facing; +} + diff --git a/intern/cycles/kernel/osl/nodes/node_environment_texture.osl b/intern/cycles/kernel/osl/nodes/node_environment_texture.osl index 267db7bad2d..3ad806781eb 100644 --- a/intern/cycles/kernel/osl/nodes/node_environment_texture.osl +++ b/intern/cycles/kernel/osl/nodes/node_environment_texture.osl @@ -23,9 +23,10 @@ shader node_environment_texture( vector Vector = P, string filename = "", string color_space = "sRGB", - output color Color = color(0.0, 0.0, 0.0)) + output color Color = color(0.0, 0.0, 0.0), + output float Alpha = 1.0) { - Color = (color)environment(filename, Vector); + Color = (color)environment(filename, Vector, "alpha", Alpha); if(color_space == "sRGB") Color = color_srgb_to_scene_linear(Color); diff --git a/intern/cycles/kernel/osl/nodes/node_fresnel.osl b/intern/cycles/kernel/osl/nodes/node_fresnel.osl index ddc86db130f..3af4448b43f 100644 --- a/intern/cycles/kernel/osl/nodes/node_fresnel.osl +++ b/intern/cycles/kernel/osl/nodes/node_fresnel.osl @@ -20,11 +20,12 @@ #include "node_fresnel.h" shader node_fresnel( - float Fresnel = 0.3, + float IOR = 1.45, normal Normal = N, output float Fac = 0.0) { - float f = max(1.0 - Fresnel, 0.00001); - Fac = fresnel_dielectric(I, Normal, backfacing()? f: 1.0/f); + float f = max(IOR, 1.0 + 1e-5); + float eta = backfacing()? 1.0/f: f; + Fac = fresnel_dielectric(I, Normal, eta); } diff --git a/intern/cycles/kernel/osl/nodes/node_glass_bsdf.osl b/intern/cycles/kernel/osl/nodes/node_glass_bsdf.osl index af946048011..cc2104af56f 100644 --- a/intern/cycles/kernel/osl/nodes/node_glass_bsdf.osl +++ b/intern/cycles/kernel/osl/nodes/node_glass_bsdf.osl @@ -23,12 +23,12 @@ shader node_glass_bsdf( color Color = color(0.8, 0.8, 0.8), string distribution = "Sharp", float Roughness = 0.2, - float Fresnel = 0.3, + float IOR = 1.45, normal Normal = N, output closure color BSDF = diffuse(Normal)) { - float f = clamp(1.0 - Fresnel, 1e-5, 1.0 - 1e-5); - float eta = backfacing()? f: 1.0/f; + float f = max(IOR, 1.0 + 1e-5); + float eta = backfacing()? 1.0/f: f; float Fr = fresnel_dielectric(I, Normal, eta); if(distribution == "Sharp") diff --git a/intern/cycles/kernel/osl/nodes/node_glossy_bsdf.osl b/intern/cycles/kernel/osl/nodes/node_glossy_bsdf.osl index ca6bee74b38..aa446b66cfb 100644 --- a/intern/cycles/kernel/osl/nodes/node_glossy_bsdf.osl +++ b/intern/cycles/kernel/osl/nodes/node_glossy_bsdf.osl @@ -23,23 +23,15 @@ shader node_glossy_bsdf( color Color = color(0.8, 0.8, 0.8), string distribution = "Beckmann", float Roughness = 0.2, - float Fresnel = 1.0, normal Normal = N, output closure color BSDF = diffuse(Normal)) { - float Fr = 1.0; - - if(Fresnel < 1.0) { - float eta = 1.0/clamp(1.0 - Fresnel, 1e-5, 1.0 - 1e-5); - Fr = fresnel_dielectric(I, Normal, eta); - } - if(distribution == "Sharp") - BSDF = (Fr*Color)*reflection(Normal); + BSDF = Color*reflection(Normal); else if(distribution == "Beckmann") - BSDF = (Fr*Color)*microfacet_beckmann(Normal, Roughness); + BSDF = Color*microfacet_beckmann(Normal, Roughness); else if(distribution == "GGX") - BSDF = (Fr*Color)*microfacet_ggx(Normal, Roughness); + BSDF = Color*microfacet_ggx(Normal, Roughness); } diff --git a/intern/cycles/kernel/osl/nodes/node_image_texture.osl b/intern/cycles/kernel/osl/nodes/node_image_texture.osl index 85025db7c74..38126401d76 100644 --- a/intern/cycles/kernel/osl/nodes/node_image_texture.osl +++ b/intern/cycles/kernel/osl/nodes/node_image_texture.osl @@ -23,9 +23,10 @@ shader node_image_texture( point Vector = P, string filename = "", string color_space = "sRGB", - output color Color = color(0.0, 0.0, 0.0)) + output color Color = color(0.0, 0.0, 0.0), + output float Alpha = 1.0) { - Color = (color)texture(filename, Vector[0], 1.0-Vector[1], "wrap", "periodic"); + Color = (color)texture(filename, Vector[0], 1.0-Vector[1], "wrap", "periodic", "alpha", Alpha); if(color_space == "sRGB") Color = color_srgb_to_scene_linear(Color); diff --git a/intern/cycles/kernel/osl/nodes/node_velvet_bsdf.osl b/intern/cycles/kernel/osl/nodes/node_velvet_bsdf.osl index 2b6219f6325..7a336c148db 100644 --- a/intern/cycles/kernel/osl/nodes/node_velvet_bsdf.osl +++ b/intern/cycles/kernel/osl/nodes/node_velvet_bsdf.osl @@ -22,19 +22,11 @@ shader node_velvet_bsdf( color Color = color(0.8, 0.8, 0.8), float Sigma = 0.0, - float Fresnel = 0.3, normal Normal = N, output closure color BSDF = diffuse(Normal)) { - float Fr = 1.0; - - if(Fresnel < 1.0) { - float eta = 1.0/clamp(1.0 - Fresnel, 1e-5, 1.0 - 1e-5); - Fr = fresnel_dielectric(I, Normal, eta); - } - float sigma = clamp(Sigma, 0.0, 1.0); - BSDF = (Fr*Color)*ashikhmin_velvet(Normal, sigma); + BSDF = Color*ashikhmin_velvet(Normal, sigma); } diff --git a/intern/cycles/kernel/svm/svm.h b/intern/cycles/kernel/svm/svm.h index a5d95c1b394..65d92a91df9 100644 --- a/intern/cycles/kernel/svm/svm.h +++ b/intern/cycles/kernel/svm/svm.h @@ -282,6 +282,9 @@ __device_noinline void svm_eval_nodes(KernelGlobals *kg, ShaderData *sd, ShaderT case NODE_FRESNEL: svm_node_fresnel(sd, stack, node.y, node.z, node.w); break; + case NODE_BLEND_WEIGHT: + svm_node_blend_weight(sd, stack, node); + break; case NODE_SET_DISPLACEMENT: svm_node_set_displacement(sd, stack, node.y); break; diff --git a/intern/cycles/kernel/svm/svm_closure.h b/intern/cycles/kernel/svm/svm_closure.h index aaf2926f60d..68f91408f1f 100644 --- a/intern/cycles/kernel/svm/svm_closure.h +++ b/intern/cycles/kernel/svm/svm_closure.h @@ -102,23 +102,19 @@ __device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *st if(kernel_data.integrator.no_caustics && (path_flag & PATH_RAY_DIFFUSE)) break; #endif - ShaderClosure *sc = svm_node_closure_get(sd); svm_node_closure_set_mix_weight(sc, mix_weight); - /* index of refraction */ - float eta = clamp(1.0f-param2, 1e-5f, 1.0f - 1e-5f); - eta = 1.0f/eta; - - /* fresnel */ - float cosNO = dot(sd->N, sd->I); - float fresnel = fresnel_dielectric_cos(cosNO, eta); float roughness = param1; - sc->weight *= fresnel; - /* setup bsdf */ - svm_node_glossy_setup(sd, sc, type, eta, roughness, false); + if(type == CLOSURE_BSDF_REFLECTION_ID) + bsdf_reflection_setup(sd, sc); + else if(type == CLOSURE_BSDF_MICROFACET_BECKMANN_ID) + bsdf_microfacet_beckmann_setup(sd, sc, roughness, 1.0f, false); + else + bsdf_microfacet_ggx_setup(sd, sc, roughness, 1.0f, false); + break; } case CLOSURE_BSDF_REFRACTION_ID: @@ -128,10 +124,9 @@ __device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *st if(kernel_data.integrator.no_caustics && (path_flag & PATH_RAY_DIFFUSE)) break; #endif - /* index of refraction */ - float eta = clamp(1.0f-param2, 1e-5f, 1.0f - 1e-5f); - eta = (sd->flag & SD_BACKFACING)? eta: 1.0f/eta; + float eta = fmaxf(param2, 1.0f + 1e-5f); + eta = (sd->flag & SD_BACKFACING)? 1.0f/eta: eta; /* fresnel */ float cosNO = dot(sd->N, sd->I); @@ -173,7 +168,6 @@ __device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *st if(kernel_data.integrator.no_caustics && (path_flag & PATH_RAY_DIFFUSE)) break; #endif - ShaderClosure *sc = svm_node_closure_get(sd); svm_node_closure_set_mix_weight(sc, mix_weight); @@ -190,17 +184,6 @@ __device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *st /* sigma */ float sigma = clamp(param1, 0.0f, 1.0f); - - /* index of refraction */ - float eta = clamp(1.0f-param2, 1e-5f, 1.0f - 1e-5f); - eta = 1.0f/eta; - - /* fresnel */ - float cosNO = dot(sd->N, sd->I); - float fresnel = fresnel_dielectric_cos(cosNO, eta); - - sc->weight *= fresnel; - bsdf_ashikhmin_velvet_setup(sd, sc, sigma); break; } @@ -308,7 +291,8 @@ __device void svm_node_emission_weight(KernelGlobals *kg, ShaderData *sd, float uint strength_offset = node.z; uint total_power = node.w; - float3 weight = stack_load_float3(stack, color_offset)*stack_load_float(stack, strength_offset); + float strength = stack_load_float(stack, strength_offset); + float3 weight = stack_load_float3(stack, color_offset)*strength; if(total_power && sd->object != ~0) weight /= object_surface_area(kg, sd->object); diff --git a/intern/cycles/kernel/svm/svm_fresnel.h b/intern/cycles/kernel/svm/svm_fresnel.h index f6122fa3071..1b9d99506e3 100644 --- a/intern/cycles/kernel/svm/svm_fresnel.h +++ b/intern/cycles/kernel/svm/svm_fresnel.h @@ -20,12 +20,48 @@ CCL_NAMESPACE_BEGIN /* Fresnel Node */ -__device void svm_node_fresnel(ShaderData *sd, float *stack, uint fresnel_offset, uint fresnel_value, uint out_offset) +__device void svm_node_fresnel(ShaderData *sd, float *stack, uint ior_offset, uint ior_value, uint out_offset) { - float fresnel = (stack_valid(fresnel_offset))? stack_load_float(stack, fresnel_offset): __int_as_float(fresnel_value); - fresnel = fmaxf(1.0f - fresnel, 0.00001f); + float eta = (stack_valid(ior_offset))? stack_load_float(stack, ior_offset): __int_as_float(ior_value); + eta = fmaxf(eta, 1.0f + 1e-5f); + eta = (sd->flag & SD_BACKFACING)? 1.0f/eta: eta; - float f = fresnel_dielectric_cos(dot(sd->I, sd->N), (sd->flag & SD_BACKFACING)? fresnel: 1.0f/fresnel); + float f = fresnel_dielectric_cos(dot(sd->I, sd->N), eta); + + stack_store_float(stack, out_offset, f); +} + +/* Blend Weight Node */ + +__device void svm_node_blend_weight(ShaderData *sd, float *stack, uint4 node) +{ + uint blend_offset = node.y; + uint blend_value = node.z; + float blend = (stack_valid(blend_offset))? stack_load_float(stack, blend_offset): __int_as_float(blend_value); + + uint type, out_offset; + decode_node_uchar4(node.w, &type, &out_offset, NULL, NULL); + + float f; + + if(type == NODE_BLEND_WEIGHT_FRESNEL) { + float eta = fmaxf(1.0f - blend, 1e-5f); + eta = (sd->flag & SD_BACKFACING)? eta: 1.0f/eta; + + f = fresnel_dielectric_cos(dot(sd->I, sd->N), eta); + } + else { + f = fabsf(dot(sd->I, sd->N)); + + if(blend != 0.5f) { + blend = clamp(blend, 0.0f, 1.0f); + blend = (blend < 0.5f)? 2.0f*blend: 0.5f/(1.0f - blend); + + f = powf(f, blend); + } + + f = 1.0f - f; + } stack_store_float(stack, out_offset, f); } diff --git a/intern/cycles/kernel/svm/svm_image.h b/intern/cycles/kernel/svm/svm_image.h index 586e35c6465..62e24166970 100644 --- a/intern/cycles/kernel/svm/svm_image.h +++ b/intern/cycles/kernel/svm/svm_image.h @@ -147,9 +147,9 @@ __device float4 svm_image_texture(KernelGlobals *kg, int id, float x, float y) __device void svm_node_tex_image(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node) { uint id = node.y; - uint co_offset, out_offset, srgb; + uint co_offset, out_offset, alpha_offset, srgb; - decode_node_uchar4(node.z, &co_offset, &out_offset, &srgb, NULL); + decode_node_uchar4(node.z, &co_offset, &out_offset, &alpha_offset, &srgb); float3 co = stack_load_float3(stack, co_offset); float4 f = svm_image_texture(kg, id, co.x, co.y); @@ -161,15 +161,18 @@ __device void svm_node_tex_image(KernelGlobals *kg, ShaderData *sd, float *stack r.z = color_srgb_to_scene_linear(r.z); } - stack_store_float3(stack, out_offset, r); + if(stack_valid(out_offset)) + stack_store_float3(stack, out_offset, r); + if(stack_valid(alpha_offset)) + stack_store_float(stack, alpha_offset, f.w); } __device void svm_node_tex_environment(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node) { uint id = node.y; - uint co_offset, out_offset, srgb; + uint co_offset, out_offset, alpha_offset, srgb; - decode_node_uchar4(node.z, &co_offset, &out_offset, &srgb, NULL); + decode_node_uchar4(node.z, &co_offset, &out_offset, &alpha_offset, &srgb); float3 co = stack_load_float3(stack, co_offset); float u = (atan2f(co.y, co.x) + M_PI_F)/(2*M_PI_F); @@ -183,7 +186,10 @@ __device void svm_node_tex_environment(KernelGlobals *kg, ShaderData *sd, float r.z = color_srgb_to_scene_linear(r.z); } - stack_store_float3(stack, out_offset, r); + if(stack_valid(out_offset)) + stack_store_float3(stack, out_offset, r); + if(stack_valid(alpha_offset)) + stack_store_float(stack, alpha_offset, f.w); } CCL_NAMESPACE_END diff --git a/intern/cycles/kernel/svm/svm_types.h b/intern/cycles/kernel/svm/svm_types.h index 98e4a5ee583..483f3c76f3c 100644 --- a/intern/cycles/kernel/svm/svm_types.h +++ b/intern/cycles/kernel/svm/svm_types.h @@ -82,7 +82,8 @@ typedef enum NodeType { NODE_ATTR_BUMP_DX = 4400, NODE_ATTR_BUMP_DY = 4500, NODE_TEX_ENVIRONMENT = 4600, - NODE_CLOSURE_HOLDOUT = 4700 + NODE_CLOSURE_HOLDOUT = 4700, + NODE_BLEND_WEIGHT = 4800 } NodeType; typedef enum NodeAttributeType { @@ -249,6 +250,11 @@ typedef enum NodeVoronoiColoring { NODE_VORONOI_POSITION_OUTLINE_INTENSITY } NodeVoronoiColoring; +typedef enum NodeBlendWeightType { + NODE_BLEND_WEIGHT_FRESNEL, + NODE_BLEND_WEIGHT_FACING +} NodeBlendWeightType; + typedef enum ShaderType { SHADER_TYPE_SURFACE, SHADER_TYPE_VOLUME, |