Blender  V3.3
wavelength.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 #pragma once
10 
12 
13 /* Wavelength to RGB */
14 
17  ccl_private float *stack,
18  uint wavelength,
20 {
21  float lambda_nm = stack_load_float(stack, wavelength);
22  float ii = (lambda_nm - 380.0f) * (1.0f / 5.0f); // scaled 0..80
23  int i = float_to_int(ii);
24  float3 color;
25 
26  if (i < 0 || i >= 80) {
27  color = make_float3(0.0f, 0.0f, 0.0f);
28  }
29  else {
30  ii -= i;
31  ccl_constant float *c = cie_colour_match[i];
32  color = interp(make_float3(c[0], c[1], c[2]), make_float3(c[3], c[4], c[5]), ii);
33  }
34 
35  color = xyz_to_rgb(kg, color);
36  color *= 1.0f / 2.52f; // Empirical scale from lg to make all comps <= 1
37 
38  /* Clamp to zero if values are smaller */
39  color = max(color, make_float3(0.0f, 0.0f, 0.0f));
40 
42 }
43 
unsigned int uint
Definition: BLI_sys_types.h:67
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 ccl_constant
Definition: cuda/compat.h:46
#define ccl_private
Definition: cuda/compat.h:48
#define ccl_device_noinline
Definition: cuda/compat.h:40
#define CCL_NAMESPACE_END
Definition: cuda/compat.h:9
const KernelGlobalsCPU *ccl_restrict KernelGlobals
ccl_global float * color_out
ccl_device_inline void stack_store_float3(ccl_private float *stack, uint a, float3 f)
ccl_device_inline float stack_load_float(ccl_private float *stack, uint a)
ccl_inline_constant float cie_colour_match[][3]
Definition: kernel/tables.h:36
ShaderData
Definition: kernel/types.h:925
ccl_device_inline float2 interp(const float2 &a, const float2 &b, float t)
Definition: math_float2.h:232
#define make_float3(x, y, z)
Definition: metal/compat.h:204
static unsigned c
Definition: RandGen.cpp:83
color xyz_to_rgb(float x, float y, float z)
Definition: node_color.h:63
float max
ccl_device_inline int float_to_int(float f)
Definition: util/math.h:410
CCL_NAMESPACE_BEGIN ccl_device_noinline void svm_node_wavelength(KernelGlobals kg, ccl_private ShaderData *sd, ccl_private float *stack, uint wavelength, uint color_out)
Definition: wavelength.h:15