Blender  V3.3
stdcycles.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Adapted from Open Shading Language
4  * Copyright (c) 2009-2010 Sony Pictures Imageworks Inc., et al.
5  * All Rights Reserved.
6  *
7  * Modifications Copyright 2011-2022 Blender Foundation. */
8 
9 #ifndef CCL_STDCYCLESOSL_H
10 #define CCL_STDCYCLESOSL_H
11 
12 #include "stdosl.h"
13 
14 // Declaration of built-in functions and closures, stdosl.h does not make
15 // these available so we have to redefine them.
16 #define BUILTIN [[int builtin = 1]]
17 #define BUILTIN_DERIV [[ int builtin = 1, int deriv = 1 ]]
18 
19 closure color diffuse_ramp(normal N, color colors[8]) BUILTIN;
20 closure color phong_ramp(normal N, float exponent, color colors[8]) BUILTIN;
21 closure color diffuse_toon(normal N, float size, float smooth) BUILTIN;
22 closure color glossy_toon(normal N, float size, float smooth) BUILTIN;
23 closure color microfacet_ggx(normal N, float ag) BUILTIN;
24 closure color microfacet_ggx_aniso(normal N, vector T, float ax, float ay) BUILTIN;
25 closure color microfacet_ggx_refraction(normal N, float ag, float eta) BUILTIN;
27 closure color microfacet_multi_ggx_aniso(normal N, vector T, float ax, float ay, color C) BUILTIN;
28 closure color microfacet_multi_ggx_glass(normal N, float ag, float eta, color C) BUILTIN;
29 closure color microfacet_ggx_fresnel(normal N, float ag, float eta, color C, color Cspec0) BUILTIN;
31  normal N, vector T, float ax, float ay, float eta, color C, color Cspec0) BUILTIN;
32 closure color
33 microfacet_multi_ggx_fresnel(normal N, float ag, float eta, color C, color Cspec0) BUILTIN;
35  normal N, vector T, float ax, float ay, float eta, color C, color Cspec0) BUILTIN;
36 closure color
39 closure color microfacet_beckmann_aniso(normal N, vector T, float ax, float ay) BUILTIN;
40 closure color microfacet_beckmann_refraction(normal N, float ab, float eta) BUILTIN;
41 closure color ashikhmin_shirley(normal N, vector T, float ax, float ay) BUILTIN;
42 closure color ashikhmin_velvet(normal N, float sigma) BUILTIN;
46 closure color principled_clearcoat(normal N, float clearcoat, float clearcoat_roughness) BUILTIN;
47 
48 // BSSRDF
49 closure color bssrdf(string method, normal N, vector radius, color albedo) BUILTIN;
50 
51 // Hair
52 closure color
53 hair_reflection(normal N, float roughnessu, float roughnessv, vector T, float offset) BUILTIN;
54 closure color
55 hair_transmission(normal N, float roughnessu, float roughnessv, vector T, float offset) BUILTIN;
57  color sigma,
58  float roughnessu,
59  float roughnessv,
60  float coat,
61  float alpha,
62  float eta) BUILTIN;
63 
64 // Volume
67 
69 {
70  /* The implementation here mirrors the one in kernel_montecarlo.h,
71  * check there for an explanation of the algorithm. */
72 
73  float sqr(float x)
74  {
75  return x * x;
76  }
77 
78  vector R = 2 * dot(N, I) * N - I;
79 
80  float threshold = min(0.9 * dot(Ng, I), 0.01);
81  if (dot(Ng, R) >= threshold) {
82  return N;
83  }
84 
85  float NdotNg = dot(N, Ng);
86  vector X = normalize(N - NdotNg * Ng);
87 
88  float Ix = dot(I, X), Iz = dot(I, Ng);
89  float Ix2 = sqr(Ix), Iz2 = sqr(Iz);
90  float a = Ix2 + Iz2;
91 
92  float b = sqrt(Ix2 * (a - sqr(threshold)));
93  float c = Iz * threshold + a;
94 
95  float fac = 0.5 / a;
96  float N1_z2 = fac * (b + c), N2_z2 = fac * (-b + c);
97  int valid1 = (N1_z2 > 1e-5) && (N1_z2 <= (1.0 + 1e-5));
98  int valid2 = (N2_z2 > 1e-5) && (N2_z2 <= (1.0 + 1e-5));
99 
100  float N_new_x, N_new_z;
101  if (valid1 && valid2) {
102  float N1_x = sqrt(1.0 - N1_z2), N1_z = sqrt(N1_z2);
103  float N2_x = sqrt(1.0 - N2_z2), N2_z = sqrt(N2_z2);
104 
105  float R1 = 2 * (N1_x * Ix + N1_z * Iz) * N1_z - Iz;
106  float R2 = 2 * (N2_x * Ix + N2_z * Iz) * N2_z - Iz;
107 
108  valid1 = (R1 >= 1e-5);
109  valid2 = (R2 >= 1e-5);
110  if (valid1 && valid2) {
111  N_new_x = (R1 < R2) ? N1_x : N2_x;
112  N_new_z = (R1 < R2) ? N1_z : N2_z;
113  }
114  else {
115  N_new_x = (R1 > R2) ? N1_x : N2_x;
116  N_new_z = (R1 > R2) ? N1_z : N2_z;
117  }
118  }
119  else if (valid1 || valid2) {
120  float Nz2 = valid1 ? N1_z2 : N2_z2;
121  N_new_x = sqrt(1.0 - Nz2);
122  N_new_z = sqrt(Nz2);
123  }
124  else {
125  return Ng;
126  }
127 
128  return N_new_x * X + N_new_z * Ng;
129 }
130 
131 #endif /* CCL_STDOSL_H */
sqrt(x)+1/max(0
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Sky Generate a procedural sky texture Noise Generate fractal Perlin noise Wave Generate procedural bands or rings with noise Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a or normal between and object coordinate space Combine Create a color from its and value channels Color Retrieve a color or the default fallback if none is specified Separate Split a vector into its X
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert a color
#define C
Definition: RandGen.cpp:25
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
IconTextureDrawCall normal
ccl_gpu_kernel_postfix ccl_global float int int int int float threshold
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
#define N
#define T
#define R
static unsigned c
Definition: RandGen.cpp:83
static unsigned a[3]
Definition: RandGen.cpp:78
T dot(const vec_base< T, Size > &a, const vec_base< T, Size > &b)
vec_base< T, Size > normalize(const vec_base< T, Size > &v)
static const pxr::TfToken clearcoat("clearcoat", pxr::TfToken::Immortal)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
static const pxr::TfToken g("g", pxr::TfToken::Immortal)
static const pxr::TfToken roughness("roughness", pxr::TfToken::Immortal)
#define I
smooth(Type::FLOAT, "mask_weight")
#define min(a, b)
Definition: sort.c:35
closure color microfacet_ggx(normal N, float ag) BUILTIN
closure color principled_diffuse(normal N, float roughness) BUILTIN
closure color microfacet_multi_ggx_glass_fresnel(normal N, float ag, float eta, color C, color Cspec0) BUILTIN
closure color absorption() BUILTIN
closure color microfacet_ggx_aniso_fresnel(normal N, vector T, float ax, float ay, float eta, color C, color Cspec0) BUILTIN
closure color phong_ramp(normal N, float exponent, color colors[8]) BUILTIN
closure color microfacet_multi_ggx_glass(normal N, float ag, float eta, color C) BUILTIN
closure color microfacet_multi_ggx_aniso_fresnel(normal N, vector T, float ax, float ay, float eta, color C, color Cspec0) BUILTIN
closure color microfacet_multi_ggx_fresnel(normal N, float ag, float eta, color C, color Cspec0) BUILTIN
closure color diffuse_toon(normal N, float size, float smooth) BUILTIN
closure color henyey_greenstein(float g) BUILTIN
#define BUILTIN
Definition: stdcycles.h:16
closure color ambient_occlusion() BUILTIN
closure color microfacet_multi_ggx(normal N, float ag, color C) BUILTIN
closure color microfacet_multi_ggx_aniso(normal N, vector T, float ax, float ay, color C) BUILTIN
closure color hair_transmission(normal N, float roughnessu, float roughnessv, vector T, float offset) BUILTIN
closure color ashikhmin_velvet(normal N, float sigma) BUILTIN
closure color diffuse_ramp(normal N, color colors[8]) BUILTIN
closure color bssrdf(string method, normal N, vector radius, color albedo) BUILTIN
closure color microfacet_ggx_refraction(normal N, float ag, float eta) BUILTIN
closure color principled_clearcoat(normal N, float clearcoat, float clearcoat_roughness) BUILTIN
closure color hair_reflection(normal N, float roughnessu, float roughnessv, vector T, float offset) BUILTIN
normal ensure_valid_reflection(normal Ng, vector I, normal N)
Definition: stdcycles.h:68
closure color microfacet_beckmann(normal N, float ab) BUILTIN
closure color microfacet_ggx_aniso(normal N, vector T, float ax, float ay) BUILTIN
closure color principled_hair(normal N, color sigma, float roughnessu, float roughnessv, float coat, float alpha, float eta) BUILTIN
closure color microfacet_ggx_fresnel(normal N, float ag, float eta, color C, color Cspec0) BUILTIN
closure color ashikhmin_shirley(normal N, vector T, float ax, float ay) BUILTIN
closure color microfacet_beckmann_aniso(normal N, vector T, float ax, float ay) BUILTIN
closure color glossy_toon(normal N, float size, float smooth) BUILTIN
closure color microfacet_beckmann_refraction(normal N, float ab, float eta) BUILTIN
closure color principled_sheen(normal N) BUILTIN
ccl_device_inline float sqr(float a)
Definition: util/math.h:746