Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Stockner <lukas.stockner@freenet.de>2018-06-15 12:03:29 +0300
committerBrecht Van Lommel <brechtvanlommel@gmail.com>2018-06-15 23:16:06 +0300
commit799779d432309e518922d23e3a1d1b5baaece71d (patch)
treedf190f684ce9b86f412913bc0dc4b8dd07491e57 /intern/cycles/kernel/svm/svm_ao.h
parent2b9edbc98becb540f1f907b7c31d7971b1603079 (diff)
Cycles: change Ambient Occlusion shader to output colors.
This means the shader can now be used for procedural texturing. New settings on the node are Samples, Inside, Local Only and Distance. Original patch by Lukas with further changes by Brecht. Differential Revision: https://developer.blender.org/D3479
Diffstat (limited to 'intern/cycles/kernel/svm/svm_ao.h')
-rw-r--r--intern/cycles/kernel/svm/svm_ao.h111
1 files changed, 111 insertions, 0 deletions
diff --git a/intern/cycles/kernel/svm/svm_ao.h b/intern/cycles/kernel/svm/svm_ao.h
new file mode 100644
index 00000000000..3f761627e2c
--- /dev/null
+++ b/intern/cycles/kernel/svm/svm_ao.h
@@ -0,0 +1,111 @@
+/*
+* Copyright 2011-2018 Blender Foundation
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+CCL_NAMESPACE_BEGIN
+
+ccl_device_noinline float svm_ao(KernelGlobals *kg,
+ ShaderData *sd,
+ float3 N,
+ ccl_addr_space PathState *state,
+ float max_dist,
+ int num_samples,
+ int flags)
+{
+ if(flags & NODE_AO_GLOBAL_RADIUS) {
+ max_dist = kernel_data.background.ao_distance;
+ }
+
+ /* Early out if no sampling needed. */
+ if(max_dist <= 0.0f || num_samples < 1 || sd->object == OBJECT_NONE) {
+ return 0.0f;
+ }
+
+ if(flags & NODE_AO_INSIDE) {
+ N = -N;
+ }
+
+ float3 T, B;
+ make_orthonormals(N, &T, &B);
+
+ int unoccluded = 0;
+ for(int sample = 0; sample < num_samples; sample++) {
+ float disk_u, disk_v;
+ path_branched_rng_2D(kg, state->rng_hash, state, sample, num_samples,
+ PRNG_BEVEL_U, &disk_u, &disk_v);
+
+ float2 d = concentric_sample_disk(disk_u, disk_v);
+ float3 D = make_float3(d.x, d.y, safe_sqrtf(1.0f - dot(d, d)));
+
+ /* Create ray. */
+ Ray ray;
+ ray.P = ray_offset(sd->P, N);
+ ray.D = D.x*T + D.y*B + D.z*N;
+ ray.t = max_dist;
+ ray.time = sd->time;
+
+ if(flags & NODE_AO_ONLY_LOCAL) {
+ if(!scene_intersect_local(kg,
+ ray,
+ NULL,
+ sd->object,
+ NULL,
+ 0)) {
+ unoccluded++;
+ }
+ }
+ else {
+ Intersection isect;
+ if(!scene_intersect(kg,
+ ray,
+ PATH_RAY_SHADOW_OPAQUE,
+ &isect,
+ NULL,
+ 0.0f, 0.0f)) {
+ unoccluded++;
+ }
+ }
+ }
+
+ return ((float) unoccluded) / num_samples;
+}
+
+ccl_device void svm_node_ao(KernelGlobals *kg,
+ ShaderData *sd,
+ ccl_addr_space PathState *state,
+ float *stack,
+ uint4 node)
+{
+ uint flags, dist_offset, normal_offset, out_ao_offset;
+ decode_node_uchar4(node.y, &flags, &dist_offset, &normal_offset, &out_ao_offset);
+
+ uint color_offset, out_color_offset, samples;
+ decode_node_uchar4(node.z, &color_offset, &out_color_offset, &samples, NULL);
+
+ float dist = stack_load_float_default(stack, dist_offset, node.w);
+ float3 normal = stack_valid(normal_offset)? stack_load_float3(stack, normal_offset): sd->N;
+ float ao = svm_ao(kg, sd, normal, state, dist, samples, flags);
+
+ if (stack_valid(out_ao_offset)) {
+ stack_store_float(stack, out_ao_offset, ao);
+ }
+
+ if (stack_valid(out_color_offset)) {
+ float3 color = stack_load_float3(stack, color_offset);
+ stack_store_float3(stack, out_color_offset, ao * color);
+ }
+}
+
+CCL_NAMESPACE_END