@volter/blender-engine 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser/runtime.ts +5 -0
- package/browser/session.py +505 -2
- package/browser/three/blender-frame-columns.ts +4 -0
- package/browser/three/blender-graph-material.ts +402 -0
- package/browser/three/blender-node-glsl.generated.ts +401 -0
- package/browser/three/blender-node-graph.ts +1026 -0
- package/browser/three/blender-physical-material.ts +32 -2
- package/browser/three/blender-presenter-change.ts +24 -0
- package/browser/three/blender-runtime-geometry.ts +86 -6
- package/browser/three/blender-runtime-lighting.ts +3 -0
- package/browser/three/blender-runtime-view.ts +173 -5
- package/browser/three/blender-texture-samplers.ts +2 -0
- package/package.json +1 -1
- package/wasm/BUNDLE.json +11 -31
- package/wasm/blender_browser.wasm.br +0 -0
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
/* GENERATED by scripts/generate-node-glsl.mjs from Blender 68bba09924c2cf08cbceb6608be4a9e1500a62bb — do not edit.
|
|
2
|
+
* SPDX-FileCopyrightText: Blender Authors
|
|
3
|
+
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
4
|
+
export const BLENDER_NODE_GLSL_COMMIT = "68bba09924c2cf08cbceb6608be4a9e1500a62bb";
|
|
5
|
+
export const BLENDER_NODE_GLSL_PRELUDE = "#define constexpr const\n#define bool32_t bool\n#define bool2 bvec2\n#define bool3 bvec3\n#define bool4 bvec4\n#define float2 vec2\n#define float3 vec3\n#define float4 vec4\n#define int2 ivec2\n#define int3 ivec3\n#define int4 ivec4\n#define uint2 uvec2\n#define uint3 uvec3\n#define uint4 uvec4\n#define packed_float2 float2\n#define packed_int2 int2\n#define packed_uint2 uint2\n#define packed_float3 float3\n#define packed_int3 int3\n#define packed_uint3 uint3\n#define packed_float4 float4\n#define packed_int4 int4\n#define packed_uint4 uint4\n#define float2x2 mat2x2\n#define float3x2 mat3x2\n#define float4x2 mat4x2\n#define float2x3 mat2x3\n#define float3x3 mat3x3\n#define float4x3 mat4x3\n#define float2x4 mat2x4\n#define float3x4 mat3x4\n#define float4x4 mat4x4\n#define char int\n#define char2 int2\n#define char3 int3\n#define char4 int4\n#define short int\n#define short2 int2\n#define short3 int3\n#define short4 int4\n#define uchar uint\n#define uchar2 uint2\n#define uchar3 uint3\n#define uchar4 uint4\n#define ushort uint\n#define ushort2 uint2\n#define ushort3 uint3\n#define ushort4 uint4\n#define half float\n#define half2 float2\n#define half3 float3\n#define half4 float4\n#define int32_t int\n#define uint32_t uint\n#define imageStoreFast imageStore\n#define imageLoadFast imageLoad\n#define sampler2DDepth sampler2D\n#define sampler2DArrayDepth sampler2DArray\n#define samplerCubeDepth sampler2D\n#define samplerCubeArrayDepth sampler2DArray\n#define usampler2DArrayAtomic usampler2DArray\n#define usampler2DAtomic usampler2D\n#define usampler3DAtomic usampler3D\n#define isampler2DArrayAtomic isampler2DArray\n#define isampler2DAtomic isampler2D\n#define isampler3DAtomic isampler3D\n#define imageFence(image)\n#define select(A, B, mask) mix(A, B, mask)\n#define float_array float[]\n#define float2_array vec2[]\n#define float3_array vec3[]\n#define float4_array vec4[]\n#define int_array int[]\n#define int2_array int2[]\n#define int3_array int3[]\n#define int4_array int4[]\n#define uint_array uint[]\n#define uint2_array uint2[]\n#define uint3_array uint3[]\n#define uint4_array uint4[]\n#define bool_array bool[]\n#define bool2_array bool2[]\n#define bool3_array bool3[]\n#define bool4_array bool4[]\n#define ARRAY_T(type) type[]\n#define ARRAY_V\n#define SHADER_LIBRARY_CREATE_INFO(a)\n#define VERTEX_SHADER_CREATE_INFO(a)\n#define FRAGMENT_SHADER_CREATE_INFO(a)\n#define COMPUTE_SHADER_CREATE_INFO(a)\n#define ATTR_FALLTHROUGH\n#define _in_sta\n#define _in_end\n#define _out_sta\n#define _out_end\n#define _inout_sta\n#define _inout_end\n#define _shared_sta\n#define _shared_end\n#define _ref(_type, _var) inout _type _var\n#define _ctor(_type) _type(\n#define _rotc() )\n#define specialization_constant_get(create_info, _res) _res\n#define shared_variable_get(create_info, _res) _res\n#define push_constant_get(create_info, _res) _res\n#define interface_get(create_info, _res) _res\n#define attribute_get(create_info, _res) _res\n#define buffer_get(create_info, _res) _res\n#define sampler_get(create_info, _res) _res\n#define image_get(create_info, _res) _res\n#define srt_access(create_info, _res) access_##create_info##_##_res()\n#define resource_table_get(table_type) table_type##_ctor_()\n#define static\n#define constant\n#define device\n#define thread\n#define threadgroup\n#define textureGather0(_tex, _co) textureGather(_tex, _co, 0)\n#define textureGather1(_tex, _co) textureGather(_tex, _co, 1)\n#define textureGather2(_tex, _co) textureGather(_tex, _co, 2)\n#define textureGather3(_tex, _co) textureGather(_tex, _co, 3)\nmat2x2 to_float2x2(mat3x3 m) { return mat2x2(m); }\nmat2x2 to_float2x2(mat4x4 m) { return mat2x2(m); }\nmat3x3 to_float3x3(mat4x4 m) { return mat3x3(m); }\nmat3x3 to_float3x3(mat2x2 m) { return mat3x3(m); }\nmat4x4 to_float4x4(mat2x2 m) { return mat4x4(m); }\nmat4x4 to_float4x4(mat3x3 m) { return mat4x4(m); }\nmat3x3 to_float3x3(mat3x4 m) { return mat3x3(m); }\n#define float_from_float4(v, luminance_coefficients) dot(v.rgb, luminance_coefficients)\n#define float_from_float3(v) ((v.r + v.g + v.b) * (1.0f / 3.0f))\n#define float_from_float2(v) ((v.x + v.y) * (1.0f / 2.0f))\n#define float2_from_float4(v) v.xy\n#define float2_from_float3(v) v.xy\n#define float2_from_float(v) float2(v)\n#define float3_from_float4(v) v.rgb\n#define float3_from_float2(v) float3(v.xy, 0.0f)\n#define float3_from_float(v) float3(v)\n#define float4_from_float3(v) float4(v, 1.0f)\n#define float4_from_float2(v) float4(v.xy, 0.0f, 1.0f)\n#define float4_from_float(v) float4(float3(v), 1.0f)\n#define gpu_dfdx(x) dFdx(x)\n#define gpu_dfdy(x) dFdy(x)\n#define gpu_fwidth(x) fwidth(x)";
|
|
6
|
+
export const BLENDER_NODE_GLSL: Readonly<Record<string, {readonly deps: readonly string[]; readonly code: string}>> = {
|
|
7
|
+
"gpu_shader_common_math.glsl": {
|
|
8
|
+
"deps": [
|
|
9
|
+
"gpu_shader_math_constants_lib.glsl",
|
|
10
|
+
"gpu_shader_math_base_lib.glsl",
|
|
11
|
+
"gpu_shader_math_safe_lib.glsl"
|
|
12
|
+
],
|
|
13
|
+
"code": "void math_add(float a, float b, float c, _ref(float ,result))\n{\n result = a + b;\n}\nvoid math_subtract(float a, float b, float c, _ref(float ,result))\n{\n result = a - b;\n}\nvoid math_multiply(float a, float b, float c, _ref(float ,result))\n{\n result = a * b;\n}\nvoid math_divide(float a, float b, float c, _ref(float ,result))\n{\n result = safe_divide(a, b);\n}\nvoid math_power(float a, float b, float c, _ref(float ,result))\n{\n if (a >= 0.0f) {\n result = compatible_pow(a, b);\n }\n else {\n float fraction = mod(abs(b), 1.0f);\n if (fraction > 0.999f || fraction < 0.001f) {\n result = compatible_pow(a, floor(b + 0.5f));\n }\n else {\n result = 0.0f;\n }\n }\n}\nvoid math_logarithm(float a, float b, float c, _ref(float ,result))\n{\n result = (a > 0.0f && b > 0.0f) ? log2(a) / log2(b) : 0.0f;\n}\nvoid math_sqrt(float a, float b, float c, _ref(float ,result))\n{\n result = (a > 0.0f) ? sqrt(a) : 0.0f;\n}\nvoid math_inversesqrt(float a, float b, float c, _ref(float ,result))\n{\n result = inversesqrt(a);\n}\nvoid math_absolute(float a, float b, float c, _ref(float ,result))\n{\n result = abs(a);\n}\nvoid math_radians(float a, float b, float c, _ref(float ,result))\n{\n result = radians(a);\n}\nvoid math_degrees(float a, float b, float c, _ref(float ,result))\n{\n result = degrees(a);\n}\nvoid math_minimum(float a, float b, float c, _ref(float ,result))\n{\n result = min(a, b);\n}\nvoid math_maximum(float a, float b, float c, _ref(float ,result))\n{\n result = max(a, b);\n}\nvoid math_less_than(float a, float b, float c, _ref(float ,result))\n{\n result = (a < b) ? 1.0f : 0.0f;\n}\nvoid math_greater_than(float a, float b, float c, _ref(float ,result))\n{\n result = (a > b) ? 1.0f : 0.0f;\n}\nvoid math_round(float a, float b, float c, _ref(float ,result))\n{\n result = floor(a + 0.5f);\n}\nvoid math_floor(float a, float b, float c, _ref(float ,result))\n{\n result = floor(a);\n}\nvoid math_ceil(float a, float b, float c, _ref(float ,result))\n{\n result = ceil(a);\n}\nvoid math_fraction(float a, float b, float c, _ref(float ,result))\n{\n result = a - floor(a);\n}\nvoid math_modulo(float a, float b, float c, _ref(float ,result))\n{\n result = compatible_mod(a, b);\n}\nvoid math_floored_modulo(float a, float b, float c, _ref(float ,result))\n{\n result = (b != 0.0f) ? a - floor(a / b) * b : 0.0f;\n}\nvoid math_trunc(float a, float b, float c, _ref(float ,result))\n{\n result = trunc(a);\n}\nvoid math_snap(float a, float b, float c, _ref(float ,result))\n{\n result = floor(safe_divide(a, b)) * b;\n}\nvoid math_pingpong(float a, float b, float c, _ref(float ,result))\n{\n result = (b != 0.0f) ? abs(fract((a - b) / (b * 2.0f)) * b * 2.0f - b) : 0.0f;\n}\nvoid math_wrap(float a, float b, float c, _ref(float ,result))\n{\n result = wrap(a, b, c);\n}\nvoid math_sine(float a, float b, float c, _ref(float ,result))\n{\n result = sin(a);\n}\nvoid math_cosine(float a, float b, float c, _ref(float ,result))\n{\n result = cos(a);\n}\nvoid math_tangent(float a, float b, float c, _ref(float ,result))\n{\n result = tan(a);\n}\nvoid math_sinh(float a, float b, float c, _ref(float ,result))\n{\n result = sinh(a);\n}\nvoid math_cosh(float a, float b, float c, _ref(float ,result))\n{\n result = cosh(a);\n}\nvoid math_tanh(float a, float b, float c, _ref(float ,result))\n{\n result = tanh(a);\n}\nvoid math_arcsine(float a, float b, float c, _ref(float ,result))\n{\n result = (a <= 1.0f && a >= -1.0f) ? asin(a) : 0.0f;\n}\nvoid math_arccosine(float a, float b, float c, _ref(float ,result))\n{\n result = (a <= 1.0f && a >= -1.0f) ? acos(a) : 0.0f;\n}\nvoid math_arctangent(float a, float b, float c, _ref(float ,result))\n{\n result = atan(a);\n}\nvoid math_arctan2(float a, float b, float c, _ref(float ,result))\n{\n result = ((a == 0.0f && b == 0.0f) ? 0.0f : atan(a, b));\n}\nvoid math_sign(float a, float b, float c, _ref(float ,result))\n{\n result = sign(a);\n}\nvoid math_exponent(float a, float b, float c, _ref(float ,result))\n{\n result = exp(a);\n}\nvoid math_compare(float a, float b, float c, _ref(float ,result))\n{\n result = (abs(a - b) <= max(c, 1e-5f)) ? 1.0f : 0.0f;\n}\nvoid math_multiply_add(float a, float b, float c, _ref(float ,result))\n{\n result = a * b + c;\n}\nvoid math_smoothmin(float a, float b, float c, _ref(float ,result))\n{\n if (c != 0.0f) {\n float h = max(c - abs(a - b), 0.0f) / c;\n result = min(a, b) - h * h * h * c * (1.0f / 6.0f);\n }\n else {\n result = min(a, b);\n }\n}\nvoid math_smoothmax(float a, float b, float c, _ref(float ,result))\n{\n math_smoothmin(-a, -b, c, result);\n result = -result;\n}\nfloat math_reduce_max(float3 a)\n{\n return max(a.x, max(a.y, a.z));\n}\n\nfloat math_average(float3 a)\n{\n return (a.x + a.y + a.z) * (1.0f / 3.0f);\n}"
|
|
14
|
+
},
|
|
15
|
+
"gpu_shader_math_constants_lib.glsl": {
|
|
16
|
+
"deps": [],
|
|
17
|
+
"code": "#define M_PI 3.14159265358979323846f\n#define M_TAU 6.28318530717958647692f\n#define M_PI_2 1.57079632679489661923f\n#define M_PI_4 0.78539816339744830962f\n#define M_SQRT2 1.41421356237309504880f\n#define M_SQRT1_2 0.70710678118654752440f\n#define M_SQRT3 1.73205080756887729352f\n#define M_SQRT1_3 0.57735026918962576450f\n#define M_1_PI 0.318309886183790671538f\n#define M_E 2.7182818284590452354f\n#define M_LOG2E 1.4426950408889634074f\n#define M_LOG10E 0.43429448190325182765f\n#define M_LN2 0.69314718055994530942f\n#define M_LN10 2.30258509299404568402f"
|
|
18
|
+
},
|
|
19
|
+
"gpu_shader_math_base_lib.glsl": {
|
|
20
|
+
"deps": [
|
|
21
|
+
"gpu_shader_math_constants_lib.glsl"
|
|
22
|
+
],
|
|
23
|
+
"code": "float pow2f(float x)\n{\n return x * x;\n}\nfloat pow3f(float x)\n{\n return x * x * x;\n}\nfloat pow4f(float x)\n{\n return pow2f(pow2f(x));\n}\nfloat pow5f(float x)\n{\n return pow4f(x) * x;\n}\nfloat pow6f(float x)\n{\n return pow2f(pow3f(x));\n}\nfloat pow7f(float x)\n{\n return pow6f(x) * x;\n}\nfloat pow8f(float x)\n{\n return pow2f(pow4f(x));\n}\n\nfloat square(float v)\n{\n return v * v;\n}\nfloat2 square(float2 v)\n{\n return v * v;\n}\nfloat3 square(float3 v)\n{\n return v * v;\n}\nfloat4 square(float4 v)\n{\n return v * v;\n}\n\nfloat hypot(float x, float y)\n{\n return sqrt(x * x + y * y);\n}\nfloat _atan2(float y, float x)\n{\n return atan(y, x);\n}\n#define atan2 _atan2\nint ceil_to_multiple(int a, int b)\n{\n return ((a + b - 1) / b) * b;\n}\nuint ceil_to_multiple(uint a, uint b)\n{\n return ((a + b - 1u) / b) * b;\n}\nint divide_ceil(int a, int b)\n{\n return (a + b - 1) / b;\n}\nuint divide_ceil(uint a, uint b)\n{\n return (a + b - 1u) / b;\n}\nvoid min_max(float value, _ref(float ,min_v), _ref(float ,max_v))\n{\n min_v = min(value, min_v);\n max_v = max(value, max_v);\n}\nbool is_equal(float a, float b, const float epsilon)\n{\n return abs(a - b) <= epsilon;\n}\n\nfloat sin_from_cos(float c)\n{\n return sqrt(max(0.0f, 1.0f - square(c)));\n}\n\nfloat cos_from_sin(float s)\n{\n return sqrt(max(0.0f, 1.0f - square(s)));\n}\n\nfloat cos_from_tan(float t)\n{\n return inversesqrt(1.0f + square(t));\n}"
|
|
24
|
+
},
|
|
25
|
+
"gpu_shader_math_safe_lib.glsl": {
|
|
26
|
+
"deps": [
|
|
27
|
+
"gpu_shader_math_constants_lib.glsl"
|
|
28
|
+
],
|
|
29
|
+
"code": "float safe_mod(float a, float b)\n{\n return (b != 0.0f) ? mod(a, b) : 0.0f;\n}\nfloat safe_divide(float a, float b)\n{\n return (b != 0.0f) ? (a / b) : 0.0f;\n}\nfloat safe_rcp(float a)\n{\n return (a != 0.0f) ? (1.0f / a) : 0.0f;\n}\nfloat safe_sqrt(float a)\n{\n return sqrt(max(0.0f, a));\n}\nfloat safe_acos(float a)\n{\n if (a <= -1.0f) {\n return M_PI;\n }\n else if (a >= 1.0f) {\n return 0.0f;\n }\n return acos(a);\n}\nfloat fallback_pow(float x, float y, float fallback)\n{\n if (x < 0.0f || (x == 0.0f && y <= 0.0f)) {\n return fallback;\n }\n\n return pow(x, y);\n}\nfloat compatible_pow(float x, float y)\n{\n if (y == 0.0f) {\n return 1.0f;\n }\n if (x < 0.0f) {\n if (mod(-y, 2.0f) == 0.0f) {\n return pow(-x, y);\n }\n else {\n return -pow(-x, y);\n }\n }\n else if (x == 0.0f) {\n return 0.0f;\n }\n\n return pow(x, y);\n}\nfloat compatible_mod(float a, float b)\n{\n if (b != 0.0f) {\n int N = int(a / b);\n return a - float(N) * b;\n }\n return 0.0f;\n}\nfloat wrap(float a, float b, float c)\n{\n float range = b - c;\n\n float s = (a != b) ? floor((a - c) / range) : 1.0f;\n return (range != 0.0f) ? a - range * s : c;\n}"
|
|
30
|
+
},
|
|
31
|
+
"gpu_shader_common_color_ramp.glsl": {
|
|
32
|
+
"deps": [
|
|
33
|
+
"gpu_shader_math_constants_lib.glsl"
|
|
34
|
+
],
|
|
35
|
+
"code": "void valtorgb_opti_constant(\n float fac, float edge, float4 color1, float4 color2, _ref(float4 ,outcol), _ref(float ,outalpha))\n{\n outcol = (fac > edge) ? color2 : color1;\n outalpha = outcol.a;\n}\nvoid valtorgb_opti_linear(\n float fac, float2 mulbias, float4 color1, float4 color2, _ref(float4 ,outcol), _ref(float ,outalpha))\n{\n fac = clamp(fac * mulbias.x + mulbias.y, 0.0f, 1.0f);\n outcol = mix(color1, color2, fac);\n outalpha = outcol.a;\n}\nvoid valtorgb_opti_ease(\n float fac, float2 mulbias, float4 color1, float4 color2, _ref(float4 ,outcol), _ref(float ,outalpha))\n{\n fac = clamp(fac * mulbias.x + mulbias.y, 0.0f, 1.0f);\n fac = fac * fac * (3.0f - 2.0f * fac);\n outcol = mix(color1, color2, fac);\n outalpha = outcol.a;\n}\nfloat compute_color_map_coordinate(float coordinate)\n{\n constexpr float sampler_resolution = 257.0f;\n constexpr float sampler_offset = 0.5f / sampler_resolution;\n constexpr float sampler_scale = 1.0f - (1.0f / sampler_resolution);\n return coordinate * sampler_scale + sampler_offset;\n}\nvoid valtorgb(float fac, sampler2D colormap, float layer, _ref(float4 ,outcol), _ref(float ,outalpha))\n{\n outcol = texture(colormap, float2(compute_color_map_coordinate(fac), layer));\n outalpha = outcol.a;\n}\nvoid valtorgb_nearest(\n float fac, sampler2D colormap, float layer, _ref(float4 ,outcol), _ref(float ,outalpha))\n{\n fac = clamp(fac, 0.0f, 1.0f);\n outcol = texelFetch(colormap, int2(fac * float(textureSize(colormap, 0).x - 1), layer), 0);\n outalpha = outcol.a;\n}"
|
|
36
|
+
},
|
|
37
|
+
"gpu_shader_common_mix_rgb.glsl": {
|
|
38
|
+
"deps": [
|
|
39
|
+
"gpu_shader_math_constants_lib.glsl",
|
|
40
|
+
"gpu_shader_common_color_utils.glsl"
|
|
41
|
+
],
|
|
42
|
+
"code": "void mix_blend(float fac, float4 col1, float4 col2, _ref(float4 ,outcol))\n{\n outcol = mix(col1, col2, fac);\n outcol.a = col1.a;\n}\nvoid mix_add(float fac, float4 col1, float4 col2, _ref(float4 ,outcol))\n{\n outcol = mix(col1, col1 + col2, fac);\n outcol.a = col1.a;\n}\nvoid mix_mult(float fac, float4 col1, float4 col2, _ref(float4 ,outcol))\n{\n outcol = mix(col1, col1 * col2, fac);\n outcol.a = col1.a;\n}\nvoid mix_screen(float fac, float4 col1, float4 col2, _ref(float4 ,outcol))\n{\n float facm = 1.0f - fac;\n\n outcol = float4(1.0f) - (float4(facm) + fac * (float4(1.0f) - col2)) * (float4(1.0f) - col1);\n outcol.a = col1.a;\n}\nvoid mix_overlay(float fac, float4 col1, float4 col2, _ref(float4 ,outcol))\n{\n float facm = 1.0f - fac;\n\n outcol = col1;\n\n if (outcol.r < 0.5f) {\n outcol.r *= facm + 2.0f * fac * col2.r;\n }\n else {\n outcol.r = 1.0f - (facm + 2.0f * fac * (1.0f - col2.r)) * (1.0f - outcol.r);\n }\n\n if (outcol.g < 0.5f) {\n outcol.g *= facm + 2.0f * fac * col2.g;\n }\n else {\n outcol.g = 1.0f - (facm + 2.0f * fac * (1.0f - col2.g)) * (1.0f - outcol.g);\n }\n\n if (outcol.b < 0.5f) {\n outcol.b *= facm + 2.0f * fac * col2.b;\n }\n else {\n outcol.b = 1.0f - (facm + 2.0f * fac * (1.0f - col2.b)) * (1.0f - outcol.b);\n }\n}\nvoid mix_sub(float fac, float4 col1, float4 col2, _ref(float4 ,outcol))\n{\n outcol = mix(col1, col1 - col2, fac);\n outcol.a = col1.a;\n}\nvoid mix_div(float fac, float4 col1, float4 col2, _ref(float4 ,outcol))\n{\n float facm = 1.0f - fac;\n\n outcol = float4(float3(0.0f), col1.a);\n\n if (col2.r != 0.0f) {\n outcol.r = facm * col1.r + fac * col1.r / col2.r;\n }\n if (col2.g != 0.0f) {\n outcol.g = facm * col1.g + fac * col1.g / col2.g;\n }\n if (col2.b != 0.0f) {\n outcol.b = facm * col1.b + fac * col1.b / col2.b;\n }\n}\nvoid mix_div_fallback(float fac, float4 col1, float4 col2, _ref(float4 ,outcol))\n{\n float facm = 1.0f - fac;\n\n outcol = col1;\n\n if (col2.r != 0.0f) {\n outcol.r = facm * outcol.r + fac * outcol.r / col2.r;\n }\n if (col2.g != 0.0f) {\n outcol.g = facm * outcol.g + fac * outcol.g / col2.g;\n }\n if (col2.b != 0.0f) {\n outcol.b = facm * outcol.b + fac * outcol.b / col2.b;\n }\n}\nvoid mix_diff(float fac, float4 col1, float4 col2, _ref(float4 ,outcol))\n{\n outcol = mix(col1, abs(col1 - col2), fac);\n outcol.a = col1.a;\n}\nvoid mix_exclusion(float fac, float4 col1, float4 col2, _ref(float4 ,outcol))\n{\n outcol = max(mix(col1, col1 + col2 - 2.0f * col1 * col2, fac), 0.0f);\n outcol.a = col1.a;\n}\nvoid mix_dark(float fac, float4 col1, float4 col2, _ref(float4 ,outcol))\n{\n outcol.rgb = mix(col1.rgb, min(col1.rgb, col2.rgb), fac);\n outcol.a = col1.a;\n}\nvoid mix_light(float fac, float4 col1, float4 col2, _ref(float4 ,outcol))\n{\n outcol.rgb = mix(col1.rgb, max(col1.rgb, col2.rgb), fac);\n outcol.a = col1.a;\n}\nvoid mix_dodge(float fac, float4 col1, float4 col2, _ref(float4 ,outcol))\n{\n outcol = col1;\n\n if (outcol.r != 0.0f) {\n float tmp = 1.0f - fac * col2.r;\n if (tmp <= 0.0f) {\n outcol.r = 1.0f;\n }\n else if ((tmp = outcol.r / tmp) > 1.0f) {\n outcol.r = 1.0f;\n }\n else {\n outcol.r = tmp;\n }\n }\n if (outcol.g != 0.0f) {\n float tmp = 1.0f - fac * col2.g;\n if (tmp <= 0.0f) {\n outcol.g = 1.0f;\n }\n else if ((tmp = outcol.g / tmp) > 1.0f) {\n outcol.g = 1.0f;\n }\n else {\n outcol.g = tmp;\n }\n }\n if (outcol.b != 0.0f) {\n float tmp = 1.0f - fac * col2.b;\n if (tmp <= 0.0f) {\n outcol.b = 1.0f;\n }\n else if ((tmp = outcol.b / tmp) > 1.0f) {\n outcol.b = 1.0f;\n }\n else {\n outcol.b = tmp;\n }\n }\n}\nvoid mix_burn(float fac, float4 col1, float4 col2, _ref(float4 ,outcol))\n{\n float tmp, facm = 1.0f - fac;\n\n outcol = col1;\n\n tmp = facm + fac * col2.r;\n if (tmp <= 0.0f) {\n outcol.r = 0.0f;\n }\n else if ((tmp = (1.0f - (1.0f - outcol.r) / tmp)) < 0.0f) {\n outcol.r = 0.0f;\n }\n else if (tmp > 1.0f) {\n outcol.r = 1.0f;\n }\n else {\n outcol.r = tmp;\n }\n\n tmp = facm + fac * col2.g;\n if (tmp <= 0.0f) {\n outcol.g = 0.0f;\n }\n else if ((tmp = (1.0f - (1.0f - outcol.g) / tmp)) < 0.0f) {\n outcol.g = 0.0f;\n }\n else if (tmp > 1.0f) {\n outcol.g = 1.0f;\n }\n else {\n outcol.g = tmp;\n }\n\n tmp = facm + fac * col2.b;\n if (tmp <= 0.0f) {\n outcol.b = 0.0f;\n }\n else if ((tmp = (1.0f - (1.0f - outcol.b) / tmp)) < 0.0f) {\n outcol.b = 0.0f;\n }\n else if (tmp > 1.0f) {\n outcol.b = 1.0f;\n }\n else {\n outcol.b = tmp;\n }\n}\nvoid mix_hue(float fac, float4 col1, float4 col2, _ref(float4 ,outcol))\n{\n float facm = 1.0f - fac;\n\n outcol = col1;\n\n float4 hsv, hsv2, tmp;\n rgb_to_hsv(col2, hsv2);\n\n if (hsv2.y != 0.0f) {\n rgb_to_hsv(outcol, hsv);\n hsv.x = hsv2.x;\n hsv_to_rgb(hsv, tmp);\n\n outcol = mix(outcol, tmp, fac);\n outcol.a = col1.a;\n }\n}\nvoid mix_sat(float fac, float4 col1, float4 col2, _ref(float4 ,outcol))\n{\n float facm = 1.0f - fac;\n\n outcol = col1;\n\n float4 hsv, hsv2;\n rgb_to_hsv(outcol, hsv);\n\n if (hsv.y != 0.0f) {\n rgb_to_hsv(col2, hsv2);\n\n hsv.y = facm * hsv.y + fac * hsv2.y;\n hsv_to_rgb(hsv, outcol);\n }\n}\nvoid mix_val(float fac, float4 col1, float4 col2, _ref(float4 ,outcol))\n{\n float facm = 1.0f - fac;\n\n float4 hsv, hsv2;\n rgb_to_hsv(col1, hsv);\n rgb_to_hsv(col2, hsv2);\n\n hsv.z = facm * hsv.z + fac * hsv2.z;\n hsv_to_rgb(hsv, outcol);\n}\nvoid mix_color(float fac, float4 col1, float4 col2, _ref(float4 ,outcol))\n{\n float facm = 1.0f - fac;\n\n outcol = col1;\n\n float4 hsv, hsv2, tmp;\n rgb_to_hsv(col2, hsv2);\n\n if (hsv2.y != 0.0f) {\n rgb_to_hsv(outcol, hsv);\n hsv.x = hsv2.x;\n hsv.y = hsv2.y;\n hsv_to_rgb(hsv, tmp);\n\n outcol = mix(outcol, tmp, fac);\n outcol.a = col1.a;\n }\n}\nvoid mix_soft(float fac, float4 col1, float4 col2, _ref(float4 ,outcol))\n{\n float facm = 1.0f - fac;\n\n float4 one = float4(1.0f);\n float4 scr = one - (one - col2) * (one - col1);\n outcol = facm * col1 + fac * ((one - col1) * col2 * col1 + col1 * scr);\n outcol.a = col1.a;\n}\nvoid mix_linear(float fac, float4 col1, float4 col2, _ref(float4 ,outcol))\n{\n outcol = col1 + fac * (2.0f * (col2 - float4(0.5f)));\n outcol.a = col1.a;\n}\nvoid clamp_color(float4 vec, const float4 min, const float4 max, _ref(float4 ,out_vec))\n{\n out_vec = clamp(vec, min, max);\n}\nvoid multiply_by_alpha(float factor, float4 color, _ref(float ,result))\n{\n result = factor * color.a;\n}"
|
|
43
|
+
},
|
|
44
|
+
"gpu_shader_common_color_utils.glsl": {
|
|
45
|
+
"deps": [
|
|
46
|
+
"gpu_shader_math_constants_lib.glsl"
|
|
47
|
+
],
|
|
48
|
+
"code": "void rgb_to_hsv(float4 rgb, _ref(float4 ,outcol))\n{\n float cmax, cmin, h, s, v, cdelta;\n float3 c;\n\n cmax = max(rgb[0], max(rgb[1], rgb[2]));\n cmin = min(rgb[0], min(rgb[1], rgb[2]));\n cdelta = cmax - cmin;\n\n v = cmax;\n if (cmax != 0.0f) {\n s = cdelta / cmax;\n }\n else {\n s = 0.0f;\n h = 0.0f;\n }\n\n if (s == 0.0f) {\n h = 0.0f;\n }\n else {\n c = (float3(cmax) - rgb.xyz) / cdelta;\n\n if (rgb.x == cmax) {\n h = c[2] - c[1];\n }\n else if (rgb.y == cmax) {\n h = 2.0f + c[0] - c[2];\n }\n else {\n h = 4.0f + c[1] - c[0];\n }\n\n h /= 6.0f;\n\n if (h < 0.0f) {\n h += 1.0f;\n }\n }\n\n outcol = float4(h, s, v, rgb.w);\n}\nvoid hsv_to_rgb(float4 hsv, _ref(float4 ,outcol))\n{\n float i, f, p, q, t, h, s, v;\n float3 rgb;\n\n h = hsv[0];\n s = hsv[1];\n v = hsv[2];\n\n if (s == 0.0f) {\n rgb = float3(v, v, v);\n }\n else {\n if (h == 1.0f) {\n h = 0.0f;\n }\n\n h *= 6.0f;\n i = floor(h);\n f = h - i;\n rgb = float3(f, f, f);\n p = v * (1.0f - s);\n q = v * (1.0f - (s * f));\n t = v * (1.0f - (s * (1.0f - f)));\n\n if (i == 0.0f) {\n rgb = float3(v, t, p);\n }\n else if (i == 1.0f) {\n rgb = float3(q, v, p);\n }\n else if (i == 2.0f) {\n rgb = float3(p, v, t);\n }\n else if (i == 3.0f) {\n rgb = float3(p, q, v);\n }\n else if (i == 4.0f) {\n rgb = float3(t, p, v);\n }\n else {\n rgb = float3(v, p, q);\n }\n }\n\n outcol = float4(rgb, hsv.w);\n}\nvoid rgb_to_hsl(float4 rgb, _ref(float4 ,outcol))\n{\n float cmax, cmin, h, s, l;\n\n cmax = max(rgb[0], max(rgb[1], rgb[2]));\n cmin = min(rgb[0], min(rgb[1], rgb[2]));\n l = min(1.0f, (cmax + cmin) / 2.0f);\n\n if (cmax == cmin) {\n h = s = 0.0f;\n }\n else {\n float cdelta = cmax - cmin;\n s = l > 0.5f ? cdelta / (2.0f - cmax - cmin) : cdelta / (cmax + cmin);\n if (cmax == rgb[0]) {\n h = (rgb[1] - rgb[2]) / cdelta + (rgb[1] < rgb[2] ? 6.0f : 0.0f);\n }\n else if (cmax == rgb[1]) {\n h = (rgb[2] - rgb[0]) / cdelta + 2.0f;\n }\n else {\n h = (rgb[0] - rgb[1]) / cdelta + 4.0f;\n }\n }\n h /= 6.0f;\n\n outcol = float4(h, s, l, rgb.w);\n}\nvoid hsl_to_rgb(float4 hsl, _ref(float4 ,outcol))\n{\n float nr, ng, nb, chroma, h, s, l;\n\n h = hsl[0];\n s = hsl[1];\n l = hsl[2];\n\n nr = abs(h * 6.0f - 3.0f) - 1.0f;\n ng = 2.0f - abs(h * 6.0f - 2.0f);\n nb = 2.0f - abs(h * 6.0f - 4.0f);\n\n nr = clamp(nr, 0.0f, 1.0f);\n nb = clamp(nb, 0.0f, 1.0f);\n ng = clamp(ng, 0.0f, 1.0f);\n\n chroma = (1.0f - abs(2.0f * l - 1.0f)) * s;\n\n outcol = float4(\n (nr - 0.5f) * chroma + l, (ng - 0.5f) * chroma + l, (nb - 0.5f) * chroma + l, hsl.w);\n}\nvoid ycca_to_rgba_itu_601(float4 ycca, _ref(float4 ,color))\n{\n ycca.xyz *= 255.0f;\n ycca.xyz -= float3(16.0f, 128.0f, 128.0f);\n color.rgb = float3x3(1.164f, 1.164f, 1.164f, 0.0f, -0.392f, 2.017f, 1.596f, -0.813f, 0.0f) *\n ycca.xyz;\n color.rgb /= 255.0f;\n color.a = ycca.a;\n}\nvoid ycca_to_rgba_itu_709(float4 ycca, _ref(float4 ,color))\n{\n ycca.xyz *= 255.0f;\n ycca.xyz -= float3(16.0f, 128.0f, 128.0f);\n color.rgb = float3x3(1.164f, 1.164f, 1.164f, 0.0f, -0.213f, 2.115f, 1.793f, -0.534f, 0.0f) *\n ycca.xyz;\n color.rgb /= 255.0f;\n color.a = ycca.a;\n}\nvoid ycca_to_rgba_jpeg(float4 ycca, _ref(float4 ,color))\n{\n ycca.xyz *= 255.0f;\n color.rgb = float3x3(1.0f, 1.0f, 1.0f, 0.0f, -0.34414f, 1.772f, 1.402f, -0.71414f, 0.0f) *\n ycca.xyz;\n color.rgb += float3(-179.456f, 135.45984f, -226.816f);\n color.rgb /= 255.0f;\n color.a = ycca.a;\n}\nvoid rgba_to_ycca_itu_601(float4 rgba, _ref(float4 ,ycca))\n{\n rgba.rgb *= 255.0f;\n ycca.xyz = float3x3(0.257f, -0.148f, 0.439f, 0.504f, -0.291f, -0.368f, 0.098f, 0.439f, -0.071f) *\n rgba.rgb;\n ycca.xyz += float3(16.0f, 128.0f, 128.0f);\n ycca.xyz /= 255.0f;\n ycca.a = rgba.a;\n}\nvoid rgba_to_ycca_itu_709(float4 rgba, _ref(float4 ,ycca))\n{\n rgba.rgb *= 255.0f;\n ycca.xyz = float3x3(0.183f, -0.101f, 0.439f, 0.614f, -0.338f, -0.399f, 0.062f, 0.439f, -0.040f) *\n rgba.rgb;\n ycca.xyz += float3(16.0f, 128.0f, 128.0f);\n ycca.xyz /= 255.0f;\n ycca.a = rgba.a;\n}\nvoid rgba_to_ycca_jpeg(float4 rgba, _ref(float4 ,ycca))\n{\n rgba.rgb *= 255.0f;\n ycca.xyz = float3x3(\n 0.299f, -0.16874f, 0.5f, 0.587f, -0.33126f, -0.41869f, 0.114f, 0.5f, -0.08131f) *\n rgba.rgb;\n ycca.xyz += float3(0.0f, 128.0f, 128.0f);\n ycca.xyz /= 255.0f;\n ycca.a = rgba.a;\n}\nvoid yuva_to_rgba_itu_709(float4 yuva, _ref(float4 ,color))\n{\n color.rgb = float3x3(1.0f, 1.0f, 1.0f, 0.0f, -0.21482f, 2.12798f, 1.28033f, -0.38059f, 0.0f) *\n yuva.xyz;\n color.a = yuva.a;\n}\nvoid rgba_to_yuva_itu_709(float4 rgba, _ref(float4 ,yuva))\n{\n yuva.xyz =\n float3x3(\n 0.2126f, -0.09991f, 0.615f, 0.7152f, -0.33609f, -0.55861f, 0.0722f, 0.436f, -0.05639f) *\n rgba.rgb;\n yuva.a = rgba.a;\n}\nvoid color_alpha_clear(float4 color, _ref(float4 ,result))\n{\n result = float4(color.rgb, 1.0f);\n}\nvoid color_alpha_premultiply(float4 color, _ref(float4 ,result))\n{\n result = float4(color.rgb * color.a, color.a);\n}\nvoid color_alpha_unpremultiply(float4 color, _ref(float4 ,result))\n{\n if (color.a == 0.0f || color.a == 1.0f) {\n result = color;\n }\n else {\n result = float4(color.rgb / color.a, color.a);\n }\n}\n\nfloat linear_rgb_to_srgb(float color)\n{\n if (color < 0.0031308f) {\n return (color < 0.0f) ? 0.0f : color * 12.92f;\n }\n\n return 1.055f * pow(color, 1.0f / 2.4f) - 0.055f;\n}\n\nfloat3 linear_rgb_to_srgb(float3 color)\n{\n return float3(\n linear_rgb_to_srgb(color.r), linear_rgb_to_srgb(color.g), linear_rgb_to_srgb(color.b));\n}\n\nfloat srgb_to_linear_rgb(float color)\n{\n if (color < 0.04045f) {\n return (color < 0.0f) ? 0.0f : color * (1.0f / 12.92f);\n }\n\n return pow((color + 0.055f) * (1.0f / 1.055f), 2.4f);\n}\n\nfloat3 srgb_to_linear_rgb(float3 color)\n{\n return float3(\n srgb_to_linear_rgb(color.r), srgb_to_linear_rgb(color.g), srgb_to_linear_rgb(color.b));\n}\n\nfloat get_luminance(float3 color, float3 luminance_coefficients)\n{\n return dot(color, luminance_coefficients);\n}"
|
|
49
|
+
},
|
|
50
|
+
"gpu_shader_material_bright_contrast.glsl": {
|
|
51
|
+
"deps": [
|
|
52
|
+
"gpu_shader_math_constants_lib.glsl"
|
|
53
|
+
],
|
|
54
|
+
"code": "void brightness_contrast(float4 col, float brightness, float contrast, _ref(float4 ,outcol))\n{\n float a = 1.0f + contrast;\n float b = brightness - contrast * 0.5f;\n\n outcol.r = max(a * col.r + b, 0.0f);\n outcol.g = max(a * col.g + b, 0.0f);\n outcol.b = max(a * col.b + b, 0.0f);\n outcol.a = col.a;\n}"
|
|
55
|
+
},
|
|
56
|
+
"gpu_shader_material_clamp.glsl": {
|
|
57
|
+
"deps": [
|
|
58
|
+
"gpu_shader_math_constants_lib.glsl"
|
|
59
|
+
],
|
|
60
|
+
"code": "void clamp_value(float value, float min, float max, _ref(float ,result))\n{\n result = clamp(value, min, max);\n}\nvoid clamp_minmax(float value, float min_allowed, float max_allowed, _ref(float ,result))\n{\n result = min(max(value, min_allowed), max_allowed);\n}\nvoid clamp_range(float value, float min, float max, _ref(float ,result))\n{\n result = (max > min) ? clamp(value, min, max) : clamp(value, max, min);\n}"
|
|
61
|
+
},
|
|
62
|
+
"gpu_shader_material_combine_color.glsl": {
|
|
63
|
+
"deps": [
|
|
64
|
+
"gpu_shader_math_constants_lib.glsl",
|
|
65
|
+
"gpu_shader_common_color_utils.glsl"
|
|
66
|
+
],
|
|
67
|
+
"code": "void combine_color_rgb(float r, float g, float b, _ref(float4 ,col))\n{\n col = float4(r, g, b, 1.0f);\n}\nvoid combine_color_hsv(float h, float s, float v, _ref(float4 ,col))\n{\n hsv_to_rgb(float4(h, s, v, 1.0f), col);\n}\nvoid combine_color_hsl(float h, float s, float l, _ref(float4 ,col))\n{\n hsl_to_rgb(float4(h, s, l, 1.0f), col);\n}"
|
|
68
|
+
},
|
|
69
|
+
"gpu_shader_material_combine_xyz.glsl": {
|
|
70
|
+
"deps": [
|
|
71
|
+
"gpu_shader_math_constants_lib.glsl"
|
|
72
|
+
],
|
|
73
|
+
"code": "void combine_xyz(float x, float y, float z, _ref(float3 ,vec))\n{\n vec = float3(x, y, z);\n}"
|
|
74
|
+
},
|
|
75
|
+
"gpu_shader_material_fresnel.glsl": {
|
|
76
|
+
"deps": [
|
|
77
|
+
"gpu_shader_math_constants_lib.glsl"
|
|
78
|
+
],
|
|
79
|
+
"code": "float fresnel_dielectric_cos(float cosi, float eta)\n{\n float c = abs(cosi);\n float g = eta * eta - 1.0f + c * c;\n float result;\n\n if (g > 0.0f) {\n g = sqrt(g);\n float A = (g - c) / (g + c);\n float B = (c * (g + c) - 1.0f) / (c * (g - c) + 1.0f);\n result = 0.5f * A * A * (1.0f + B * B);\n }\n else {\n result = 1.0f;\n }\n\n return result;\n}\n\nfloat fresnel_dielectric(float3 Incoming, float3 Normal, float eta)\n{\n return fresnel_dielectric_cos(dot(Incoming, Normal), eta);\n}\nvoid node_fresnel(float ior, float3 N, _ref(float ,result))\n{\n N = normalize(N);\n float3 V = coordinate_incoming(g_data.P);\n\n float eta = max(ior, 0.00001f);\n result = fresnel_dielectric(V, N, (FrontFacing) ? eta : 1.0f / eta);\n}"
|
|
80
|
+
},
|
|
81
|
+
"gpu_shader_material_gamma.glsl": {
|
|
82
|
+
"deps": [
|
|
83
|
+
"gpu_shader_math_constants_lib.glsl",
|
|
84
|
+
"gpu_shader_math_safe_lib.glsl"
|
|
85
|
+
],
|
|
86
|
+
"code": "void node_gamma(float4 col, float gamma, _ref(float4 ,outcol))\n{\n outcol = col;\n\n if (col.r > 0.0f) {\n outcol.r = compatible_pow(col.r, gamma);\n }\n if (col.g > 0.0f) {\n outcol.g = compatible_pow(col.g, gamma);\n }\n if (col.b > 0.0f) {\n outcol.b = compatible_pow(col.b, gamma);\n }\n}"
|
|
87
|
+
},
|
|
88
|
+
"gpu_shader_material_hue_sat_val.glsl": {
|
|
89
|
+
"deps": [
|
|
90
|
+
"gpu_shader_math_constants_lib.glsl",
|
|
91
|
+
"gpu_shader_common_color_utils.glsl"
|
|
92
|
+
],
|
|
93
|
+
"code": "void hue_sat(float hue, float sat, float value, float fac, float4 col, _ref(float4 ,outcol))\n{\n float4 hsv;\n\n rgb_to_hsv(col, hsv);\n\n hsv[0] = fract(hsv[0] + hue + 0.5f);\n hsv[1] = clamp(hsv[1] * sat, 0.0f, 1.0f);\n hsv[2] = hsv[2] * value;\n\n hsv_to_rgb(hsv, outcol);\n\n outcol = mix(col, outcol, fac);\n}"
|
|
94
|
+
},
|
|
95
|
+
"gpu_shader_material_invert.glsl": {
|
|
96
|
+
"deps": [
|
|
97
|
+
"gpu_shader_math_constants_lib.glsl"
|
|
98
|
+
],
|
|
99
|
+
"code": "void invert(float fac, float4 col, _ref(float4 ,outcol))\n{\n outcol.xyz = mix(col.xyz, float3(1.0f) - col.xyz, fac);\n outcol.w = col.w;\n}"
|
|
100
|
+
},
|
|
101
|
+
"gpu_shader_material_layer_weight.glsl": {
|
|
102
|
+
"deps": [
|
|
103
|
+
"gpu_shader_math_constants_lib.glsl",
|
|
104
|
+
"gpu_shader_material_fresnel.glsl"
|
|
105
|
+
],
|
|
106
|
+
"code": "void node_layer_weight(float blend, float3 N, _ref(float ,fresnel), _ref(float ,facing))\n{\n N = normalize(N);\n float eta = max(1.0f - blend, 0.00001f);\n float3 V = coordinate_incoming(g_data.P);\n\n fresnel = fresnel_dielectric(V, N, (FrontFacing) ? 1.0f / eta : eta);\n facing = abs(dot(V, N));\n if (blend != 0.5f) {\n blend = clamp(blend, 0.0f, 0.99999f);\n blend = (blend < 0.5f) ? 2.0f * blend : 0.5f / (1.0f - blend);\n facing = pow(facing, blend);\n }\n facing = 1.0f - facing;\n}"
|
|
107
|
+
},
|
|
108
|
+
"gpu_shader_material_map_range.glsl": {
|
|
109
|
+
"deps": [
|
|
110
|
+
"gpu_shader_math_constants_lib.glsl",
|
|
111
|
+
"gpu_shader_math_safe_lib.glsl",
|
|
112
|
+
"gpu_shader_math_vector_safe_lib.glsl"
|
|
113
|
+
],
|
|
114
|
+
"code": "float smootherstep(float edge0, float edge1, float x)\n{\n x = clamp(safe_divide((x - edge0), (edge1 - edge0)), 0.0f, 1.0f);\n return x * x * x * (x * (x * 6.0f - 15.0f) + 10.0f);\n}\n\nfloat3 smootherstep(float3 edge0, float3 edge1, float3 x)\n{\n x = clamp(safe_divide((x - edge0), (edge1 - edge0)), 0.0f, 1.0f);\n return x * x * x * (x * (x * 6.0f - 15.0f) + 10.0f);\n}\nvoid vector_map_range_linear(float value,\n float fromMin,\n float fromMax,\n float toMin,\n float toMax,\n float steps,\n float3 v_value,\n float3 v_from_min,\n float3 v_from_max,\n float3 v_to_min,\n float3 v_to_max,\n float3 v_steps,\n float use_clamp,\n _ref(float ,result),\n _ref(float3 ,v_result))\n{\n float3 factor = safe_divide((v_value - v_from_min), (v_from_max - v_from_min));\n v_result = v_to_min + factor * (v_to_max - v_to_min);\n if (use_clamp > 0.0f) {\n v_result.x = (v_to_min.x > v_to_max.x) ? clamp(v_result.x, v_to_max.x, v_to_min.x) :\n clamp(v_result.x, v_to_min.x, v_to_max.x);\n v_result.y = (v_to_min.y > v_to_max.y) ? clamp(v_result.y, v_to_max.y, v_to_min.y) :\n clamp(v_result.y, v_to_min.y, v_to_max.y);\n v_result.z = (v_to_min.z > v_to_max.z) ? clamp(v_result.z, v_to_max.z, v_to_min.z) :\n clamp(v_result.z, v_to_min.z, v_to_max.z);\n }\n}\nvoid vector_map_range_stepped(float value,\n float fromMin,\n float fromMax,\n float toMin,\n float toMax,\n float steps,\n float3 v_value,\n float3 v_from_min,\n float3 v_from_max,\n float3 v_to_min,\n float3 v_to_max,\n float3 v_steps,\n float use_clamp,\n _ref(float ,result),\n _ref(float3 ,v_result))\n{\n float3 factor = safe_divide((v_value - v_from_min), (v_from_max - v_from_min));\n factor = safe_divide(floor(factor * (v_steps + 1.0f)), v_steps);\n v_result = v_to_min + factor * (v_to_max - v_to_min);\n if (use_clamp > 0.0f) {\n v_result.x = (v_to_min.x > v_to_max.x) ? clamp(v_result.x, v_to_max.x, v_to_min.x) :\n clamp(v_result.x, v_to_min.x, v_to_max.x);\n v_result.y = (v_to_min.y > v_to_max.y) ? clamp(v_result.y, v_to_max.y, v_to_min.y) :\n clamp(v_result.y, v_to_min.y, v_to_max.y);\n v_result.z = (v_to_min.z > v_to_max.z) ? clamp(v_result.z, v_to_max.z, v_to_min.z) :\n clamp(v_result.z, v_to_min.z, v_to_max.z);\n }\n}\nvoid vector_map_range_smoothstep(float value,\n float fromMin,\n float fromMax,\n float toMin,\n float toMax,\n float steps,\n float3 v_value,\n float3 v_from_min,\n float3 v_from_max,\n float3 v_to_min,\n float3 v_to_max,\n float3 v_steps,\n float use_clamp,\n _ref(float ,result),\n _ref(float3 ,v_result))\n{\n float3 factor = safe_divide((v_value - v_from_min), (v_from_max - v_from_min));\n factor = clamp(factor, 0.0f, 1.0f);\n factor = (3.0f - 2.0f * factor) * (factor * factor);\n v_result = v_to_min + factor * (v_to_max - v_to_min);\n}\nvoid vector_map_range_smootherstep(float value,\n float fromMin,\n float fromMax,\n float toMin,\n float toMax,\n float steps,\n float3 v_value,\n float3 v_from_min,\n float3 v_from_max,\n float3 v_to_min,\n float3 v_to_max,\n float3 v_steps,\n float use_clamp,\n _ref(float ,result),\n _ref(float3 ,v_result))\n{\n float3 factor = safe_divide((v_value - v_from_min), (v_from_max - v_from_min));\n factor = clamp(factor, 0.0f, 1.0f);\n factor = factor * factor * factor * (factor * (factor * 6.0f - 15.0f) + 10.0f);\n v_result = v_to_min + factor * (v_to_max - v_to_min);\n}\nvoid map_range_linear(float value,\n float fromMin,\n float fromMax,\n float toMin,\n float toMax,\n float steps,\n float3 v_value,\n float3 v_from_min,\n float3 v_from_max,\n float3 v_to_min,\n float3 v_to_max,\n float3 v_steps,\n float use_clamp,\n _ref(float ,result),\n _ref(float3 ,v_result))\n{\n if (fromMax != fromMin) {\n result = toMin + ((value - fromMin) / (fromMax - fromMin)) * (toMax - toMin);\n }\n else {\n result = 0.0f;\n }\n}\nvoid map_range_stepped(float value,\n float fromMin,\n float fromMax,\n float toMin,\n float toMax,\n float steps,\n float3 v_value,\n float3 v_from_min,\n float3 v_from_max,\n float3 v_to_min,\n float3 v_to_max,\n float3 v_steps,\n float use_clamp,\n _ref(float ,result),\n _ref(float3 ,v_result))\n{\n if (fromMax != fromMin) {\n float factor = (value - fromMin) / (fromMax - fromMin);\n factor = (steps > 0.0f) ? floor(factor * (steps + 1.0f)) / steps : 0.0f;\n result = toMin + factor * (toMax - toMin);\n }\n else {\n result = 0.0f;\n }\n}\nvoid map_range_smoothstep(float value,\n float fromMin,\n float fromMax,\n float toMin,\n float toMax,\n float steps,\n float3 v_value,\n float3 v_from_min,\n float3 v_from_max,\n float3 v_to_min,\n float3 v_to_max,\n float3 v_steps,\n float use_clamp,\n _ref(float ,result),\n _ref(float3 ,v_result))\n{\n if (fromMax != fromMin) {\n float factor = (fromMin > fromMax) ? 1.0f - smoothstep(fromMax, fromMin, value) :\n smoothstep(fromMin, fromMax, value);\n result = toMin + factor * (toMax - toMin);\n }\n else {\n result = 0.0f;\n }\n}\nvoid map_range_smootherstep(float value,\n float fromMin,\n float fromMax,\n float toMin,\n float toMax,\n float steps,\n float3 v_value,\n float3 v_from_min,\n float3 v_from_max,\n float3 v_to_min,\n float3 v_to_max,\n float3 v_steps,\n float use_clamp,\n _ref(float ,result),\n _ref(float3 ,v_result))\n{\n if (fromMax != fromMin) {\n float factor = (fromMin > fromMax) ? 1.0f - smootherstep(fromMax, fromMin, value) :\n smootherstep(fromMin, fromMax, value);\n result = toMin + factor * (toMax - toMin);\n }\n else {\n result = 0.0f;\n }\n}"
|
|
115
|
+
},
|
|
116
|
+
"gpu_shader_math_vector_safe_lib.glsl": {
|
|
117
|
+
"deps": [
|
|
118
|
+
"gpu_shader_math_constants_lib.glsl",
|
|
119
|
+
"gpu_shader_math_safe_lib.glsl"
|
|
120
|
+
],
|
|
121
|
+
"code": "float2 safe_mod(float2 a, float2 b)\n{\n return select(float2(0), mod(a, b), notEqual(b, float2(0)));\n}\nfloat3 safe_mod(float3 a, float3 b)\n{\n return select(float3(0), mod(a, b), notEqual(b, float3(0)));\n}\nfloat4 safe_mod(float4 a, float4 b)\n{\n return select(float4(0), mod(a, b), notEqual(b, float4(0)));\n}\nfloat2 safe_mod(float2 a, float b)\n{\n return (b != 0.0f) ? mod(a, float2(b)) : float2(0);\n}\nfloat3 safe_mod(float3 a, float b)\n{\n return (b != 0.0f) ? mod(a, float3(b)) : float3(0);\n}\nfloat4 safe_mod(float4 a, float b)\n{\n return (b != 0.0f) ? mod(a, float4(b)) : float4(0);\n}\nfloat2 compatible_mod(float2 a, float b)\n{\n return float2(compatible_mod(a.x, b), compatible_mod(a.y, b));\n}\nfloat3 compatible_mod(float3 a, float b)\n{\n return float3(compatible_mod(a.x, b), compatible_mod(a.y, b), compatible_mod(a.z, b));\n}\nfloat4 compatible_mod(float4 a, float b)\n{\n return float4(compatible_mod(a.x, b),\n compatible_mod(a.y, b),\n compatible_mod(a.z, b),\n compatible_mod(a.w, b));\n}\nfloat2 compatible_mod(float2 a, float2 b)\n{\n return float2(compatible_mod(a.x, b.x), compatible_mod(a.y, b.y));\n}\nfloat3 compatible_mod(float3 a, float3 b)\n{\n return float3(compatible_mod(a.x, b.x), compatible_mod(a.y, b.y), compatible_mod(a.z, b.z));\n}\nfloat4 compatible_mod(float4 a, float4 b)\n{\n return float4(compatible_mod(a.x, b.x),\n compatible_mod(a.y, b.y),\n compatible_mod(a.z, b.z),\n compatible_mod(a.w, b.w));\n}\nfloat2 safe_divide(float2 a, float2 b)\n{\n return select(float2(0), a / b, notEqual(b, float2(0)));\n}\nfloat3 safe_divide(float3 a, float3 b)\n{\n return select(float3(0), a / b, notEqual(b, float3(0)));\n}\nfloat4 safe_divide(float4 a, float4 b)\n{\n return select(float4(0), a / b, notEqual(b, float4(0)));\n}\nfloat2 safe_divide(float2 a, float b)\n{\n return (b != 0.0f) ? (a / b) : float2(0);\n}\nfloat3 safe_divide(float3 a, float b)\n{\n return (b != 0.0f) ? (a / b) : float3(0);\n}\nfloat4 safe_divide(float4 a, float b)\n{\n return (b != 0.0f) ? (a / b) : float4(0);\n}\nfloat2 safe_normalize_and_get_length(float2 vector, _ref(float ,out_length))\n{\n float length_squared = dot(vector, vector);\n constexpr float threshold = 1e-35f;\n if (length_squared > threshold) {\n out_length = sqrt(length_squared);\n return vector / out_length;\n }\n\n out_length = 0.0f;\n float2 result = float2(0.0f);\n result[0] = 1.0f;\n return result;\n}\nfloat3 safe_normalize_and_get_length(float3 vector, _ref(float ,out_length))\n{\n float length_squared = dot(vector, vector);\n constexpr float threshold = 1e-35f;\n if (length_squared > threshold) {\n out_length = sqrt(length_squared);\n return vector / out_length;\n }\n\n out_length = 0.0f;\n float3 result = float3(0.0f);\n result[0] = 1.0f;\n return result;\n}\nfloat4 safe_normalize_and_get_length(float4 vector, _ref(float ,out_length))\n{\n float length_squared = dot(vector, vector);\n constexpr float threshold = 1e-35f;\n if (length_squared > threshold) {\n out_length = sqrt(length_squared);\n return vector / out_length;\n }\n\n out_length = 0.0f;\n float4 result = float4(0.0f);\n result[0] = 1.0f;\n return result;\n}\nfloat2 safe_normalize(float2 vector)\n{\n float unused_length = 0.0f;\n return safe_normalize_and_get_length(vector, unused_length);\n}\nfloat3 safe_normalize(float3 vector)\n{\n float unused_length = 0.0f;\n return safe_normalize_and_get_length(vector, unused_length);\n}\nfloat4 safe_normalize(float4 vector)\n{\n float unused_length = 0.0f;\n return safe_normalize_and_get_length(vector, unused_length);\n}\nfloat2 normalize_fallback(float2 vector, float2 fallback)\n{\n float length_squared = dot(vector, vector);\n constexpr float threshold = 1e-35f;\n if (length_squared > threshold) {\n return vector * inversesqrt(length_squared);\n }\n\n return fallback;\n}\nfloat3 normalize_fallback(float3 vector, float3 fallback)\n{\n float length_squared = dot(vector, vector);\n constexpr float threshold = 1e-35f;\n if (length_squared > threshold) {\n return vector * inversesqrt(length_squared);\n }\n\n return fallback;\n}\nfloat4 normalize_fallback(float4 vector, float4 fallback)\n{\n float length_squared = dot(vector, vector);\n constexpr float threshold = 1e-35f;\n if (length_squared > threshold) {\n return vector * inversesqrt(length_squared);\n }\n\n return fallback;\n}\nfloat2 safe_rcp(float2 a)\n{\n return select(float2(0.0f), (1.0f / a), notEqual(a, float2(0.0f)));\n}\nfloat3 safe_rcp(float3 a)\n{\n return select(float3(0.0f), (1.0f / a), notEqual(a, float3(0.0f)));\n}\nfloat4 safe_rcp(float4 a)\n{\n return select(float4(0.0f), (1.0f / a), notEqual(a, float4(0.0f)));\n}\nfloat2 fallback_pow(float2 a, float b, float2 fallback)\n{\n return float2(fallback_pow(a.x, b, fallback.x), fallback_pow(a.y, b, fallback.y));\n}\nfloat3 fallback_pow(float3 a, float b, float3 fallback)\n{\n return float3(fallback_pow(a.x, b, fallback.x),\n fallback_pow(a.y, b, fallback.y),\n fallback_pow(a.z, b, fallback.z));\n}\nfloat4 fallback_pow(float4 a, float b, float4 fallback)\n{\n return float4(fallback_pow(a.x, b, fallback.x),\n fallback_pow(a.y, b, fallback.y),\n fallback_pow(a.z, b, fallback.z),\n fallback_pow(a.w, b, fallback.w));\n}\n\nfloat2 compatible_pow(float2 a, float2 b)\n{\n return float2(compatible_pow(a.x, b.x), compatible_pow(a.y, b.y));\n}\nfloat3 compatible_pow(float3 a, float3 b)\n{\n return float3(compatible_pow(a.x, b.x), compatible_pow(a.y, b.y), compatible_pow(a.z, b.z));\n}\nfloat4 compatible_pow(float4 a, float4 b)\n{\n return float4(compatible_pow(a.x, b.x),\n compatible_pow(a.y, b.y),\n compatible_pow(a.z, b.z),\n compatible_pow(a.w, b.w));\n}\nfloat2 wrap(float2 a, float2 b, float2 c)\n{\n return float2(wrap(a.x, b.x, c.x), wrap(a.y, b.y, c.y));\n}\nfloat3 wrap(float3 a, float3 b, float3 c)\n{\n return float3(wrap(a.x, b.x, c.x), wrap(a.y, b.y, c.y), wrap(a.z, b.z, c.z));\n}\nfloat4 wrap(float4 a, float4 b, float4 c)\n{\n return float4(\n wrap(a.x, b.x, c.x), wrap(a.y, b.y, c.y), wrap(a.z, b.z, c.z), wrap(a.w, b.w, c.w));\n}"
|
|
122
|
+
},
|
|
123
|
+
"gpu_shader_material_mapping.glsl": {
|
|
124
|
+
"deps": [
|
|
125
|
+
"gpu_shader_math_constants_lib.glsl",
|
|
126
|
+
"gpu_shader_math_euler_lib.glsl",
|
|
127
|
+
"gpu_shader_math_matrix_construct_lib.glsl",
|
|
128
|
+
"gpu_shader_math_vector_safe_lib.glsl"
|
|
129
|
+
],
|
|
130
|
+
"code": "void mapping_mat4(float3 vec,\n float4 m0,\n float4 m1,\n float4 m2,\n float4 m3,\n float3 minvec,\n float3 maxvec,\n _ref(float3 ,outvec))\n{\n float4x4 mat = float4x4(m0, m1, m2, m3);\n outvec = (mat * float4(vec, 1.0f)).xyz;\n outvec = clamp(outvec, minvec, maxvec);\n}\nvoid mapping_point(float3 vector, float3 location, float3 rotation, float3 scale, _ref(float3 ,result))\n{\n result = (from_rotation(EulerXYZ_from_float3(rotation)) * (vector * scale)) + location;\n}\nvoid mapping_texture(float3 vector, float3 location, float3 rotation, float3 scale, _ref(float3 ,result))\n{\n result = safe_divide(\n transpose(from_rotation(EulerXYZ_from_float3(rotation))) * (vector - location), scale);\n}\nvoid mapping_vector(float3 vector, float3 location, float3 rotation, float3 scale, _ref(float3 ,result))\n{\n result = from_rotation(EulerXYZ_from_float3(rotation)) * (vector * scale);\n}\nvoid mapping_normal(float3 vector, float3 location, float3 rotation, float3 scale, _ref(float3 ,result))\n{\n result = normalize(from_rotation(EulerXYZ_from_float3(rotation)) * safe_divide(vector, scale));\n}"
|
|
131
|
+
},
|
|
132
|
+
"gpu_shader_math_euler_lib.glsl": {
|
|
133
|
+
"deps": [
|
|
134
|
+
"gpu_shader_math_constants_lib.glsl"
|
|
135
|
+
],
|
|
136
|
+
"code": "struct EulerXYZ {\n float x;float y;float z;\n};\n\n#ifndef GPU_METAL\nEulerXYZ EulerXYZ_ctor_();\nEulerXYZ EulerXYZ_from_float3(float3 eul);\nEulerXYZ EulerXYZ_identity();\nfloat3 _as_float3(const EulerXYZ this_);\n#endif\n EulerXYZ EulerXYZ_ctor_() {EulerXYZ r;r.x=0.0f;r.y=0.0f;r.z=0.0f;return r;}\n EulerXYZ EulerXYZ_from_float3(float3 eul)\n {\n return _ctor(EulerXYZ) eul.x, eul.y, eul.z _rotc() ;\n }\n EulerXYZ EulerXYZ_identity()\n {\n return _ctor(EulerXYZ) 0.0f, 0.0f, 0.0f _rotc() ;\n }\n float3 _as_float3(const EulerXYZ this_)\n {\n return float3(this_.x, this_.y, this_.z);\n }"
|
|
137
|
+
},
|
|
138
|
+
"gpu_shader_math_matrix_construct_lib.glsl": {
|
|
139
|
+
"deps": [
|
|
140
|
+
"gpu_shader_math_constants_lib.glsl",
|
|
141
|
+
"gpu_shader_math_angle_lib.glsl",
|
|
142
|
+
"gpu_shader_math_axis_angle_lib.glsl",
|
|
143
|
+
"gpu_shader_math_base_lib.glsl",
|
|
144
|
+
"gpu_shader_math_euler_lib.glsl",
|
|
145
|
+
"gpu_shader_math_quaternion_lib.glsl"
|
|
146
|
+
],
|
|
147
|
+
"code": "float2x2 mat2x2_diagonal(float v)\n{\n return float2x2(float2(v, 0.0f), float2(0.0f, v));\n}\nfloat3x3 mat3x3_diagonal(float v)\n{\n return float3x3(float3(v, 0.0f, 0.0f), float3(0.0f, v, 0.0f), float3(0.0f, 0.0f, v));\n}\nfloat4x4 mat4x4_diagonal(float v)\n{\n return float4x4(float4(v, 0.0f, 0.0f, 0.0f),\n float4(0.0f, v, 0.0f, 0.0f),\n float4(0.0f, 0.0f, v, 0.0f),\n float4(0.0f, 0.0f, 0.0f, v));\n}\n\nfloat2x2 mat2x2_all(float v)\n{\n return float2x2(float2(v), float2(v));\n}\nfloat3x3 mat3x3_all(float v)\n{\n return float3x3(float3(v), float3(v), float3(v));\n}\nfloat4x4 mat4x4_all(float v)\n{\n return float4x4(float4(v), float4(v), float4(v), float4(v));\n}\n\nfloat2x2 mat2x2_zero()\n{\n return mat2x2_all(0.0f);\n}\nfloat3x3 mat3x3_zero()\n{\n return mat3x3_all(0.0f);\n}\nfloat4x4 mat4x4_zero()\n{\n return mat4x4_all(0.0f);\n}\n\nfloat2x2 mat2x2_identity()\n{\n return mat2x2_diagonal(1.0f);\n}\nfloat3x3 mat3x3_identity()\n{\n return mat3x3_diagonal(1.0f);\n}\nfloat4x4 mat4x4_identity()\n{\n return mat4x4_diagonal(1.0f);\n}\nfloat4x4 from_location(float3 location)\n{\n float4x4 ret = float4x4(1.0f);\n ret[3].xyz = location;\n return ret;\n}\nfloat2x2 from_scale(float2 scale)\n{\n float2x2 ret = float2x2(0.0f);\n ret[0][0] = scale[0];\n ret[1][1] = scale[1];\n return ret;\n}\nfloat3x3 from_scale(float3 scale)\n{\n float3x3 ret = float3x3(0.0f);\n ret[0][0] = scale[0];\n ret[1][1] = scale[1];\n ret[2][2] = scale[2];\n return ret;\n}\nfloat4x4 from_scale(float4 scale)\n{\n float4x4 ret = float4x4(0.0f);\n ret[0][0] = scale[0];\n ret[1][1] = scale[1];\n ret[2][2] = scale[2];\n ret[3][3] = scale[3];\n return ret;\n}\nfloat2x2 from_rotation(AngleRadian rotation)\n{\n float c = cos(rotation.angle);\n float s = sin(rotation.angle);\n return float2x2(c, -s, s, c);\n}\nfloat3x3 from_rotation(EulerXYZ rotation)\n{\n float ci = cos(rotation.x);\n float cj = cos(rotation.y);\n float ch = cos(rotation.z);\n float si = sin(rotation.x);\n float sj = sin(rotation.y);\n float sh = sin(rotation.z);\n float cc = ci * ch;\n float cs = ci * sh;\n float sc = si * ch;\n float ss = si * sh;\n\n float3x3 mat;\n mat[0][0] = cj * ch;\n mat[1][0] = sj * sc - cs;\n mat[2][0] = sj * cc + ss;\n\n mat[0][1] = cj * sh;\n mat[1][1] = sj * ss + cc;\n mat[2][1] = sj * cs - sc;\n\n mat[0][2] = -sj;\n mat[1][2] = cj * si;\n mat[2][2] = cj * ci;\n return mat;\n}\nfloat3x3 from_rotation(Quaternion rotation)\n{\n\n float q0 = M_SQRT2 * float(rotation.x);\n float q1 = M_SQRT2 * float(rotation.y);\n float q2 = M_SQRT2 * float(rotation.z);\n float q3 = M_SQRT2 * float(rotation.w);\n\n float qda = q0 * q1;\n float qdb = q0 * q2;\n float qdc = q0 * q3;\n float qaa = q1 * q1;\n float qab = q1 * q2;\n float qac = q1 * q3;\n float qbb = q2 * q2;\n float qbc = q2 * q3;\n float qcc = q3 * q3;\n\n float3x3 mat;\n mat[0][0] = float(1.0f - qbb - qcc);\n mat[0][1] = float(qdc + qab);\n mat[0][2] = float(-qdb + qac);\n\n mat[1][0] = float(-qdc + qab);\n mat[1][1] = float(1.0f - qaa - qcc);\n mat[1][2] = float(qda + qbc);\n\n mat[2][0] = float(qdb + qac);\n mat[2][1] = float(-qda + qbc);\n mat[2][2] = float(1.0f - qaa - qbb);\n return mat;\n}\nfloat3x3 from_rotation(AxisAngle rotation)\n{\n float angle_sin = sin(rotation.angle);\n float angle_cos = cos(rotation.angle);\n float3 axis = rotation.axis;\n\n float ico = (float(1) - angle_cos);\n float3 nsi = axis * angle_sin;\n\n float3 n012 = (axis * axis) * ico;\n float n_01 = (axis[0] * axis[1]) * ico;\n float n_02 = (axis[0] * axis[2]) * ico;\n float n_12 = (axis[1] * axis[2]) * ico;\n\n float3x3 mat = from_scale(n012 + angle_cos);\n mat[0][1] = n_01 + nsi[2];\n mat[0][2] = n_02 - nsi[1];\n mat[1][0] = n_01 - nsi[2];\n mat[1][2] = n_12 + nsi[0];\n mat[2][0] = n_02 + nsi[1];\n mat[2][1] = n_12 - nsi[0];\n return mat;\n}\nfloat3x3 from_rot_scale(EulerXYZ rotation, float3 scale)\n{\n return from_rotation(rotation) * from_scale(scale);\n}\nfloat3x3 from_rot_scale(Quaternion rotation, float3 scale)\n{\n return from_rotation(rotation) * from_scale(scale);\n}\nfloat3x3 from_rot_scale(AxisAngle rotation, float3 scale)\n{\n return from_rotation(rotation) * from_scale(scale);\n}\nfloat4x4 from_loc_rot(float3 location, EulerXYZ rotation)\n{\n float4x4 ret = to_float4x4(from_rotation(rotation));\n ret[3].xyz = location;\n return ret;\n}\nfloat4x4 from_loc_rot(float3 location, Quaternion rotation)\n{\n float4x4 ret = to_float4x4(from_rotation(rotation));\n ret[3].xyz = location;\n return ret;\n}\nfloat4x4 from_loc_rot(float3 location, AxisAngle rotation)\n{\n float4x4 ret = to_float4x4(from_rotation(rotation));\n ret[3].xyz = location;\n return ret;\n}\nfloat4x4 from_loc_rot_scale(float3 location, EulerXYZ rotation, float3 scale)\n{\n float4x4 ret = to_float4x4(from_rot_scale(rotation, scale));\n ret[3].xyz = location;\n return ret;\n}\nfloat4x4 from_loc_rot_scale(float3 location, Quaternion rotation, float3 scale)\n{\n float4x4 ret = to_float4x4(from_rot_scale(rotation, scale));\n ret[3].xyz = location;\n return ret;\n}\nfloat4x4 from_loc_rot_scale(float3 location, AxisAngle rotation, float3 scale)\n{\n float4x4 ret = to_float4x4(from_rot_scale(rotation, scale));\n ret[3].xyz = location;\n return ret;\n}\nfloat2x2 from_direction(float2 direction)\n{\n float cos_angle = direction.x;\n float sin_angle = direction.y;\n return float2x2(cos_angle, sin_angle, -sin_angle, cos_angle);\n}\nfloat3x3 from_up_axis(float3 up)\n{\n\n float z_sign = up.z >= 0.0f ? 1.0f : -1.0f;\n float a = -1.0f / (z_sign + up.z);\n float b = up.x * up.y * a;\n\n float3x3 basis;\n basis[0] = float3(1.0f + z_sign * square(up.x) * a, z_sign * b, -z_sign * up.x);\n basis[1] = float3(b, z_sign + square(up.y) * a, -up.y);\n basis[2] = up;\n return basis;\n}"
|
|
148
|
+
},
|
|
149
|
+
"gpu_shader_math_angle_lib.glsl": {
|
|
150
|
+
"deps": [
|
|
151
|
+
"gpu_shader_math_constants_lib.glsl"
|
|
152
|
+
],
|
|
153
|
+
"code": "struct AngleRadian {\n\n float angle;\n};\n\n#ifndef GPU_METAL\nAngleRadian AngleRadian_ctor_();\nAngleRadian AngleRadian_identity();\nAngleRadian AngleRadian_from_degree(float angle_degree);\n#endif\n AngleRadian AngleRadian_ctor_() {AngleRadian r;r.angle=0.0f;return r;}\n AngleRadian AngleRadian_identity()\n {\n return _ctor(AngleRadian) 0.0f _rotc() ;\n }\n AngleRadian AngleRadian_from_degree(float angle_degree)\n {\n return _ctor(AngleRadian) angle_degree * (M_PI / 180.0f) _rotc() ;\n }"
|
|
154
|
+
},
|
|
155
|
+
"gpu_shader_math_axis_angle_lib.glsl": {
|
|
156
|
+
"deps": [
|
|
157
|
+
"gpu_shader_math_constants_lib.glsl"
|
|
158
|
+
],
|
|
159
|
+
"code": "struct AxisAngle {\n float3 axis;\n float angle;\n};\n\n#ifndef GPU_METAL\nAxisAngle AxisAngle_ctor_();\nAxisAngle AxisAngle_identity();\n#endif\n AxisAngle AxisAngle_ctor_() {AxisAngle r;r.axis=float3(0);r.angle=0.0f;return r;}\n AxisAngle AxisAngle_identity()\n {\n return _ctor(AxisAngle) float3(0, 1, 0), 0.0f _rotc() ;\n }"
|
|
160
|
+
},
|
|
161
|
+
"gpu_shader_math_quaternion_lib.glsl": {
|
|
162
|
+
"deps": [
|
|
163
|
+
"gpu_shader_math_constants_lib.glsl"
|
|
164
|
+
],
|
|
165
|
+
"code": "struct Quaternion {\n float x;float y;float z;float w;\n};\n#ifndef GPU_METAL\nQuaternion Quaternion_ctor_();\nQuaternion Quaternion_identity();\nfloat4 _as_float4(const Quaternion this_);\n#endif\n Quaternion Quaternion_ctor_() {Quaternion r;r.x=0.0f;r.y=0.0f;r.z=0.0f;r.w=0.0f;return r;}\n Quaternion Quaternion_identity()\n {\n return _ctor(Quaternion) 1.0f, 0.0f, 0.0f, 0.0f _rotc() ;\n }\n float4 _as_float4(const Quaternion this_)\n {\n return float4(this_.x, this_.y, this_.z, this_.w);\n }\nQuaternion math_quaternion_multiply(Quaternion a, Quaternion b)\n{\n Quaternion result;\n result.x = a.x * b.x - a.y * b.y - a.z * b.z - a.w * b.w;\n result.y = a.x * b.y + a.y * b.x + a.z * b.w - a.w * b.z;\n result.z = a.x * b.z - a.y * b.w + a.z * b.x + a.w * b.y;\n result.w = a.x * b.w + a.y * b.z - a.z * b.y + a.w * b.x;\n return result;\n}\n\nQuaternion quaternion_conjugate(Quaternion q)\n{\n return _ctor(Quaternion) q.x, -q.y, -q.z, -q.w _rotc() ;\n}\n\nfloat3 transform_point_by_quaternion(Quaternion q, float3 v)\n{\n Quaternion v_quat = _ctor(Quaternion) 0.0f, v.x, v.y, v.z _rotc() ;\n Quaternion result = math_quaternion_multiply(math_quaternion_multiply(q, v_quat),\n quaternion_conjugate(q));\n return float3(result.y, result.z, result.w);\n}"
|
|
166
|
+
},
|
|
167
|
+
"gpu_shader_material_mix_color.glsl": {
|
|
168
|
+
"deps": [
|
|
169
|
+
"gpu_shader_math_constants_lib.glsl",
|
|
170
|
+
"gpu_shader_common_color_utils.glsl",
|
|
171
|
+
"gpu_shader_math_rotation_lib.glsl"
|
|
172
|
+
],
|
|
173
|
+
"code": "void node_mix_blend(float fac, float4 col1, float4 col2, _ref(float4 ,outcol))\n{\n outcol = mix(col1, col2, fac);\n}\nvoid node_mix_add(float fac, float4 col1, float4 col2, _ref(float4 ,outcol))\n{\n\n outcol = mix(col1, col1 + col2, fac);\n outcol.a = col1.a;\n}\nvoid node_mix_mult(float fac, float4 col1, float4 col2, _ref(float4 ,outcol))\n{\n\n outcol = mix(col1, col1 * col2, fac);\n outcol.a = col1.a;\n}\nvoid node_mix_screen(float fac, float4 col1, float4 col2, _ref(float4 ,outcol))\n{\n\n float facm = 1.0f - fac;\n\n outcol = float4(1.0f) - (float4(facm) + fac * (float4(1.0f) - col2)) * (float4(1.0f) - col1);\n outcol.a = col1.a;\n}\nvoid node_mix_overlay(float fac, float4 col1, float4 col2, _ref(float4 ,outcol))\n{\n\n float facm = 1.0f - fac;\n\n outcol = col1;\n\n if (outcol.r < 0.5f) {\n outcol.r *= facm + 2.0f * fac * col2.r;\n }\n else {\n outcol.r = 1.0f - (facm + 2.0f * fac * (1.0f - col2.r)) * (1.0f - outcol.r);\n }\n\n if (outcol.g < 0.5f) {\n outcol.g *= facm + 2.0f * fac * col2.g;\n }\n else {\n outcol.g = 1.0f - (facm + 2.0f * fac * (1.0f - col2.g)) * (1.0f - outcol.g);\n }\n\n if (outcol.b < 0.5f) {\n outcol.b *= facm + 2.0f * fac * col2.b;\n }\n else {\n outcol.b = 1.0f - (facm + 2.0f * fac * (1.0f - col2.b)) * (1.0f - outcol.b);\n }\n}\nvoid node_mix_sub(float fac, float4 col1, float4 col2, _ref(float4 ,outcol))\n{\n\n outcol = mix(col1, col1 - col2, fac);\n outcol.a = col1.a;\n}\nvoid node_mix_div_fallback(float fac, float4 col1, float4 col2, _ref(float4 ,outcol))\n{\n\n float facm = 1.0f - fac;\n\n outcol = col1;\n\n if (col2.r != 0.0f) {\n outcol.r = facm * outcol.r + fac * outcol.r / col2.r;\n }\n if (col2.g != 0.0f) {\n outcol.g = facm * outcol.g + fac * outcol.g / col2.g;\n }\n if (col2.b != 0.0f) {\n outcol.b = facm * outcol.b + fac * outcol.b / col2.b;\n }\n}\nvoid node_mix_diff(float fac, float4 col1, float4 col2, _ref(float4 ,outcol))\n{\n\n outcol = mix(col1, abs(col1 - col2), fac);\n outcol.a = col1.a;\n}\nvoid node_mix_exclusion(float fac, float4 col1, float4 col2, _ref(float4 ,outcol))\n{\n\n outcol = max(mix(col1, col1 + col2 - 2.0f * col1 * col2, fac), 0.0f);\n outcol.a = col1.a;\n}\nvoid node_mix_dark(float fac, float4 col1, float4 col2, _ref(float4 ,outcol))\n{\n\n outcol.rgb = mix(col1.rgb, min(col1.rgb, col2.rgb), fac);\n outcol.a = col1.a;\n}\nvoid node_mix_light(float fac, float4 col1, float4 col2, _ref(float4 ,outcol))\n{\n outcol.rgb = mix(col1.rgb, max(col1.rgb, col2.rgb), fac);\n outcol.a = col1.a;\n}\nvoid node_mix_dodge(float fac, float4 col1, float4 col2, _ref(float4 ,outcol))\n{\n outcol = col1;\n\n if (outcol.r != 0.0f) {\n float tmp = 1.0f - fac * col2.r;\n if (tmp <= 0.0f) {\n outcol.r = 1.0f;\n }\n else if ((tmp = outcol.r / tmp) > 1.0f) {\n outcol.r = 1.0f;\n }\n else {\n outcol.r = tmp;\n }\n }\n if (outcol.g != 0.0f) {\n float tmp = 1.0f - fac * col2.g;\n if (tmp <= 0.0f) {\n outcol.g = 1.0f;\n }\n else if ((tmp = outcol.g / tmp) > 1.0f) {\n outcol.g = 1.0f;\n }\n else {\n outcol.g = tmp;\n }\n }\n if (outcol.b != 0.0f) {\n float tmp = 1.0f - fac * col2.b;\n if (tmp <= 0.0f) {\n outcol.b = 1.0f;\n }\n else if ((tmp = outcol.b / tmp) > 1.0f) {\n outcol.b = 1.0f;\n }\n else {\n outcol.b = tmp;\n }\n }\n}\nvoid node_mix_burn(float fac, float4 col1, float4 col2, _ref(float4 ,outcol))\n{\n\n float tmp, facm = 1.0f - fac;\n\n outcol = col1;\n\n tmp = facm + fac * col2.r;\n if (tmp <= 0.0f) {\n outcol.r = 0.0f;\n }\n else if ((tmp = (1.0f - (1.0f - outcol.r) / tmp)) < 0.0f) {\n outcol.r = 0.0f;\n }\n else if (tmp > 1.0f) {\n outcol.r = 1.0f;\n }\n else {\n outcol.r = tmp;\n }\n\n tmp = facm + fac * col2.g;\n if (tmp <= 0.0f) {\n outcol.g = 0.0f;\n }\n else if ((tmp = (1.0f - (1.0f - outcol.g) / tmp)) < 0.0f) {\n outcol.g = 0.0f;\n }\n else if (tmp > 1.0f) {\n outcol.g = 1.0f;\n }\n else {\n outcol.g = tmp;\n }\n\n tmp = facm + fac * col2.b;\n if (tmp <= 0.0f) {\n outcol.b = 0.0f;\n }\n else if ((tmp = (1.0f - (1.0f - outcol.b) / tmp)) < 0.0f) {\n outcol.b = 0.0f;\n }\n else if (tmp > 1.0f) {\n outcol.b = 1.0f;\n }\n else {\n outcol.b = tmp;\n }\n}\nvoid node_mix_hue(float fac, float4 col1, float4 col2, _ref(float4 ,outcol))\n{\n\n outcol = col1;\n\n float4 hsv, hsv2, tmp;\n rgb_to_hsv(col2, hsv2);\n\n if (hsv2.y != 0.0f) {\n rgb_to_hsv(outcol, hsv);\n hsv.x = hsv2.x;\n hsv_to_rgb(hsv, tmp);\n\n outcol = mix(outcol, tmp, fac);\n outcol.a = col1.a;\n }\n}\nvoid node_mix_sat(float fac, float4 col1, float4 col2, _ref(float4 ,outcol))\n{\n\n outcol = col1;\n\n float4 hsv, hsv2;\n rgb_to_hsv(outcol, hsv);\n\n if (hsv.y != 0.0f) {\n rgb_to_hsv(col2, hsv2);\n\n hsv.y = (1.0f - fac) * hsv.y + fac * hsv2.y;\n hsv_to_rgb(hsv, outcol);\n }\n}\nvoid node_mix_val(float fac, float4 col1, float4 col2, _ref(float4 ,outcol))\n{\n\n float4 hsv, hsv2;\n rgb_to_hsv(col1, hsv);\n rgb_to_hsv(col2, hsv2);\n\n hsv.z = (1.0f - fac) * hsv.z + fac * hsv2.z;\n hsv_to_rgb(hsv, outcol);\n}\nvoid node_mix_color(float fac, float4 col1, float4 col2, _ref(float4 ,outcol))\n{\n outcol = col1;\n\n float4 hsv, hsv2, tmp;\n rgb_to_hsv(col2, hsv2);\n\n if (hsv2.y != 0.0f) {\n rgb_to_hsv(outcol, hsv);\n hsv.x = hsv2.x;\n hsv.y = hsv2.y;\n hsv_to_rgb(hsv, tmp);\n\n outcol = mix(outcol, tmp, fac);\n outcol.a = col1.a;\n }\n}\nvoid node_mix_soft(float fac, float4 col1, float4 col2, _ref(float4 ,outcol))\n{\n\n float facm = 1.0f - fac;\n\n float4 one = float4(1.0f);\n float4 scr = one - (one - col2) * (one - col1);\n outcol = facm * col1 + fac * ((one - col1) * col2 * col1 + col1 * scr);\n outcol.a = col1.a;\n}\nvoid node_mix_linear(float fac, float4 col1, float4 col2, _ref(float4 ,outcol))\n{\n\n outcol = col1 + fac * (2.0f * (col2 - float4(0.5f)));\n outcol.a = col1.a;\n}\nvoid node_mix_float(float fac, float f1, float f2, _ref(float ,outfloat))\n{\n\n outfloat = f1 * (1.0f - fac) + f2 * fac;\n}\nvoid node_mix_vector(float fac, float3 v1, float3 v2, _ref(float3 ,outvec))\n{\n\n outvec = v1 * (1.0f - fac) + v2 * fac;\n}\nvoid node_mix_vector_non_uniform(float3 facvec, float3 v1, float3 v2, _ref(float3 ,outvec))\n{\n\n outvec = v1 * (float3(1.0f) - facvec) + v2 * facvec;\n}\nvoid node_mix_rgba(float fac, float4 col1, float4 col2, _ref(float4 ,outcol))\n{\n outcol = mix(col1, col2, fac);\n}\nvoid node_mix_clamp_color(float4 col, float4 min, float4 max, _ref(float4 ,out_col))\n{\n out_col = clamp(col, min, max);\n}\nvoid node_mix_clamp_vector(float3 vec, float3 min, float3 max, _ref(float3 ,outvec))\n{\n outvec = clamp(vec, min, max);\n}\nvoid node_mix_clamp_value(float value, float min, float max, _ref(float ,outfloat))\n{\n outfloat = clamp(value, min, max);\n}\nvoid node_mix_rotation(float fac, float4 rot1, float4 rot2, _ref(float4 ,outrot))\n{\n outrot = _as_float4(interpolate(_ctor(Quaternion) UNPACK4(rot1) _rotc() , _ctor(Quaternion) UNPACK4(rot2) _rotc() , fac));\n}"
|
|
174
|
+
},
|
|
175
|
+
"gpu_shader_math_rotation_lib.glsl": {
|
|
176
|
+
"deps": [
|
|
177
|
+
"gpu_shader_math_constants_lib.glsl",
|
|
178
|
+
"gpu_shader_math_axis_angle_lib.glsl",
|
|
179
|
+
"gpu_shader_math_euler_lib.glsl",
|
|
180
|
+
"gpu_shader_math_matrix_construct_lib.glsl",
|
|
181
|
+
"gpu_shader_math_quaternion_lib.glsl",
|
|
182
|
+
"gpu_shader_utildefines_lib.glsl"
|
|
183
|
+
],
|
|
184
|
+
"code": "float2 interpolate_dot_slerp(float t, float cosom)\n{\n float2 w = float2(1.0f - t, t);\n\n constexpr float eps = 1e-4f;\n if (abs(cosom) < 1.0f - eps) {\n float omega = acos(cosom);\n w = sin(w * omega) / sin(omega);\n }\n return w;\n}\n\nQuaternion interpolate(Quaternion a, Quaternion b, float t)\n{\n float4 quat = _as_float4(a);\n float cosom = dot(_as_float4(a), _as_float4(b));\n\n if (cosom < 0.0f) {\n cosom = -cosom;\n quat = -quat;\n }\n float2 w = interpolate_dot_slerp(t, cosom);\n quat = w.x * quat + w.y * _as_float4(b);\n return _ctor(Quaternion) UNPACK4(quat) _rotc() ;\n}\nfloat3x3 rotate(float3x3 mat, AxisAngle rotation)\n{\n float3x3 result;\n\n if (rotation.axis.x == 1.0f) {\n float angle_cos = cos(rotation.angle);\n float angle_sin = sin(rotation.angle);\n for (int c = 0; c < 3; c++) {\n result[0][c] = mat[0][c];\n result[1][c] = angle_cos * mat[1][c] + angle_sin * mat[2][c];\n result[2][c] = -angle_sin * mat[1][c] + angle_cos * mat[2][c];\n }\n }\n else if (rotation.axis.y == 1.0f) {\n float angle_cos = cos(rotation.angle);\n float angle_sin = sin(rotation.angle);\n for (int c = 0; c < 3; c++) {\n result[0][c] = angle_cos * mat[0][c] - angle_sin * mat[2][c];\n result[1][c] = mat[1][c];\n result[2][c] = angle_sin * mat[0][c] + angle_cos * mat[2][c];\n }\n }\n else if (rotation.axis.z == 1.0f) {\n float angle_cos = cos(rotation.angle);\n float angle_sin = sin(rotation.angle);\n for (int c = 0; c < 3; c++) {\n result[0][c] = angle_cos * mat[0][c] + angle_sin * mat[1][c];\n result[1][c] = -angle_sin * mat[0][c] + angle_cos * mat[1][c];\n result[2][c] = mat[2][c];\n }\n }\n else {\n\n result = mat * from_rotation(rotation);\n }\n return result;\n}\nfloat3x3 rotate(float3x3 mat, EulerXYZ rotation)\n{\n AxisAngle axis_angle;\n if (rotation.y == 0.0f && rotation.z == 0.0f) {\n axis_angle = _ctor(AxisAngle) float3(1.0f, 0.0f, 0.0f), rotation.x _rotc() ;\n }\n else if (rotation.x == 0.0f && rotation.z == 0.0f) {\n axis_angle = _ctor(AxisAngle) float3(0.0f, 1.0f, 0.0f), rotation.y _rotc() ;\n }\n else if (rotation.x == 0.0f && rotation.y == 0.0f) {\n axis_angle = _ctor(AxisAngle) float3(0.0f, 0.0f, 1.0f), rotation.z _rotc() ;\n }\n else {\n\n return mat * from_rotation(rotation);\n }\n return rotate(mat, axis_angle);\n}\nfloat4x4 rotate(float4x4 mat, AxisAngle rotation)\n{\n float4x4 result = to_float4x4(rotate(to_float3x3(mat), rotation));\n result[0][3] = mat[0][3];\n result[1][3] = mat[1][3];\n result[2][3] = mat[2][3];\n result[3][0] = mat[3][0];\n result[3][1] = mat[3][1];\n result[3][2] = mat[3][2];\n result[3][3] = mat[3][3];\n return result;\n}\nfloat4x4 rotate(float4x4 mat, EulerXYZ rotation)\n{\n float4x4 result = to_float4x4(rotate(to_float3x3(mat), rotation));\n result[0][3] = mat[0][3];\n result[1][3] = mat[1][3];\n result[2][3] = mat[2][3];\n result[3][0] = mat[3][0];\n result[3][1] = mat[3][1];\n result[3][2] = mat[3][2];\n result[3][3] = mat[3][3];\n return result;\n}"
|
|
185
|
+
},
|
|
186
|
+
"gpu_shader_utildefines_lib.glsl": {
|
|
187
|
+
"deps": [
|
|
188
|
+
"gpu_shader_math_constants_lib.glsl"
|
|
189
|
+
],
|
|
190
|
+
"code": "#ifndef FLT_MAX\n# define FLT_MAX uintBitsToFloat(0x7F7FFFFFu)\n# define FLT_MIN uintBitsToFloat(0x00800000u)\n# define FLT_EPSILON 1.192092896e-07F\n#endif\n#ifndef SHRT_MAX\n# define SHRT_MAX 0x00007FFF\n# define INT_MAX 0x7FFFFFFF\n# define USHRT_MAX 0x0000FFFFu\n# define UINT_MAX 0xFFFFFFFFu\n#endif\n#define NAN_FLT uintBitsToFloat(0x7FC00000u)\n#define FLT_11_MAX uintBitsToFloat(0x477E0000)\n#define FLT_10_MAX uintBitsToFloat(0x477C0000)\n#define FLT_11_11_10_MAX float3(FLT_11_MAX, FLT_11_MAX, FLT_10_MAX)\n\n#define UNPACK2(a) (a)[0], (a)[1]\n#define UNPACK3(a) (a)[0], (a)[1], (a)[2]\n#define UNPACK4(a) (a)[0], (a)[1], (a)[2], (a)[3]\n#define saturate(a) clamp(a, 0.0f, 1.0f)\n\n#define isfinite(a) (!isinf(a) && !isnan(a))\n#define in_range_inclusive(val, min_v, max_v) (all(greaterThanEqual(val, min_v)) && all(lessThanEqual(val, max_v)))\n#define in_range_exclusive(val, min_v, max_v) (all(greaterThan(val, min_v)) && all(lessThan(val, max_v)))\n#define in_texture_range(texel, tex) (all(greaterThanEqual(texel, int2(0))) && all(lessThan(texel, textureSize(tex, 0).xy)))\n#define in_image_range(texel, tex) (all(greaterThanEqual(texel, int2(0))) && all(lessThan(texel, imageSize(tex).xy)))\n\n#define weighted_sum(val0, val1, val2, val3, weights) ((val0 * weights[0] + val1 * weights[1] + val2 * weights[2] + val3 * weights[3]) * safe_rcp(weights[0] + weights[1] + weights[2] + weights[3]))\n#define weighted_sum_array(val, weights) ((val[0] * weights[0] + val[1] * weights[1] + val[2] * weights[2] + val[3] * weights[3]) * safe_rcp(weights[0] + weights[1] + weights[2] + weights[3]))\nbool flag_test(uint flag, uint val)\n{\n return (flag & val) != 0u;\n}\nbool flag_test(int flag, uint val)\n{\n return flag_test(uint(flag), val);\n}\nbool flag_test(int flag, int val)\n{\n return (flag & val) != 0;\n}\n\nvoid set_flag_from_test(_ref(uint ,value), bool test, uint flag)\n{\n if (test) {\n value |= flag;\n }\n else {\n value &= ~flag;\n }\n}\nvoid set_flag_from_test(_ref(int ,value), bool test, int flag)\n{\n if (test) {\n value |= flag;\n }\n else {\n value &= ~flag;\n }\n}\n#define SET_FLAG_FROM_TEST(value, test, flag) set_flag_from_test(value, test, flag)\nbool bitmask64_test(uint2 bitmask, uint bit_index)\n{\n uint bitmask32 = (bit_index >= 32u) ? bitmask.y : bitmask.x;\n return flag_test(bitmask32, 1u << (bit_index & 0x1Fu));\n}\nuint packUvec2x16(uint2 a)\n{\n a = (a & 0xFFFFu) << uint2(0u, 16u);\n return a.x | a.y;\n}\nuint2 unpackUvec2x16(uint a)\n{\n return (uint2(a) >> uint2(0u, 16u)) & uint2(0xFFFFu);\n}\nuint packUvec4x8(uint4 a)\n{\n a = (a & 0xFFu) << uint4(0u, 8u, 16u, 24u);\n return a.x | a.y | a.z | a.w;\n}\nuint4 unpackUvec4x8(uint a)\n{\n return (uint4(a) >> uint4(0u, 8u, 16u, 24u)) & uint4(0xFFu);\n}\nint floatBitsToOrderedInt(float value)\n{\n int int_value = floatBitsToInt(value);\n return (int_value < 0) ? (int_value ^ 0x7FFFFFFF) : int_value;\n}\nfloat orderedIntBitsToFloat(int int_value)\n{\n return intBitsToFloat((int_value < 0) ? (int_value ^ 0x7FFFFFFF) : int_value);\n}"
|
|
191
|
+
},
|
|
192
|
+
"gpu_shader_material_rgb_to_bw.glsl": {
|
|
193
|
+
"deps": [
|
|
194
|
+
"gpu_shader_math_constants_lib.glsl"
|
|
195
|
+
],
|
|
196
|
+
"code": "void rgbtobw(float4 color, float3 luminance_coefficients, _ref(float ,outval))\n{\n outval = dot(color.rgb, luminance_coefficients);\n}"
|
|
197
|
+
},
|
|
198
|
+
"gpu_shader_material_separate_color.glsl": {
|
|
199
|
+
"deps": [
|
|
200
|
+
"gpu_shader_math_constants_lib.glsl",
|
|
201
|
+
"gpu_shader_common_color_utils.glsl"
|
|
202
|
+
],
|
|
203
|
+
"code": "void separate_color_rgb(float4 col, _ref(float ,r), _ref(float ,g), _ref(float ,b))\n{\n r = col.r;\n g = col.g;\n b = col.b;\n}\nvoid separate_color_hsv(float4 col, _ref(float ,r), _ref(float ,g), _ref(float ,b))\n{\n float4 hsv;\n\n rgb_to_hsv(col, hsv);\n r = hsv[0];\n g = hsv[1];\n b = hsv[2];\n}\nvoid separate_color_hsl(float4 col, _ref(float ,r), _ref(float ,g), _ref(float ,b))\n{\n float4 hsl;\n\n rgb_to_hsl(col, hsl);\n r = hsl[0];\n g = hsl[1];\n b = hsl[2];\n}"
|
|
204
|
+
},
|
|
205
|
+
"gpu_shader_material_separate_xyz.glsl": {
|
|
206
|
+
"deps": [
|
|
207
|
+
"gpu_shader_math_constants_lib.glsl"
|
|
208
|
+
],
|
|
209
|
+
"code": "void separate_xyz(float3 vec, _ref(float ,x), _ref(float ,y), _ref(float ,z))\n{\n x = vec.r;\n y = vec.g;\n z = vec.b;\n}"
|
|
210
|
+
},
|
|
211
|
+
"gpu_shader_material_tex_brick.glsl": {
|
|
212
|
+
"deps": [
|
|
213
|
+
"gpu_shader_math_constants_lib.glsl",
|
|
214
|
+
"gpu_shader_common_hash.glsl"
|
|
215
|
+
],
|
|
216
|
+
"code": "float2 calc_brick_texture(float3 p,\n float mortar_size,\n float mortar_smooth,\n float bias,\n float brick_width,\n float row_height,\n float offset_amount,\n int offset_frequency,\n float squash_amount,\n int squash_frequency)\n{\n int bricknum, rownum;\n float offset = 0.0f;\n float x, y;\n\n rownum = int(floor(p.y / row_height));\n\n if (offset_frequency != 0 && squash_frequency != 0) {\n brick_width *= (rownum % squash_frequency != 0) ? 1.0f : squash_amount;\n offset = (rownum % offset_frequency != 0) ? 0.0f : (brick_width * offset_amount);\n }\n\n bricknum = int(floor((p.x + offset) / brick_width));\n\n x = (p.x + offset) - brick_width * float(bricknum);\n y = p.y - row_height * float(rownum);\n\n float tint = clamp((integer_noise((rownum << 16) + (bricknum & 0xFFFF)) + bias), 0.0f, 1.0f);\n\n float min_dist = min(min(x, y), min(brick_width - x, row_height - y));\n if (min_dist >= mortar_size) {\n return float2(tint, 0.0f);\n }\n else if (mortar_smooth == 0.0f) {\n return float2(tint, 1.0f);\n }\n else {\n min_dist = 1.0f - min_dist / mortar_size;\n return float2(tint, smoothstep(0.0f, mortar_smooth, min_dist));\n }\n}\nvoid node_tex_brick(float3 co,\n float4 color1,\n float4 color2,\n float4 mortar,\n float scale,\n float mortar_size,\n float mortar_smooth,\n float bias,\n float brick_width,\n float row_height,\n float offset_amount,\n float offset_frequency,\n float squash_amount,\n float squash_frequency,\n _ref(float4 ,color),\n _ref(float ,fac))\n{\n float2 f2 = calc_brick_texture(co * scale,\n mortar_size,\n mortar_smooth,\n bias,\n brick_width,\n row_height,\n offset_amount,\n int(offset_frequency),\n squash_amount,\n int(squash_frequency));\n float tint = f2.x;\n float f = f2.y;\n if (f != 1.0f) {\n float facm = 1.0f - tint;\n color1 = facm * color1 + tint * color2;\n }\n color = mix(color1, mortar, f);\n fac = f;\n}"
|
|
217
|
+
},
|
|
218
|
+
"gpu_shader_common_hash.glsl": {
|
|
219
|
+
"deps": [
|
|
220
|
+
"gpu_shader_math_constants_lib.glsl"
|
|
221
|
+
],
|
|
222
|
+
"code": "#define rot(x, k) (((x) << (k)) | ((x) >> (32 - (k))))\n\n#define mix(a, b, c) \\\n { \\\n a -= c; \\\n a ^= rot(c, 4); \\\n c += b; \\\n b -= a; \\\n b ^= rot(a, 6); \\\n a += c; \\\n c -= b; \\\n c ^= rot(b, 8); \\\n b += a; \\\n a -= c; \\\n a ^= rot(c, 16); \\\n c += b; \\\n b -= a; \\\n b ^= rot(a, 19); \\\n a += c; \\\n c -= b; \\\n c ^= rot(b, 4); \\\n b += a; \\\n }\n\n#define final(a, b, c) \\\n { \\\n c ^= b; \\\n c -= rot(b, 14); \\\n a ^= c; \\\n a -= rot(c, 11); \\\n b ^= a; \\\n b -= rot(a, 25); \\\n c ^= b; \\\n c -= rot(b, 16); \\\n a ^= c; \\\n a -= rot(c, 4); \\\n b ^= a; \\\n b -= rot(a, 14); \\\n c ^= b; \\\n c -= rot(b, 24); \\\n }\n\nuint hash_uint(uint kx)\n{\n uint a, b, c;\n a = b = c = 0xdeadbeefu + (1u << 2u) + 13u;\n\n a += kx;\n final(a, b, c);\n\n return c;\n}\n\nuint hash_uint2(uint kx, uint ky)\n{\n uint a, b, c;\n a = b = c = 0xdeadbeefu + (2u << 2u) + 13u;\n\n b += ky;\n a += kx;\n final(a, b, c);\n\n return c;\n}\n\nuint hash_uint3(uint kx, uint ky, uint kz)\n{\n uint a, b, c;\n a = b = c = 0xdeadbeefu + (3u << 2u) + 13u;\n\n c += kz;\n b += ky;\n a += kx;\n final(a, b, c);\n\n return c;\n}\n\nuint hash_uint4(uint kx, uint ky, uint kz, uint kw)\n{\n uint a, b, c;\n a = b = c = 0xdeadbeefu + (4u << 2u) + 13u;\n\n a += kx;\n b += ky;\n c += kz;\n mix(a, b, c);\n\n a += kw;\n final(a, b, c);\n\n return c;\n}\n\n#undef rot\n#undef final\n#undef mix\n\nuint hash_int(int kx)\n{\n return hash_uint(uint(kx));\n}\n\nuint hash_int2(int kx, int ky)\n{\n return hash_uint2(uint(kx), uint(ky));\n}\n\nuint hash_int3(int kx, int ky, int kz)\n{\n return hash_uint3(uint(kx), uint(ky), uint(kz));\n}\n\nuint hash_int4(int kx, int ky, int kz, int kw)\n{\n return hash_uint4(uint(kx), uint(ky), uint(kz), uint(kw));\n}\nint2 hash_pcg2d_i(int2 v)\n{\n v = v * 1664525 + 1013904223;\n v.x += v.y * 1664525;\n v.y += v.x * 1664525;\n v = v ^ (v >> 16);\n v.x += v.y * 1664525;\n v.y += v.x * 1664525;\n return v;\n}\n\nint3 hash_pcg3d_i(int3 v)\n{\n v = v * 1664525 + 1013904223;\n v.x += v.y * v.z;\n v.y += v.z * v.x;\n v.z += v.x * v.y;\n v = v ^ (v >> 16);\n v.x += v.y * v.z;\n v.y += v.z * v.x;\n v.z += v.x * v.y;\n return v;\n}\n\nint4 hash_pcg4d_i(int4 v)\n{\n v = v * 1664525 + 1013904223;\n v.x += v.y * v.w;\n v.y += v.z * v.x;\n v.z += v.x * v.y;\n v.w += v.y * v.z;\n v = v ^ (v >> 16);\n v.x += v.y * v.w;\n v.y += v.z * v.x;\n v.z += v.x * v.y;\n v.w += v.y * v.z;\n return v;\n}\nfloat hash_uint_to_float(uint kx)\n{\n return float(hash_uint(kx)) / float(0xFFFFFFFFu);\n}\n\nfloat hash_uint2_to_float(uint kx, uint ky)\n{\n return float(hash_uint2(kx, ky)) / float(0xFFFFFFFFu);\n}\n\nfloat hash_uint3_to_float(uint kx, uint ky, uint kz)\n{\n return float(hash_uint3(kx, ky, kz)) / float(0xFFFFFFFFu);\n}\n\nfloat hash_uint4_to_float(uint kx, uint ky, uint kz, uint kw)\n{\n return float(hash_uint4(kx, ky, kz, kw)) / float(0xFFFFFFFFu);\n}\nfloat hash_float_to_float(float k)\n{\n return hash_uint_to_float(floatBitsToUint(k));\n}\n\nfloat hash_vec2_to_float(float2 k)\n{\n return hash_uint2_to_float(floatBitsToUint(k.x), floatBitsToUint(k.y));\n}\n\nfloat hash_vec3_to_float(float3 k)\n{\n return hash_uint3_to_float(floatBitsToUint(k.x), floatBitsToUint(k.y), floatBitsToUint(k.z));\n}\n\nfloat hash_vec4_to_float(float4 k)\n{\n return hash_uint4_to_float(\n floatBitsToUint(k.x), floatBitsToUint(k.y), floatBitsToUint(k.z), floatBitsToUint(k.w));\n}\nfloat2 hash_vec2_to_vec2(float2 k)\n{\n return float2(hash_vec2_to_float(k), hash_vec3_to_float(float3(k, 1.0f)));\n}\n\nfloat3 hash_vec3_to_vec3(float3 k)\n{\n return float3(hash_vec3_to_float(k),\n hash_vec4_to_float(float4(k, 1.0f)),\n hash_vec4_to_float(float4(k, 2.0f)));\n}\n\nfloat4 hash_vec4_to_vec4(float4 k)\n{\n return float4(hash_vec4_to_float(k.xyzw),\n hash_vec4_to_float(k.wxyz),\n hash_vec4_to_float(k.zwxy),\n hash_vec4_to_float(k.yzwx));\n}\nfloat2 hash_int2_to_vec2(int2 k)\n{\n int2 h = hash_pcg2d_i(k);\n return float2(h & 0x7fffffff) * (1.0 / float(0x7fffffff));\n}\n\nfloat3 hash_int3_to_vec3(int3 k)\n{\n int3 h = hash_pcg3d_i(k);\n return float3(h & 0x7fffffff) * (1.0 / float(0x7fffffff));\n}\n\nfloat4 hash_int4_to_vec4(int4 k)\n{\n int4 h = hash_pcg4d_i(k);\n return float4(h & 0x7fffffff) * (1.0 / float(0x7fffffff));\n}\n\nfloat3 hash_int2_to_vec3(int2 k)\n{\n return hash_int3_to_vec3(int3(k.x, k.y, 0));\n}\n\nfloat3 hash_int4_to_vec3(int4 k)\n{\n return hash_int4_to_vec4(k).xyz;\n}\nfloat3 hash_float_to_vec3(float k)\n{\n return float3(hash_float_to_float(k),\n hash_vec2_to_float(float2(k, 1.0f)),\n hash_vec2_to_float(float2(k, 2.0f)));\n}\n\nfloat3 hash_vec2_to_vec3(float2 k)\n{\n return float3(hash_vec2_to_float(k),\n hash_vec3_to_float(float3(k, 1.0f)),\n hash_vec3_to_float(float3(k, 2.0f)));\n}\n\nfloat3 hash_vec4_to_vec3(float4 k)\n{\n return float3(\n hash_vec4_to_float(k.xyzw), hash_vec4_to_float(k.zxwy), hash_vec4_to_float(k.wzyx));\n}\nfloat2 hash_float_to_vec2(float k)\n{\n return float2(hash_float_to_float(k), hash_vec2_to_float(float2(k, 1.0f)));\n}\n\nfloat2 hash_vec3_to_vec2(float3 k)\n{\n return float2(hash_vec3_to_float(k.xyz), hash_vec3_to_float(k.zxy));\n}\n\nfloat2 hash_vec4_to_vec2(float4 k)\n{\n return float2(hash_vec4_to_float(k.xyzw), hash_vec4_to_float(k.zxwy));\n}\nfloat integer_noise(int n)\n{\n uint nn;\n nn = (uint(n) + 1013u) & 0x7fffffffu;\n nn = (nn >> 13u) ^ nn;\n nn = (uint(nn * (nn * nn * 60493u + 19990303u)) + 1376312589u) & 0x7fffffffu;\n return 0.5f * (float(nn) / 1073741824.0f);\n}\n\nfloat wang_hash_noise(uint s)\n{\n s = (s ^ 61u) ^ (s >> 16u);\n s *= 9u;\n s = s ^ (s >> 4u);\n s *= 0x27d4eb2du;\n s = s ^ (s >> 15u);\n\n return fract(float(s) / 4294967296.0f);\n}"
|
|
223
|
+
},
|
|
224
|
+
"gpu_shader_material_tex_checker.glsl": {
|
|
225
|
+
"deps": [
|
|
226
|
+
"gpu_shader_math_constants_lib.glsl"
|
|
227
|
+
],
|
|
228
|
+
"code": "void node_tex_checker(\n float3 co, float4 color1, float4 color2, float scale, _ref(float4 ,color), _ref(float ,fac))\n{\n float3 p = co * scale;\n p = (p + 0.000001f) * 0.999999f;\n\n int xi = int(abs(floor(p.x)));\n int yi = int(abs(floor(p.y)));\n int zi = int(abs(floor(p.z)));\n\n bool check = (((xi % 2) == (yi % 2)) == bool(zi % 2));\n\n color = check ? color1 : color2;\n fac = check ? 1.0f : 0.0f;\n}"
|
|
229
|
+
},
|
|
230
|
+
"gpu_shader_material_tex_gradient.glsl": {
|
|
231
|
+
"deps": [
|
|
232
|
+
"gpu_shader_math_constants_lib.glsl"
|
|
233
|
+
],
|
|
234
|
+
"code": "float calc_gradient(float3 p, int gradient_type)\n{\n float x, y, z;\n x = p.x;\n y = p.y;\n z = p.z;\n if (gradient_type == 0) {\n return x;\n }\n else if (gradient_type == 1) {\n float r = max(x, 0.0f);\n return r * r;\n }\n else if (gradient_type == 2) {\n float r = min(max(x, 0.0f), 1.0f);\n float t = r * r;\n return (3.0f * t - 2.0f * t * r);\n }\n else if (gradient_type == 3) {\n return (x + y) * 0.5f;\n }\n else if (gradient_type == 4) {\n return atan(y, x) / (M_PI * 2.0f) + 0.5f;\n }\n else {\n float r = max(0.999999f - sqrt(x * x + y * y + z * z), 0.0f);\n if (gradient_type == 5) {\n return r * r;\n }\n else if (gradient_type == 6) {\n return r;\n }\n }\n return 0.0f;\n}\nvoid node_tex_gradient(float3 co, float gradient_type, _ref(float4 ,color), _ref(float ,fac))\n{\n float f = calc_gradient(co, int(gradient_type));\n f = clamp(f, 0.0f, 1.0f);\n\n color = float4(f, f, f, 1.0f);\n fac = f;\n}"
|
|
235
|
+
},
|
|
236
|
+
"gpu_shader_material_tex_magic.glsl": {
|
|
237
|
+
"deps": [
|
|
238
|
+
"gpu_shader_math_constants_lib.glsl"
|
|
239
|
+
],
|
|
240
|
+
"code": "void node_tex_magic(\n float3 co, float scale, float distortion, float depth, _ref(float4 ,color), _ref(float ,fac))\n{\n float3 p = mod(co * scale, 2.0f * M_PI);\n\n float x = sin((p.x + p.y + p.z) * 5.0f);\n float y = cos((-p.x + p.y - p.z) * 5.0f);\n float z = -cos((-p.x - p.y + p.z) * 5.0f);\n\n if (depth > 0.0f) {\n x *= distortion;\n y *= distortion;\n z *= distortion;\n y = -cos(x - y + z);\n y *= distortion;\n if (depth > 1.0f) {\n x = cos(x - y - z);\n x *= distortion;\n if (depth > 2.0f) {\n z = sin(-x - y - z);\n z *= distortion;\n if (depth > 3.0f) {\n x = -cos(-x + y - z);\n x *= distortion;\n if (depth > 4.0f) {\n y = -sin(-x + y + z);\n y *= distortion;\n if (depth > 5.0f) {\n y = -cos(-x + y + z);\n y *= distortion;\n if (depth > 6.0f) {\n x = cos(x + y + z);\n x *= distortion;\n if (depth > 7.0f) {\n z = sin(x + y - z);\n z *= distortion;\n if (depth > 8.0f) {\n x = -cos(-x - y + z);\n x *= distortion;\n if (depth > 9.0f) {\n y = -sin(x - y + z);\n y *= distortion;\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n if (distortion != 0.0f) {\n distortion *= 2.0f;\n x /= distortion;\n y /= distortion;\n z /= distortion;\n }\n\n color = float4(0.5f - x, 0.5f - y, 0.5f - z, 1.0f);\n fac = (color.x + color.y + color.z) / 3.0f;\n}"
|
|
241
|
+
},
|
|
242
|
+
"gpu_shader_material_tex_noise.glsl": {
|
|
243
|
+
"deps": [
|
|
244
|
+
"gpu_shader_math_constants_lib.glsl",
|
|
245
|
+
"gpu_shader_common_hash.glsl",
|
|
246
|
+
"gpu_shader_material_fractal_noise.glsl",
|
|
247
|
+
"gpu_shader_material_noise.glsl"
|
|
248
|
+
],
|
|
249
|
+
"code": "#define NOISE_FRACTAL_DISTORTED_1D(NOISE_TYPE) \\\n if (distortion != 0.0f) { \\\n p += snoise(p + random_float_offset(0.0f)) * distortion; \\\n } \\\n value = NOISE_TYPE(p, detail, roughness, lacunarity, offset, gain, normalize != 0.0f); \\\n if (compute_color != 0.0f) { \\\n color = float4(value, \\\n NOISE_TYPE(p + random_float_offset(1.0f), \\\n detail, \\\n roughness, \\\n lacunarity, \\\n offset, \\\n gain, \\\n normalize != 0.0f), \\\n NOISE_TYPE(p + random_float_offset(2.0f), \\\n detail, \\\n roughness, \\\n lacunarity, \\\n offset, \\\n gain, \\\n normalize != 0.0f), \\\n 1.0f); \\\n }\n\n#define NOISE_FRACTAL_DISTORTED_2D(NOISE_TYPE) \\\n if (distortion != 0.0f) { \\\n p += float2(snoise(p + random_vec2_offset(0.0f)) * distortion, \\\n snoise(p + random_vec2_offset(1.0f)) * distortion); \\\n } \\\n value = NOISE_TYPE(p, detail, roughness, lacunarity, offset, gain, normalize != 0.0f); \\\n if (compute_color != 0.0f) { \\\n color = float4(value, \\\n NOISE_TYPE(p + random_vec2_offset(2.0f), \\\n detail, \\\n roughness, \\\n lacunarity, \\\n offset, \\\n gain, \\\n normalize != 0.0f), \\\n NOISE_TYPE(p + random_vec2_offset(3.0f), \\\n detail, \\\n roughness, \\\n lacunarity, \\\n offset, \\\n gain, \\\n normalize != 0.0f), \\\n 1.0f); \\\n }\n\n#define NOISE_FRACTAL_DISTORTED_3D(NOISE_TYPE) \\\n if (distortion != 0.0f) { \\\n p += float3(snoise(p + random_vec3_offset(0.0f)) * distortion, \\\n snoise(p + random_vec3_offset(1.0f)) * distortion, \\\n snoise(p + random_vec3_offset(2.0f)) * distortion); \\\n } \\\n value = NOISE_TYPE(p, detail, roughness, lacunarity, offset, gain, normalize != 0.0f); \\\n if (compute_color != 0.0f) { \\\n color = float4(value, \\\n NOISE_TYPE(p + random_vec3_offset(3.0f), \\\n detail, \\\n roughness, \\\n lacunarity, \\\n offset, \\\n gain, \\\n normalize != 0.0f), \\\n NOISE_TYPE(p + random_vec3_offset(4.0f), \\\n detail, \\\n roughness, \\\n lacunarity, \\\n offset, \\\n gain, \\\n normalize != 0.0f), \\\n 1.0f); \\\n }\n\n#define NOISE_FRACTAL_DISTORTED_4D(NOISE_TYPE) \\\n if (distortion != 0.0f) { \\\n p += float4(snoise(p + random_vec4_offset(0.0f)) * distortion, \\\n snoise(p + random_vec4_offset(1.0f)) * distortion, \\\n snoise(p + random_vec4_offset(2.0f)) * distortion, \\\n snoise(p + random_vec4_offset(3.0f)) * distortion); \\\n } \\\n value = NOISE_TYPE(p, detail, roughness, lacunarity, offset, gain, normalize != 0.0f); \\\n if (compute_color != 0.0f) { \\\n color = float4(value, \\\n NOISE_TYPE(p + random_vec4_offset(4.0f), \\\n detail, \\\n roughness, \\\n lacunarity, \\\n offset, \\\n gain, \\\n normalize != 0.0f), \\\n NOISE_TYPE(p + random_vec4_offset(5.0f), \\\n detail, \\\n roughness, \\\n lacunarity, \\\n offset, \\\n gain, \\\n normalize != 0.0f), \\\n 1.0f); \\\n }\n\nfloat random_float_offset(float seed)\n{\n return 100.0f + hash_float_to_float(seed) * 100.0f;\n}\n\nfloat2 random_vec2_offset(float seed)\n{\n return float2(100.0f + hash_vec2_to_float(float2(seed, 0.0f)) * 100.0f,\n 100.0f + hash_vec2_to_float(float2(seed, 1.0f)) * 100.0f);\n}\n\nfloat3 random_vec3_offset(float seed)\n{\n return float3(100.0f + hash_vec2_to_float(float2(seed, 0.0f)) * 100.0f,\n 100.0f + hash_vec2_to_float(float2(seed, 1.0f)) * 100.0f,\n 100.0f + hash_vec2_to_float(float2(seed, 2.0f)) * 100.0f);\n}\n\nfloat4 random_vec4_offset(float seed)\n{\n return float4(100.0f + hash_vec2_to_float(float2(seed, 0.0f)) * 100.0f,\n 100.0f + hash_vec2_to_float(float2(seed, 1.0f)) * 100.0f,\n 100.0f + hash_vec2_to_float(float2(seed, 2.0f)) * 100.0f,\n 100.0f + hash_vec2_to_float(float2(seed, 3.0f)) * 100.0f);\n}\nvoid node_noise_tex_fbm_1d(float3 co,\n float w,\n float scale,\n float detail,\n float roughness,\n float lacunarity,\n float offset,\n float gain,\n float distortion,\n float normalize,\n float compute_color,\n _ref(float ,value),\n _ref(float4 ,color))\n{\n detail = clamp(detail, 0.0f, 15.0f);\n roughness = max(roughness, 0.0f);\n\n float p = w * scale;\n\n NOISE_FRACTAL_DISTORTED_1D(noise_fbm)\n}\nvoid node_noise_tex_fbm_2d(float3 co,\n float w,\n float scale,\n float detail,\n float roughness,\n float lacunarity,\n float offset,\n float gain,\n float distortion,\n float normalize,\n float compute_color,\n _ref(float ,value),\n _ref(float4 ,color))\n{\n detail = clamp(detail, 0.0f, 15.0f);\n roughness = max(roughness, 0.0f);\n\n float2 p = co.xy * scale;\n\n NOISE_FRACTAL_DISTORTED_2D(noise_fbm)\n}\nvoid node_noise_tex_fbm_3d(float3 co,\n float w,\n float scale,\n float detail,\n float roughness,\n float lacunarity,\n float offset,\n float gain,\n float distortion,\n float normalize,\n float compute_color,\n _ref(float ,value),\n _ref(float4 ,color))\n{\n detail = clamp(detail, 0.0f, 15.0f);\n roughness = max(roughness, 0.0f);\n\n float3 p = co * scale;\n\n NOISE_FRACTAL_DISTORTED_3D(noise_fbm)\n}\nvoid node_noise_tex_fbm_4d(float3 co,\n float w,\n float scale,\n float detail,\n float roughness,\n float lacunarity,\n float offset,\n float gain,\n float distortion,\n float normalize,\n float compute_color,\n _ref(float ,value),\n _ref(float4 ,color))\n{\n detail = clamp(detail, 0.0f, 15.0f);\n roughness = max(roughness, 0.0f);\n\n float4 p = float4(co, w) * scale;\n\n NOISE_FRACTAL_DISTORTED_4D(noise_fbm)\n}\nvoid node_noise_tex_multi_fractal_1d(float3 co,\n float w,\n float scale,\n float detail,\n float roughness,\n float lacunarity,\n float offset,\n float gain,\n float distortion,\n float normalize,\n float compute_color,\n _ref(float ,value),\n _ref(float4 ,color))\n{\n detail = clamp(detail, 0.0f, 15.0f);\n roughness = max(roughness, 0.0f);\n\n float p = w * scale;\n\n NOISE_FRACTAL_DISTORTED_1D(noise_multi_fractal)\n}\nvoid node_noise_tex_multi_fractal_2d(float3 co,\n float w,\n float scale,\n float detail,\n float roughness,\n float lacunarity,\n float offset,\n float gain,\n float distortion,\n float normalize,\n float compute_color,\n _ref(float ,value),\n _ref(float4 ,color))\n{\n detail = clamp(detail, 0.0f, 15.0f);\n roughness = max(roughness, 0.0f);\n\n float2 p = co.xy * scale;\n\n NOISE_FRACTAL_DISTORTED_2D(noise_multi_fractal)\n}\nvoid node_noise_tex_multi_fractal_3d(float3 co,\n float w,\n float scale,\n float detail,\n float roughness,\n float lacunarity,\n float offset,\n float gain,\n float distortion,\n float normalize,\n float compute_color,\n _ref(float ,value),\n _ref(float4 ,color))\n{\n detail = clamp(detail, 0.0f, 15.0f);\n roughness = max(roughness, 0.0f);\n\n float3 p = co * scale;\n\n NOISE_FRACTAL_DISTORTED_3D(noise_multi_fractal)\n}\nvoid node_noise_tex_multi_fractal_4d(float3 co,\n float w,\n float scale,\n float detail,\n float roughness,\n float lacunarity,\n float offset,\n float gain,\n float distortion,\n float normalize,\n float compute_color,\n _ref(float ,value),\n _ref(float4 ,color))\n{\n detail = clamp(detail, 0.0f, 15.0f);\n roughness = max(roughness, 0.0f);\n\n float4 p = float4(co, w) * scale;\n\n NOISE_FRACTAL_DISTORTED_4D(noise_multi_fractal)\n}\nvoid node_noise_tex_hetero_terrain_1d(float3 co,\n float w,\n float scale,\n float detail,\n float roughness,\n float lacunarity,\n float offset,\n float gain,\n float distortion,\n float normalize,\n float compute_color,\n _ref(float ,value),\n _ref(float4 ,color))\n{\n detail = clamp(detail, 0.0f, 15.0f);\n roughness = max(roughness, 0.0f);\n\n float p = w * scale;\n\n NOISE_FRACTAL_DISTORTED_1D(noise_hetero_terrain)\n}\nvoid node_noise_tex_hetero_terrain_2d(float3 co,\n float w,\n float scale,\n float detail,\n float roughness,\n float lacunarity,\n float offset,\n float gain,\n float distortion,\n float normalize,\n float compute_color,\n _ref(float ,value),\n _ref(float4 ,color))\n{\n detail = clamp(detail, 0.0f, 15.0f);\n roughness = max(roughness, 0.0f);\n\n float2 p = co.xy * scale;\n\n NOISE_FRACTAL_DISTORTED_2D(noise_hetero_terrain)\n}\nvoid node_noise_tex_hetero_terrain_3d(float3 co,\n float w,\n float scale,\n float detail,\n float roughness,\n float lacunarity,\n float offset,\n float gain,\n float distortion,\n float normalize,\n float compute_color,\n _ref(float ,value),\n _ref(float4 ,color))\n{\n detail = clamp(detail, 0.0f, 15.0f);\n roughness = max(roughness, 0.0f);\n\n float3 p = co * scale;\n\n NOISE_FRACTAL_DISTORTED_3D(noise_hetero_terrain)\n}\nvoid node_noise_tex_hetero_terrain_4d(float3 co,\n float w,\n float scale,\n float detail,\n float roughness,\n float lacunarity,\n float offset,\n float gain,\n float distortion,\n float normalize,\n float compute_color,\n _ref(float ,value),\n _ref(float4 ,color))\n{\n detail = clamp(detail, 0.0f, 15.0f);\n roughness = max(roughness, 0.0f);\n\n float4 p = float4(co, w) * scale;\n\n NOISE_FRACTAL_DISTORTED_4D(noise_hetero_terrain)\n}\nvoid node_noise_tex_hybrid_multi_fractal_1d(float3 co,\n float w,\n float scale,\n float detail,\n float roughness,\n float lacunarity,\n float offset,\n float gain,\n float distortion,\n float normalize,\n float compute_color,\n _ref(float ,value),\n _ref(float4 ,color))\n{\n detail = clamp(detail, 0.0f, 15.0f);\n roughness = max(roughness, 0.0f);\n\n float p = w * scale;\n\n NOISE_FRACTAL_DISTORTED_1D(noise_hybrid_multi_fractal)\n}\nvoid node_noise_tex_hybrid_multi_fractal_2d(float3 co,\n float w,\n float scale,\n float detail,\n float roughness,\n float lacunarity,\n float offset,\n float gain,\n float distortion,\n float normalize,\n float compute_color,\n _ref(float ,value),\n _ref(float4 ,color))\n{\n detail = clamp(detail, 0.0f, 15.0f);\n roughness = max(roughness, 0.0f);\n\n float2 p = co.xy * scale;\n\n NOISE_FRACTAL_DISTORTED_2D(noise_hybrid_multi_fractal)\n}\nvoid node_noise_tex_hybrid_multi_fractal_3d(float3 co,\n float w,\n float scale,\n float detail,\n float roughness,\n float lacunarity,\n float offset,\n float gain,\n float distortion,\n float normalize,\n float compute_color,\n _ref(float ,value),\n _ref(float4 ,color))\n{\n detail = clamp(detail, 0.0f, 15.0f);\n roughness = max(roughness, 0.0f);\n\n float3 p = co * scale;\n\n NOISE_FRACTAL_DISTORTED_3D(noise_hybrid_multi_fractal)\n}\nvoid node_noise_tex_hybrid_multi_fractal_4d(float3 co,\n float w,\n float scale,\n float detail,\n float roughness,\n float lacunarity,\n float offset,\n float gain,\n float distortion,\n float normalize,\n float compute_color,\n _ref(float ,value),\n _ref(float4 ,color))\n{\n detail = clamp(detail, 0.0f, 15.0f);\n roughness = max(roughness, 0.0f);\n\n float4 p = float4(co, w) * scale;\n\n NOISE_FRACTAL_DISTORTED_4D(noise_hybrid_multi_fractal)\n}\nvoid node_noise_tex_ridged_multi_fractal_1d(float3 co,\n float w,\n float scale,\n float detail,\n float roughness,\n float lacunarity,\n float offset,\n float gain,\n float distortion,\n float normalize,\n float compute_color,\n _ref(float ,value),\n _ref(float4 ,color))\n{\n detail = clamp(detail, 0.0f, 15.0f);\n roughness = max(roughness, 0.0f);\n\n float p = w * scale;\n\n NOISE_FRACTAL_DISTORTED_1D(noise_ridged_multi_fractal)\n}\nvoid node_noise_tex_ridged_multi_fractal_2d(float3 co,\n float w,\n float scale,\n float detail,\n float roughness,\n float lacunarity,\n float offset,\n float gain,\n float distortion,\n float normalize,\n float compute_color,\n _ref(float ,value),\n _ref(float4 ,color))\n{\n detail = clamp(detail, 0.0f, 15.0f);\n roughness = max(roughness, 0.0f);\n\n float2 p = co.xy * scale;\n\n NOISE_FRACTAL_DISTORTED_2D(noise_ridged_multi_fractal)\n}\nvoid node_noise_tex_ridged_multi_fractal_3d(float3 co,\n float w,\n float scale,\n float detail,\n float roughness,\n float lacunarity,\n float offset,\n float gain,\n float distortion,\n float normalize,\n float compute_color,\n _ref(float ,value),\n _ref(float4 ,color))\n{\n detail = clamp(detail, 0.0f, 15.0f);\n roughness = max(roughness, 0.0f);\n\n float3 p = co * scale;\n\n NOISE_FRACTAL_DISTORTED_3D(noise_ridged_multi_fractal)\n}\nvoid node_noise_tex_ridged_multi_fractal_4d(float3 co,\n float w,\n float scale,\n float detail,\n float roughness,\n float lacunarity,\n float offset,\n float gain,\n float distortion,\n float normalize,\n float compute_color,\n _ref(float ,value),\n _ref(float4 ,color))\n{\n detail = clamp(detail, 0.0f, 15.0f);\n roughness = max(roughness, 0.0f);\n\n float4 p = float4(co, w) * scale;\n\n NOISE_FRACTAL_DISTORTED_4D(noise_ridged_multi_fractal)\n}"
|
|
250
|
+
},
|
|
251
|
+
"gpu_shader_material_fractal_noise.glsl": {
|
|
252
|
+
"deps": [
|
|
253
|
+
"gpu_shader_math_constants_lib.glsl",
|
|
254
|
+
"gpu_shader_common_hash.glsl",
|
|
255
|
+
"gpu_shader_material_noise.glsl"
|
|
256
|
+
],
|
|
257
|
+
"code": "#define NOISE_FBM(T) \\\n float noise_fbm(T co, \\\n float detail, \\\n float roughness, \\\n float lacunarity, \\\n float offset, \\\n float gain, \\\n bool normalize) \\\n { \\\n T p = co; \\\n float fscale = 1.0f; \\\n float amp = 1.0f; \\\n float maxamp = 0.0f; \\\n float sum = 0.0f; \\\n for (int i = 0; i <= int(detail); i++) { \\\n float t = snoise(fscale * p); \\\n sum += t * amp; \\\n maxamp += amp; \\\n amp *= roughness; \\\n fscale *= lacunarity; \\\n } \\\n float rmd = detail - floor(detail); \\\n if (rmd != 0.0f) { \\\n float t = snoise(fscale * p); \\\n float sum2 = sum + t * amp; \\\n return normalize ? \\\n mix(0.5f * sum / maxamp + 0.5f, 0.5f * sum2 / (maxamp + amp) + 0.5f, rmd) : \\\n mix(sum, sum2, rmd); \\\n } \\\n else { \\\n return normalize ? 0.5f * sum / maxamp + 0.5f : sum; \\\n } \\\n }\n\n#define NOISE_MULTI_FRACTAL(T) \\\n float noise_multi_fractal(T co, \\\n float detail, \\\n float roughness, \\\n float lacunarity, \\\n float offset, \\\n float gain, \\\n bool normalize) \\\n { \\\n T p = co; \\\n float value = 1.0f; \\\n float pwr = 1.0f; \\\n for (int i = 0; i <= int(detail); i++) { \\\n value *= (pwr * snoise(p) + 1.0f); \\\n pwr *= roughness; \\\n p *= lacunarity; \\\n } \\\n float rmd = detail - floor(detail); \\\n if (rmd != 0.0f) { \\\n value *= (rmd * pwr * snoise(p) + 1.0f); \\\n } \\\n return value; \\\n }\n\n#define NOISE_HETERO_TERRAIN(T) \\\n float noise_hetero_terrain(T co, \\\n float detail, \\\n float roughness, \\\n float lacunarity, \\\n float offset, \\\n float gain, \\\n bool normalize) \\\n { \\\n T p = co; \\\n float pwr = roughness; \\\n float value = offset + snoise(p); \\\n p *= lacunarity; \\\n for (int i = 1; i <= int(detail); i++) { \\\n float increment = (snoise(p) + offset) * pwr * value; \\\n value += increment; \\\n pwr *= roughness; \\\n p *= lacunarity; \\\n } \\\n float rmd = detail - floor(detail); \\\n if (rmd != 0.0f) { \\\n float increment = (snoise(p) + offset) * pwr * value; \\\n value += rmd * increment; \\\n } \\\n return value; \\\n }\n\n#define NOISE_HYBRID_MULTI_FRACTAL(T) \\\n float noise_hybrid_multi_fractal(T co, \\\n float detail, \\\n float roughness, \\\n float lacunarity, \\\n float offset, \\\n float gain, \\\n bool normalize) \\\n { \\\n T p = co; \\\n float pwr = 1.0f; \\\n float value = 0.0f; \\\n float weight = 1.0f; \\\n for (int i = 0; (weight > 0.001f) && (i <= int(detail)); i++) { \\\n if (weight > 1.0f) { \\\n weight = 1.0f; \\\n } \\\n float signal = (snoise(p) + offset) * pwr; \\\n pwr *= roughness; \\\n value += weight * signal; \\\n weight *= gain * signal; \\\n p *= lacunarity; \\\n } \\\n float rmd = detail - floor(detail); \\\n if ((rmd != 0.0f) && (weight > 0.001f)) { \\\n if (weight > 1.0f) { \\\n weight = 1.0f; \\\n } \\\n float signal = (snoise(p) + offset) * pwr; \\\n value += rmd * weight * signal; \\\n } \\\n return value; \\\n }\n\n#define NOISE_RIDGED_MULTI_FRACTAL(T) \\\n float noise_ridged_multi_fractal(T co, \\\n float detail, \\\n float roughness, \\\n float lacunarity, \\\n float offset, \\\n float gain, \\\n bool normalize) \\\n { \\\n T p = co; \\\n float pwr = roughness; \\\n float signal = offset - abs(snoise(p)); \\\n signal *= signal; \\\n float value = signal; \\\n float weight = 1.0f; \\\n for (int i = 1; i <= int(detail); i++) { \\\n p *= lacunarity; \\\n weight = clamp(signal * gain, 0.0f, 1.0f); \\\n signal = offset - abs(snoise(p)); \\\n signal *= signal; \\\n signal *= weight; \\\n value += signal * pwr; \\\n pwr *= roughness; \\\n } \\\n return value; \\\n }\nNOISE_FBM(float)\nNOISE_FBM(float2)\nNOISE_FBM(float3)\nNOISE_FBM(float4)\nNOISE_MULTI_FRACTAL(float)\nNOISE_MULTI_FRACTAL(float2)\nNOISE_MULTI_FRACTAL(float3)\nNOISE_MULTI_FRACTAL(float4)\nNOISE_HETERO_TERRAIN(float)\nNOISE_HETERO_TERRAIN(float2)\nNOISE_HETERO_TERRAIN(float3)\nNOISE_HETERO_TERRAIN(float4)\nNOISE_HYBRID_MULTI_FRACTAL(float)\nNOISE_HYBRID_MULTI_FRACTAL(float2)\nNOISE_HYBRID_MULTI_FRACTAL(float3)\nNOISE_HYBRID_MULTI_FRACTAL(float4)\nNOISE_RIDGED_MULTI_FRACTAL(float)\nNOISE_RIDGED_MULTI_FRACTAL(float2)\nNOISE_RIDGED_MULTI_FRACTAL(float3)\nNOISE_RIDGED_MULTI_FRACTAL(float4)"
|
|
258
|
+
},
|
|
259
|
+
"gpu_shader_material_noise.glsl": {
|
|
260
|
+
"deps": [
|
|
261
|
+
"gpu_shader_math_constants_lib.glsl",
|
|
262
|
+
"gpu_shader_common_hash.glsl",
|
|
263
|
+
"gpu_shader_math_vector_safe_lib.glsl"
|
|
264
|
+
],
|
|
265
|
+
"code": "#define FLOORFRAC(x, x_int, x_fract) { float x_floor = floor(x); x_int = int(x_floor); x_fract = x - x_floor; }\nfloat bi_mix(float v0, float v1, float v2, float v3, float x, float y)\n{\n float x1 = 1.0f - x;\n return (1.0f - y) * (v0 * x1 + v1 * x) + y * (v2 * x1 + v3 * x);\n}\nfloat tri_mix(float v0,\n float v1,\n float v2,\n float v3,\n float v4,\n float v5,\n float v6,\n float v7,\n float x,\n float y,\n float z)\n{\n float x1 = 1.0f - x;\n float y1 = 1.0f - y;\n float z1 = 1.0f - z;\n return z1 * (y1 * (v0 * x1 + v1 * x) + y * (v2 * x1 + v3 * x)) +\n z * (y1 * (v4 * x1 + v5 * x) + y * (v6 * x1 + v7 * x));\n}\n\nfloat quad_mix(float v0,\n float v1,\n float v2,\n float v3,\n float v4,\n float v5,\n float v6,\n float v7,\n float v8,\n float v9,\n float v10,\n float v11,\n float v12,\n float v13,\n float v14,\n float v15,\n float x,\n float y,\n float z,\n float w)\n{\n return mix(tri_mix(v0, v1, v2, v3, v4, v5, v6, v7, x, y, z),\n tri_mix(v8, v9, v10, v11, v12, v13, v14, v15, x, y, z),\n w);\n}\n\nfloat fade(float t)\n{\n return t * t * t * (t * (t * 6.0f - 15.0f) + 10.0f);\n}\n\nfloat negate_if(float value, uint condition)\n{\n return (condition != 0u) ? -value : value;\n}\n\nfloat noise_grad(uint hash, float x)\n{\n uint h = hash & 15u;\n float g = float(1u + (h & 7u));\n return negate_if(g, h & 8u) * x;\n}\n\nfloat noise_grad(uint hash, float x, float y)\n{\n uint h = hash & 7u;\n float u = h < 4u ? x : y;\n float v = 2.0f * (h < 4u ? y : x);\n return negate_if(u, h & 1u) + negate_if(v, h & 2u);\n}\n\nfloat noise_grad(uint hash, float x, float y, float z)\n{\n uint h = hash & 15u;\n float u = h < 8u ? x : y;\n float vt = ((h == 12u) || (h == 14u)) ? x : z;\n float v = h < 4u ? y : vt;\n return negate_if(u, h & 1u) + negate_if(v, h & 2u);\n}\n\nfloat noise_grad(uint hash, float x, float y, float z, float w)\n{\n uint h = hash & 31u;\n float u = h < 24u ? x : y;\n float v = h < 16u ? y : z;\n float s = h < 8u ? z : w;\n return negate_if(u, h & 1u) + negate_if(v, h & 2u) + negate_if(s, h & 4u);\n}\n\nfloat noise_perlin(float x)\n{\n int X;\n float fx;\n\n FLOORFRAC(x, X, fx);\n\n float u = fade(fx);\n\n float r = mix(noise_grad(hash_int(X), fx), noise_grad(hash_int(X + 1), fx - 1.0f), u);\n\n return r;\n}\n\nfloat noise_perlin(float2 vec)\n{\n int X, Y;\n float fx, fy;\n\n FLOORFRAC(vec.x, X, fx);\n FLOORFRAC(vec.y, Y, fy);\n\n float u = fade(fx);\n float v = fade(fy);\n\n float r = bi_mix(noise_grad(hash_int2(X, Y), fx, fy),\n noise_grad(hash_int2(X + 1, Y), fx - 1.0f, fy),\n noise_grad(hash_int2(X, Y + 1), fx, fy - 1.0f),\n noise_grad(hash_int2(X + 1, Y + 1), fx - 1.0f, fy - 1.0f),\n u,\n v);\n\n return r;\n}\n\nfloat noise_perlin(float3 vec)\n{\n int X, Y, Z;\n float fx, fy, fz;\n\n FLOORFRAC(vec.x, X, fx);\n FLOORFRAC(vec.y, Y, fy);\n FLOORFRAC(vec.z, Z, fz);\n\n float u = fade(fx);\n float v = fade(fy);\n float w = fade(fz);\n\n float r = tri_mix(noise_grad(hash_int3(X, Y, Z), fx, fy, fz),\n noise_grad(hash_int3(X + 1, Y, Z), fx - 1.0f, fy, fz),\n noise_grad(hash_int3(X, Y + 1, Z), fx, fy - 1.0f, fz),\n noise_grad(hash_int3(X + 1, Y + 1, Z), fx - 1.0f, fy - 1.0f, fz),\n noise_grad(hash_int3(X, Y, Z + 1), fx, fy, fz - 1.0f),\n noise_grad(hash_int3(X + 1, Y, Z + 1), fx - 1.0f, fy, fz - 1.0f),\n noise_grad(hash_int3(X, Y + 1, Z + 1), fx, fy - 1.0f, fz - 1.0f),\n noise_grad(hash_int3(X + 1, Y + 1, Z + 1), fx - 1.0f, fy - 1.0f, fz - 1.0f),\n u,\n v,\n w);\n\n return r;\n}\n\nfloat noise_perlin(float4 vec)\n{\n int X, Y, Z, W;\n float fx, fy, fz, fw;\n\n FLOORFRAC(vec.x, X, fx);\n FLOORFRAC(vec.y, Y, fy);\n FLOORFRAC(vec.z, Z, fz);\n FLOORFRAC(vec.w, W, fw);\n\n float u = fade(fx);\n float v = fade(fy);\n float t = fade(fz);\n float s = fade(fw);\n\n float r = quad_mix(\n noise_grad(hash_int4(X, Y, Z, W), fx, fy, fz, fw),\n noise_grad(hash_int4(X + 1, Y, Z, W), fx - 1.0f, fy, fz, fw),\n noise_grad(hash_int4(X, Y + 1, Z, W), fx, fy - 1.0f, fz, fw),\n noise_grad(hash_int4(X + 1, Y + 1, Z, W), fx - 1.0f, fy - 1.0f, fz, fw),\n noise_grad(hash_int4(X, Y, Z + 1, W), fx, fy, fz - 1.0f, fw),\n noise_grad(hash_int4(X + 1, Y, Z + 1, W), fx - 1.0f, fy, fz - 1.0f, fw),\n noise_grad(hash_int4(X, Y + 1, Z + 1, W), fx, fy - 1.0f, fz - 1.0f, fw),\n noise_grad(hash_int4(X + 1, Y + 1, Z + 1, W), fx - 1.0f, fy - 1.0f, fz - 1.0f, fw),\n noise_grad(hash_int4(X, Y, Z, W + 1), fx, fy, fz, fw - 1.0f),\n noise_grad(hash_int4(X + 1, Y, Z, W + 1), fx - 1.0f, fy, fz, fw - 1.0f),\n noise_grad(hash_int4(X, Y + 1, Z, W + 1), fx, fy - 1.0f, fz, fw - 1.0f),\n noise_grad(hash_int4(X + 1, Y + 1, Z, W + 1), fx - 1.0f, fy - 1.0f, fz, fw - 1.0f),\n noise_grad(hash_int4(X, Y, Z + 1, W + 1), fx, fy, fz - 1.0f, fw - 1.0f),\n noise_grad(hash_int4(X + 1, Y, Z + 1, W + 1), fx - 1.0f, fy, fz - 1.0f, fw - 1.0f),\n noise_grad(hash_int4(X, Y + 1, Z + 1, W + 1), fx, fy - 1.0f, fz - 1.0f, fw - 1.0f),\n noise_grad(\n hash_int4(X + 1, Y + 1, Z + 1, W + 1), fx - 1.0f, fy - 1.0f, fz - 1.0f, fw - 1.0f),\n u,\n v,\n t,\n s);\n\n return r;\n}\nfloat noise_scale1(float result)\n{\n return 0.2500f * result;\n}\n\nfloat noise_scale2(float result)\n{\n return 0.6616f * result;\n}\n\nfloat noise_scale3(float result)\n{\n return 0.9820f * result;\n}\n\nfloat noise_scale4(float result)\n{\n return 0.8344f * result;\n}\nfloat snoise(float p)\n{\n float precision_correction = 0.5f * float(abs(p) >= 1000000.0f);\n p = compatible_mod(p, 100000.0f) + precision_correction;\n\n return noise_scale1(noise_perlin(p));\n}\n\nfloat noise(float p)\n{\n return 0.5f * snoise(p) + 0.5f;\n}\n\nfloat snoise(float2 p)\n{\n float2 precision_correction = 0.5f * float2(float(abs(p.x) >= 1000000.0f),\n float(abs(p.y) >= 1000000.0f));\n p = compatible_mod(p, 100000.0f) + precision_correction;\n\n return noise_scale2(noise_perlin(p));\n}\n\nfloat noise(float2 p)\n{\n return 0.5f * snoise(p) + 0.5f;\n}\n\nfloat snoise(float3 p)\n{\n float3 precision_correction = 0.5f * float3(float(abs(p.x) >= 1000000.0f),\n float(abs(p.y) >= 1000000.0f),\n float(abs(p.z) >= 1000000.0f));\n p = compatible_mod(p, 100000.0f) + precision_correction;\n\n return noise_scale3(noise_perlin(p));\n}\n\nfloat noise(float3 p)\n{\n return 0.5f * snoise(p) + 0.5f;\n}\n\nfloat snoise(float4 p)\n{\n float4 precision_correction = 0.5f * float4(float(abs(p.x) >= 1000000.0f),\n float(abs(p.y) >= 1000000.0f),\n float(abs(p.z) >= 1000000.0f),\n float(abs(p.w) >= 1000000.0f));\n p = compatible_mod(p, 100000.0f) + precision_correction;\n\n return noise_scale4(noise_perlin(p));\n}\n\nfloat noise(float4 p)\n{\n return 0.5f * snoise(p) + 0.5f;\n}"
|
|
266
|
+
},
|
|
267
|
+
"gpu_shader_material_tex_voronoi.glsl": {
|
|
268
|
+
"deps": [
|
|
269
|
+
"gpu_shader_math_constants_lib.glsl",
|
|
270
|
+
"gpu_shader_common_hash.glsl",
|
|
271
|
+
"gpu_shader_material_fractal_voronoi.glsl",
|
|
272
|
+
"gpu_shader_material_voronoi.glsl",
|
|
273
|
+
"gpu_shader_math_base_lib.glsl"
|
|
274
|
+
],
|
|
275
|
+
"code": "#define INITIALIZE_VORONOIPARAMS(FEATURE) \\\n params.feature = FEATURE; \\\n params.metric = int(metric); \\\n params.scale = scale; \\\n params.detail = clamp(detail, 0.0f, 15.0f); \\\n params.roughness = clamp(roughness, 0.0f, 1.0f); \\\n params.lacunarity = lacunarity; \\\n params.smoothness = clamp(smoothness / 2.0f, 0.0f, 0.5f); \\\n params.exponent = exponent; \\\n params.randomness = clamp(randomness, 0.0f, 1.0f); \\\n params.max_distance = 0.0f; \\\n params.normalize = bool(normalize);\nvoid node_tex_voronoi_f1_1d(float3 coord,\n float w,\n float scale,\n float detail,\n float roughness,\n float lacunarity,\n float smoothness,\n float exponent,\n float randomness,\n float metric,\n float normalize,\n _ref(float ,outDistance),\n _ref(float4 ,outColor),\n _ref(float3 ,outPosition),\n _ref(float ,outW),\n _ref(float ,outRadius))\n{\n VoronoiParams params;\n\n INITIALIZE_VORONOIPARAMS(SHD_VORONOI_F1)\n\n w *= scale;\n\n params.max_distance = 0.5f + 0.5f * params.randomness;\n VoronoiOutput Output = fractal_voronoi_x_fx(params, w);\n outDistance = Output.Distance;\n outColor = float4(Output.Color, 1.0f);\n outW = Output.Position.w;\n}\nvoid node_tex_voronoi_smooth_f1_1d(float3 coord,\n float w,\n float scale,\n float detail,\n float roughness,\n float lacunarity,\n float smoothness,\n float exponent,\n float randomness,\n float metric,\n float normalize,\n _ref(float ,outDistance),\n _ref(float4 ,outColor),\n _ref(float3 ,outPosition),\n _ref(float ,outW),\n _ref(float ,outRadius))\n{\n VoronoiParams params;\n\n INITIALIZE_VORONOIPARAMS(SHD_VORONOI_SMOOTH_F1)\n\n w *= scale;\n\n params.max_distance = 0.5f + 0.5f * params.randomness;\n VoronoiOutput Output = fractal_voronoi_x_fx(params, w);\n outDistance = Output.Distance;\n outColor = float4(Output.Color, 1.0f);\n outW = Output.Position.w;\n}\nvoid node_tex_voronoi_f2_1d(float3 coord,\n float w,\n float scale,\n float detail,\n float roughness,\n float lacunarity,\n float smoothness,\n float exponent,\n float randomness,\n float metric,\n float normalize,\n _ref(float ,outDistance),\n _ref(float4 ,outColor),\n _ref(float3 ,outPosition),\n _ref(float ,outW),\n _ref(float ,outRadius))\n{\n VoronoiParams params;\n\n INITIALIZE_VORONOIPARAMS(SHD_VORONOI_F2)\n\n w *= scale;\n\n params.max_distance = (0.5f + 0.5f * params.randomness) * 2.0f;\n VoronoiOutput Output = fractal_voronoi_x_fx(params, w);\n outDistance = Output.Distance;\n outColor = float4(Output.Color, 1.0f);\n outW = Output.Position.w;\n}\nvoid node_tex_voronoi_distance_to_edge_1d(float3 coord,\n float w,\n float scale,\n float detail,\n float roughness,\n float lacunarity,\n float smoothness,\n float exponent,\n float randomness,\n float metric,\n float normalize,\n _ref(float ,outDistance),\n _ref(float4 ,outColor),\n _ref(float3 ,outPosition),\n _ref(float ,outW),\n _ref(float ,outRadius))\n{\n VoronoiParams params;\n\n INITIALIZE_VORONOIPARAMS(SHD_VORONOI_DISTANCE_TO_EDGE)\n\n w *= scale;\n\n params.max_distance = 0.5f + 0.5f * params.randomness;\n outDistance = fractal_voronoi_distance_to_edge(params, w);\n}\nvoid node_tex_voronoi_n_sphere_radius_1d(float3 coord,\n float w,\n float scale,\n float detail,\n float roughness,\n float lacunarity,\n float smoothness,\n float exponent,\n float randomness,\n float metric,\n float normalize,\n _ref(float ,outDistance),\n _ref(float4 ,outColor),\n _ref(float3 ,outPosition),\n _ref(float ,outW),\n _ref(float ,outRadius))\n{\n VoronoiParams params;\n\n INITIALIZE_VORONOIPARAMS(SHD_VORONOI_N_SPHERE_RADIUS)\n\n w *= scale;\n\n outRadius = voronoi_n_sphere_radius(params, w);\n}\nvoid node_tex_voronoi_f1_2d(float3 coord,\n float w,\n float scale,\n float detail,\n float roughness,\n float lacunarity,\n float smoothness,\n float exponent,\n float randomness,\n float metric,\n float normalize,\n _ref(float ,outDistance),\n _ref(float4 ,outColor),\n _ref(float3 ,outPosition),\n _ref(float ,outW),\n _ref(float ,outRadius))\n{\n VoronoiParams params;\n\n INITIALIZE_VORONOIPARAMS(SHD_VORONOI_F1)\n\n coord *= scale;\n\n params.max_distance = voronoi_distance(\n float2(0.0f), float2(0.5f + 0.5f * params.randomness), params);\n VoronoiOutput Output = fractal_voronoi_x_fx(params, coord.xy);\n outDistance = Output.Distance;\n outColor = float4(Output.Color, 1.0f);\n outPosition = Output.Position.xyz;\n}\nvoid node_tex_voronoi_smooth_f1_2d(float3 coord,\n float w,\n float scale,\n float detail,\n float roughness,\n float lacunarity,\n float smoothness,\n float exponent,\n float randomness,\n float metric,\n float normalize,\n _ref(float ,outDistance),\n _ref(float4 ,outColor),\n _ref(float3 ,outPosition),\n _ref(float ,outW),\n _ref(float ,outRadius))\n{\n VoronoiParams params;\n\n INITIALIZE_VORONOIPARAMS(SHD_VORONOI_SMOOTH_F1)\n\n coord *= scale;\n\n params.max_distance = voronoi_distance(\n float2(0.0f), float2(0.5f + 0.5f * params.randomness), params);\n VoronoiOutput Output = fractal_voronoi_x_fx(params, coord.xy);\n outDistance = Output.Distance;\n outColor = float4(Output.Color, 1.0f);\n outPosition = Output.Position.xyz;\n}\nvoid node_tex_voronoi_f2_2d(float3 coord,\n float w,\n float scale,\n float detail,\n float roughness,\n float lacunarity,\n float smoothness,\n float exponent,\n float randomness,\n float metric,\n float normalize,\n _ref(float ,outDistance),\n _ref(float4 ,outColor),\n _ref(float3 ,outPosition),\n _ref(float ,outW),\n _ref(float ,outRadius))\n{\n VoronoiParams params;\n\n INITIALIZE_VORONOIPARAMS(SHD_VORONOI_F2)\n\n coord *= scale;\n\n params.max_distance = voronoi_distance(\n float2(0.0f), float2(0.5f + 0.5f * params.randomness), params) *\n 2.0f;\n VoronoiOutput Output = fractal_voronoi_x_fx(params, coord.xy);\n outDistance = Output.Distance;\n outColor = float4(Output.Color, 1.0f);\n outPosition = Output.Position.xyz;\n}\nvoid node_tex_voronoi_distance_to_edge_2d(float3 coord,\n float w,\n float scale,\n float detail,\n float roughness,\n float lacunarity,\n float smoothness,\n float exponent,\n float randomness,\n float metric,\n float normalize,\n _ref(float ,outDistance),\n _ref(float4 ,outColor),\n _ref(float3 ,outPosition),\n _ref(float ,outW),\n _ref(float ,outRadius))\n{\n VoronoiParams params;\n\n INITIALIZE_VORONOIPARAMS(SHD_VORONOI_DISTANCE_TO_EDGE)\n\n coord *= scale;\n\n params.max_distance = 0.5f + 0.5f * params.randomness;\n outDistance = fractal_voronoi_distance_to_edge(params, coord.xy);\n}\nvoid node_tex_voronoi_n_sphere_radius_2d(float3 coord,\n float w,\n float scale,\n float detail,\n float roughness,\n float lacunarity,\n float smoothness,\n float exponent,\n float randomness,\n float metric,\n float normalize,\n _ref(float ,outDistance),\n _ref(float4 ,outColor),\n _ref(float3 ,outPosition),\n _ref(float ,outW),\n _ref(float ,outRadius))\n{\n VoronoiParams params;\n\n INITIALIZE_VORONOIPARAMS(SHD_VORONOI_N_SPHERE_RADIUS)\n\n coord *= scale;\n\n outRadius = voronoi_n_sphere_radius(params, coord.xy);\n}\nvoid node_tex_voronoi_f1_3d(float3 coord,\n float w,\n float scale,\n float detail,\n float roughness,\n float lacunarity,\n float smoothness,\n float exponent,\n float randomness,\n float metric,\n float normalize,\n _ref(float ,outDistance),\n _ref(float4 ,outColor),\n _ref(float3 ,outPosition),\n _ref(float ,outW),\n _ref(float ,outRadius))\n{\n VoronoiParams params;\n\n INITIALIZE_VORONOIPARAMS(SHD_VORONOI_F1)\n\n coord *= scale;\n\n params.max_distance = voronoi_distance(\n float3(0.0f), float3(0.5f + 0.5f * params.randomness), params);\n VoronoiOutput Output = fractal_voronoi_x_fx(params, coord);\n outDistance = Output.Distance;\n outColor = float4(Output.Color, 1.0f);\n outPosition = Output.Position.xyz;\n}\nvoid node_tex_voronoi_smooth_f1_3d(float3 coord,\n float w,\n float scale,\n float detail,\n float roughness,\n float lacunarity,\n float smoothness,\n float exponent,\n float randomness,\n float metric,\n float normalize,\n _ref(float ,outDistance),\n _ref(float4 ,outColor),\n _ref(float3 ,outPosition),\n _ref(float ,outW),\n _ref(float ,outRadius))\n{\n VoronoiParams params;\n\n INITIALIZE_VORONOIPARAMS(SHD_VORONOI_SMOOTH_F1)\n\n coord *= scale;\n\n params.max_distance = voronoi_distance(\n float3(0.0f), float3(0.5f + 0.5f * params.randomness), params);\n VoronoiOutput Output = fractal_voronoi_x_fx(params, coord);\n outDistance = Output.Distance;\n outColor = float4(Output.Color, 1.0f);\n outPosition = Output.Position.xyz;\n}\nvoid node_tex_voronoi_f2_3d(float3 coord,\n float w,\n float scale,\n float detail,\n float roughness,\n float lacunarity,\n float smoothness,\n float exponent,\n float randomness,\n float metric,\n float normalize,\n _ref(float ,outDistance),\n _ref(float4 ,outColor),\n _ref(float3 ,outPosition),\n _ref(float ,outW),\n _ref(float ,outRadius))\n{\n VoronoiParams params;\n\n INITIALIZE_VORONOIPARAMS(SHD_VORONOI_F2)\n\n coord *= scale;\n\n params.max_distance = voronoi_distance(\n float3(0.0f), float3(0.5f + 0.5f * params.randomness), params) *\n 2.0f;\n VoronoiOutput Output = fractal_voronoi_x_fx(params, coord);\n outDistance = Output.Distance;\n outColor = float4(Output.Color, 1.0f);\n outPosition = Output.Position.xyz;\n}\nvoid node_tex_voronoi_distance_to_edge_3d(float3 coord,\n float w,\n float scale,\n float detail,\n float roughness,\n float lacunarity,\n float smoothness,\n float exponent,\n float randomness,\n float metric,\n float normalize,\n _ref(float ,outDistance),\n _ref(float4 ,outColor),\n _ref(float3 ,outPosition),\n _ref(float ,outW),\n _ref(float ,outRadius))\n{\n VoronoiParams params;\n\n INITIALIZE_VORONOIPARAMS(SHD_VORONOI_DISTANCE_TO_EDGE)\n\n coord *= scale;\n\n params.max_distance = 0.5f + 0.5f * params.randomness;\n outDistance = fractal_voronoi_distance_to_edge(params, coord);\n}\nvoid node_tex_voronoi_n_sphere_radius_3d(float3 coord,\n float w,\n float scale,\n float detail,\n float roughness,\n float lacunarity,\n float smoothness,\n float exponent,\n float randomness,\n float metric,\n float normalize,\n _ref(float ,outDistance),\n _ref(float4 ,outColor),\n _ref(float3 ,outPosition),\n _ref(float ,outW),\n _ref(float ,outRadius))\n{\n VoronoiParams params;\n\n INITIALIZE_VORONOIPARAMS(SHD_VORONOI_N_SPHERE_RADIUS)\n\n coord *= scale;\n\n outRadius = voronoi_n_sphere_radius(params, coord);\n}\nvoid node_tex_voronoi_f1_4d(float3 coord,\n float w,\n float scale,\n float detail,\n float roughness,\n float lacunarity,\n float smoothness,\n float exponent,\n float randomness,\n float metric,\n float normalize,\n _ref(float ,outDistance),\n _ref(float4 ,outColor),\n _ref(float3 ,outPosition),\n _ref(float ,outW),\n _ref(float ,outRadius))\n{\n VoronoiParams params;\n\n INITIALIZE_VORONOIPARAMS(SHD_VORONOI_F1)\n\n w *= scale;\n coord *= scale;\n\n params.max_distance = voronoi_distance(\n float4(0.0f), float4(0.5f + 0.5f * params.randomness), params);\n VoronoiOutput Output = fractal_voronoi_x_fx(params, float4(coord, w));\n outDistance = Output.Distance;\n outColor = float4(Output.Color, 1.0f);\n outPosition = Output.Position.xyz;\n outW = Output.Position.w;\n}\nvoid node_tex_voronoi_smooth_f1_4d(float3 coord,\n float w,\n float scale,\n float detail,\n float roughness,\n float lacunarity,\n float smoothness,\n float exponent,\n float randomness,\n float metric,\n float normalize,\n _ref(float ,outDistance),\n _ref(float4 ,outColor),\n _ref(float3 ,outPosition),\n _ref(float ,outW),\n _ref(float ,outRadius))\n{\n VoronoiParams params;\n\n INITIALIZE_VORONOIPARAMS(SHD_VORONOI_SMOOTH_F1)\n\n w *= scale;\n coord *= scale;\n\n params.max_distance = voronoi_distance(\n float4(0.0f), float4(0.5f + 0.5f * params.randomness), params);\n VoronoiOutput Output = fractal_voronoi_x_fx(params, float4(coord, w));\n outDistance = Output.Distance;\n outColor = float4(Output.Color, 1.0f);\n outPosition = Output.Position.xyz;\n outW = Output.Position.w;\n}\nvoid node_tex_voronoi_f2_4d(float3 coord,\n float w,\n float scale,\n float detail,\n float roughness,\n float lacunarity,\n float smoothness,\n float exponent,\n float randomness,\n float metric,\n float normalize,\n _ref(float ,outDistance),\n _ref(float4 ,outColor),\n _ref(float3 ,outPosition),\n _ref(float ,outW),\n _ref(float ,outRadius))\n{\n VoronoiParams params;\n\n INITIALIZE_VORONOIPARAMS(SHD_VORONOI_F2)\n\n w *= scale;\n coord *= scale;\n\n params.max_distance = voronoi_distance(\n float4(0.0f), float4(0.5f + 0.5f * params.randomness), params) *\n 2.0f;\n VoronoiOutput Output = fractal_voronoi_x_fx(params, float4(coord, w));\n outDistance = Output.Distance;\n outColor = float4(Output.Color, 1.0f);\n outPosition = Output.Position.xyz;\n outW = Output.Position.w;\n}\nvoid node_tex_voronoi_distance_to_edge_4d(float3 coord,\n float w,\n float scale,\n float detail,\n float roughness,\n float lacunarity,\n float smoothness,\n float exponent,\n float randomness,\n float metric,\n float normalize,\n _ref(float ,outDistance),\n _ref(float4 ,outColor),\n _ref(float3 ,outPosition),\n _ref(float ,outW),\n _ref(float ,outRadius))\n{\n VoronoiParams params;\n\n INITIALIZE_VORONOIPARAMS(SHD_VORONOI_DISTANCE_TO_EDGE)\n\n w *= scale;\n coord *= scale;\n\n params.max_distance = 0.5f + 0.5f * params.randomness;\n outDistance = fractal_voronoi_distance_to_edge(params, float4(coord, w));\n}\nvoid node_tex_voronoi_n_sphere_radius_4d(float3 coord,\n float w,\n float scale,\n float detail,\n float roughness,\n float lacunarity,\n float smoothness,\n float exponent,\n float randomness,\n float metric,\n float normalize,\n _ref(float ,outDistance),\n _ref(float4 ,outColor),\n _ref(float3 ,outPosition),\n _ref(float ,outW),\n _ref(float ,outRadius))\n{\n VoronoiParams params;\n\n INITIALIZE_VORONOIPARAMS(SHD_VORONOI_N_SPHERE_RADIUS)\n\n w *= scale;\n coord *= scale;\n\n outRadius = voronoi_n_sphere_radius(params, float4(coord, w));\n}"
|
|
276
|
+
},
|
|
277
|
+
"gpu_shader_material_fractal_voronoi.glsl": {
|
|
278
|
+
"deps": [
|
|
279
|
+
"gpu_shader_math_constants_lib.glsl",
|
|
280
|
+
"gpu_shader_material_voronoi.glsl",
|
|
281
|
+
"gpu_shader_math_vector_safe_lib.glsl"
|
|
282
|
+
],
|
|
283
|
+
"code": "#define FRACTAL_VORONOI_DISTANCE_TO_EDGE_FUNCTION(T) \\\n float fractal_voronoi_distance_to_edge(VoronoiParams params, T coord) \\\n { \\\n float amplitude = 1.0f; \\\n float max_amplitude = params.max_distance; \\\n float scale = 1.0f; \\\n float distance = 8.0f; \\\n bool zero_input = params.detail == 0.0f || params.roughness == 0.0f; \\\n for (int i = 0; float(i) <= ceil(params.detail); ++i) { \\\n float octave_distance = voronoi_distance_to_edge(params, coord * scale); \\\n if (zero_input) { \\\n distance = octave_distance; \\\n break; \\\n } \\\n else if (float(i) <= params.detail) { \\\n max_amplitude = mix(max_amplitude, params.max_distance / scale, amplitude); \\\n distance = mix(distance, min(distance, octave_distance / scale), amplitude); \\\n scale *= params.lacunarity; \\\n amplitude *= params.roughness; \\\n } \\\n else { \\\n float remainder = params.detail - floor(params.detail); \\\n if (remainder != 0.0f) { \\\n float lerp_amplitude = mix(max_amplitude, params.max_distance / scale, amplitude); \\\n max_amplitude = mix(max_amplitude, lerp_amplitude, remainder); \\\n float lerp_distance = mix(distance, min(distance, octave_distance / scale), amplitude); \\\n distance = mix(distance, min(distance, lerp_distance), remainder); \\\n } \\\n } \\\n } \\\n if (params.normalize) { \\\n distance /= max_amplitude; \\\n } \\\n return distance; \\\n }\nVoronoiOutput fractal_voronoi_x_fx(VoronoiParams params, float coord)\n{\n float amplitude = 1.0f;\n float max_amplitude = 0.0f;\n float scale = 1.0f;\n\n VoronoiOutput Output;\n Output.Distance = 0.0f;\n Output.Color = float3(0.0f, 0.0f, 0.0f);\n Output.Position = float4(0.0f, 0.0f, 0.0f, 0.0f);\n bool zero_input = params.detail == 0.0f || params.roughness == 0.0f;\n\n for (int i = 0; float(i) <= ceil(params.detail); ++i) {\n VoronoiOutput octave;\n if (params.feature == SHD_VORONOI_F2) {\n octave = voronoi_f2(params, coord * scale);\n }\n else if (params.feature == SHD_VORONOI_SMOOTH_F1 && params.smoothness != 0.0f) {\n octave = voronoi_smooth_f1(params, coord * scale);\n }\n else {\n octave = voronoi_f1(params, coord * scale);\n }\n\n if (zero_input) {\n max_amplitude = 1.0f;\n Output = octave;\n break;\n }\n else if (float(i) <= params.detail) {\n max_amplitude += amplitude;\n Output.Distance += octave.Distance * amplitude;\n Output.Color += octave.Color * amplitude;\n Output.Position = mix(Output.Position, octave.Position / scale, amplitude);\n scale *= params.lacunarity;\n amplitude *= params.roughness;\n }\n else {\n float remainder = params.detail - floor(params.detail);\n if (remainder != 0.0f) {\n max_amplitude = mix(max_amplitude, max_amplitude + amplitude, remainder);\n Output.Distance = mix(\n Output.Distance, Output.Distance + octave.Distance * amplitude, remainder);\n Output.Color = mix(Output.Color, Output.Color + octave.Color * amplitude, remainder);\n Output.Position = mix(\n Output.Position, mix(Output.Position, octave.Position / scale, amplitude), remainder);\n }\n }\n }\n\n if (params.normalize) {\n Output.Distance /= max_amplitude * params.max_distance;\n Output.Color /= max_amplitude;\n }\n\n Output.Position = safe_divide(Output.Position, params.scale);\n\n return Output;\n}\n\nFRACTAL_VORONOI_DISTANCE_TO_EDGE_FUNCTION(float)\nVoronoiOutput fractal_voronoi_x_fx(VoronoiParams params, float2 coord)\n{\n float amplitude = 1.0f;\n float max_amplitude = 0.0f;\n float scale = 1.0f;\n\n VoronoiOutput Output;\n Output.Distance = 0.0f;\n Output.Color = float3(0.0f, 0.0f, 0.0f);\n Output.Position = float4(0.0f, 0.0f, 0.0f, 0.0f);\n bool zero_input = params.detail == 0.0f || params.roughness == 0.0f;\n\n for (int i = 0; float(i) <= ceil(params.detail); ++i) {\n VoronoiOutput octave;\n if (params.feature == SHD_VORONOI_F2) {\n octave = voronoi_f2(params, coord * scale);\n }\n else if (params.feature == SHD_VORONOI_SMOOTH_F1 && params.smoothness != 0.0f) {\n octave = voronoi_smooth_f1(params, coord * scale);\n }\n else {\n octave = voronoi_f1(params, coord * scale);\n }\n\n if (zero_input) {\n max_amplitude = 1.0f;\n Output = octave;\n break;\n }\n else if (float(i) <= params.detail) {\n max_amplitude += amplitude;\n Output.Distance += octave.Distance * amplitude;\n Output.Color += octave.Color * amplitude;\n Output.Position = mix(Output.Position, octave.Position / scale, amplitude);\n scale *= params.lacunarity;\n amplitude *= params.roughness;\n }\n else {\n float remainder = params.detail - floor(params.detail);\n if (remainder != 0.0f) {\n max_amplitude = mix(max_amplitude, max_amplitude + amplitude, remainder);\n Output.Distance = mix(\n Output.Distance, Output.Distance + octave.Distance * amplitude, remainder);\n Output.Color = mix(Output.Color, Output.Color + octave.Color * amplitude, remainder);\n Output.Position = mix(\n Output.Position, mix(Output.Position, octave.Position / scale, amplitude), remainder);\n }\n }\n }\n\n if (params.normalize) {\n Output.Distance /= max_amplitude * params.max_distance;\n Output.Color /= max_amplitude;\n }\n\n Output.Position = safe_divide(Output.Position, params.scale);\n\n return Output;\n}\n\nFRACTAL_VORONOI_DISTANCE_TO_EDGE_FUNCTION(float2)\nVoronoiOutput fractal_voronoi_x_fx(VoronoiParams params, float3 coord)\n{\n float amplitude = 1.0f;\n float max_amplitude = 0.0f;\n float scale = 1.0f;\n\n VoronoiOutput Output;\n Output.Distance = 0.0f;\n Output.Color = float3(0.0f, 0.0f, 0.0f);\n Output.Position = float4(0.0f, 0.0f, 0.0f, 0.0f);\n bool zero_input = params.detail == 0.0f || params.roughness == 0.0f;\n\n for (int i = 0; float(i) <= ceil(params.detail); ++i) {\n VoronoiOutput octave;\n if (params.feature == SHD_VORONOI_F2) {\n octave = voronoi_f2(params, coord * scale);\n }\n else if (params.feature == SHD_VORONOI_SMOOTH_F1 && params.smoothness != 0.0f) {\n octave = voronoi_smooth_f1(params, coord * scale);\n }\n else {\n octave = voronoi_f1(params, coord * scale);\n }\n\n if (zero_input) {\n max_amplitude = 1.0f;\n Output = octave;\n break;\n }\n else if (float(i) <= params.detail) {\n max_amplitude += amplitude;\n Output.Distance += octave.Distance * amplitude;\n Output.Color += octave.Color * amplitude;\n Output.Position = mix(Output.Position, octave.Position / scale, amplitude);\n scale *= params.lacunarity;\n amplitude *= params.roughness;\n }\n else {\n float remainder = params.detail - floor(params.detail);\n if (remainder != 0.0f) {\n max_amplitude = mix(max_amplitude, max_amplitude + amplitude, remainder);\n Output.Distance = mix(\n Output.Distance, Output.Distance + octave.Distance * amplitude, remainder);\n Output.Color = mix(Output.Color, Output.Color + octave.Color * amplitude, remainder);\n Output.Position = mix(\n Output.Position, mix(Output.Position, octave.Position / scale, amplitude), remainder);\n }\n }\n }\n\n if (params.normalize) {\n Output.Distance /= max_amplitude * params.max_distance;\n Output.Color /= max_amplitude;\n }\n\n Output.Position = safe_divide(Output.Position, params.scale);\n\n return Output;\n}\n\nFRACTAL_VORONOI_DISTANCE_TO_EDGE_FUNCTION(float3)\nVoronoiOutput fractal_voronoi_x_fx(VoronoiParams params, float4 coord)\n{\n float amplitude = 1.0f;\n float max_amplitude = 0.0f;\n float scale = 1.0f;\n\n VoronoiOutput Output;\n Output.Distance = 0.0f;\n Output.Color = float3(0.0f, 0.0f, 0.0f);\n Output.Position = float4(0.0f, 0.0f, 0.0f, 0.0f);\n bool zero_input = params.detail == 0.0f || params.roughness == 0.0f;\n\n for (int i = 0; float(i) <= ceil(params.detail); ++i) {\n VoronoiOutput octave;\n if (params.feature == SHD_VORONOI_F2) {\n octave = voronoi_f2(params, coord * scale);\n }\n else if (params.feature == SHD_VORONOI_SMOOTH_F1 && params.smoothness != 0.0f) {\n octave = voronoi_smooth_f1(params, coord * scale);\n }\n else {\n octave = voronoi_f1(params, coord * scale);\n }\n\n if (zero_input) {\n max_amplitude = 1.0f;\n Output = octave;\n break;\n }\n else if (float(i) <= params.detail) {\n max_amplitude += amplitude;\n Output.Distance += octave.Distance * amplitude;\n Output.Color += octave.Color * amplitude;\n Output.Position = mix(Output.Position, octave.Position / scale, amplitude);\n scale *= params.lacunarity;\n amplitude *= params.roughness;\n }\n else {\n float remainder = params.detail - floor(params.detail);\n if (remainder != 0.0f) {\n max_amplitude = mix(max_amplitude, max_amplitude + amplitude, remainder);\n Output.Distance = mix(\n Output.Distance, Output.Distance + octave.Distance * amplitude, remainder);\n Output.Color = mix(Output.Color, Output.Color + octave.Color * amplitude, remainder);\n Output.Position = mix(\n Output.Position, mix(Output.Position, octave.Position / scale, amplitude), remainder);\n }\n }\n }\n\n if (params.normalize) {\n Output.Distance /= max_amplitude * params.max_distance;\n Output.Color /= max_amplitude;\n }\n\n Output.Position = safe_divide(Output.Position, params.scale);\n\n return Output;\n}\n\nFRACTAL_VORONOI_DISTANCE_TO_EDGE_FUNCTION(float4)"
|
|
284
|
+
},
|
|
285
|
+
"gpu_shader_material_voronoi.glsl": {
|
|
286
|
+
"deps": [
|
|
287
|
+
"gpu_shader_math_constants_lib.glsl",
|
|
288
|
+
"gpu_shader_common_hash.glsl",
|
|
289
|
+
"gpu_shader_utildefines_lib.glsl"
|
|
290
|
+
],
|
|
291
|
+
"code": "#define SHD_VORONOI_EUCLIDEAN 0\n#define SHD_VORONOI_MANHATTAN 1\n#define SHD_VORONOI_CHEBYCHEV 2\n#define SHD_VORONOI_MINKOWSKI 3\n\n#define SHD_VORONOI_F1 0\n#define SHD_VORONOI_F2 1\n#define SHD_VORONOI_SMOOTH_F1 2\n#define SHD_VORONOI_DISTANCE_TO_EDGE 3\n#define SHD_VORONOI_N_SPHERE_RADIUS 4\n\nstruct VoronoiParams {\n float scale;\n float detail;\n float roughness;\n float lacunarity;\n float smoothness;\n float exponent;\n float randomness;\n float max_distance;\n bool normalize;\n int feature;\n int metric;\n};\n VoronoiParams VoronoiParams_ctor_() {VoronoiParams r;r.scale=0.0f;r.detail=0.0f;r.roughness=0.0f;r.lacunarity=0.0f;r.smoothness=0.0f;r.exponent=0.0f;r.randomness=0.0f;r.max_distance=0.0f;r.normalize=false;r.feature=0;r.metric=0;return r;}\nstruct VoronoiOutput {\n float Distance;\n float3 Color;\n float4 Position;\n};\n VoronoiOutput VoronoiOutput_ctor_() {VoronoiOutput r;r.Distance=0.0f;r.Color=float3(0);r.Position=float4(0);return r;}\nfloat voronoi_distance(float a, float b)\n{\n return abs(a - b);\n}\n\nfloat voronoi_distance(float2 a, float2 b, VoronoiParams params)\n{\n if (params.metric == SHD_VORONOI_EUCLIDEAN) {\n return distance(a, b);\n }\n else if (params.metric == SHD_VORONOI_MANHATTAN) {\n return abs(a.x - b.x) + abs(a.y - b.y);\n }\n else if (params.metric == SHD_VORONOI_CHEBYCHEV) {\n return max(abs(a.x - b.x), abs(a.y - b.y));\n }\n else if (params.metric == SHD_VORONOI_MINKOWSKI) {\n return pow(pow(abs(a.x - b.x), params.exponent) + pow(abs(a.y - b.y), params.exponent),\n 1.0f / params.exponent);\n }\n else {\n return 0.0f;\n }\n}\n\nfloat voronoi_distance(float3 a, float3 b, VoronoiParams params)\n{\n if (params.metric == SHD_VORONOI_EUCLIDEAN) {\n return distance(a, b);\n }\n else if (params.metric == SHD_VORONOI_MANHATTAN) {\n return abs(a.x - b.x) + abs(a.y - b.y) + abs(a.z - b.z);\n }\n else if (params.metric == SHD_VORONOI_CHEBYCHEV) {\n return max(abs(a.x - b.x), max(abs(a.y - b.y), abs(a.z - b.z)));\n }\n else if (params.metric == SHD_VORONOI_MINKOWSKI) {\n return pow(pow(abs(a.x - b.x), params.exponent) + pow(abs(a.y - b.y), params.exponent) +\n pow(abs(a.z - b.z), params.exponent),\n 1.0f / params.exponent);\n }\n else {\n return 0.0f;\n }\n}\n\nfloat voronoi_distance(float4 a, float4 b, VoronoiParams params)\n{\n if (params.metric == SHD_VORONOI_EUCLIDEAN) {\n return distance(a, b);\n }\n else if (params.metric == SHD_VORONOI_MANHATTAN) {\n return abs(a.x - b.x) + abs(a.y - b.y) + abs(a.z - b.z) + abs(a.w - b.w);\n }\n else if (params.metric == SHD_VORONOI_CHEBYCHEV) {\n return max(abs(a.x - b.x), max(abs(a.y - b.y), max(abs(a.z - b.z), abs(a.w - b.w))));\n }\n else if (params.metric == SHD_VORONOI_MINKOWSKI) {\n return pow(pow(abs(a.x - b.x), params.exponent) + pow(abs(a.y - b.y), params.exponent) +\n pow(abs(a.z - b.z), params.exponent) + pow(abs(a.w - b.w), params.exponent),\n 1.0f / params.exponent);\n }\n else {\n return 0.0f;\n }\n}\nfloat4 voronoi_position(float coord)\n{\n return float4(0.0f, 0.0f, 0.0f, coord);\n}\n\nVoronoiOutput voronoi_f1(VoronoiParams params, float coord)\n{\n float cellPosition = floor(coord);\n float localPosition = coord - cellPosition;\n\n float minDistance = FLT_MAX;\n float targetOffset = 0.0f;\n float targetPosition = 0.0f;\n for (int i = -1; i <= 1; i++) {\n float cellOffset = float(i);\n float pointPosition = cellOffset +\n hash_float_to_float(cellPosition + cellOffset) * params.randomness;\n float distanceToPoint = voronoi_distance(pointPosition, localPosition);\n if (distanceToPoint < minDistance) {\n targetOffset = cellOffset;\n minDistance = distanceToPoint;\n targetPosition = pointPosition;\n }\n }\n\n VoronoiOutput octave;\n octave.Distance = minDistance;\n octave.Color = hash_float_to_vec3(cellPosition + targetOffset);\n octave.Position = voronoi_position(targetPosition + cellPosition);\n return octave;\n}\n\nVoronoiOutput voronoi_smooth_f1(VoronoiParams params, float coord)\n{\n float cellPosition = floor(coord);\n float localPosition = coord - cellPosition;\n\n float smoothDistance = 0.0f;\n float smoothPosition = 0.0f;\n float3 smoothColor = float3(0.0f);\n float h = -1.0f;\n for (int i = -2; i <= 2; i++) {\n float cellOffset = float(i);\n float pointPosition = cellOffset +\n hash_float_to_float(cellPosition + cellOffset) * params.randomness;\n float distanceToPoint = voronoi_distance(pointPosition, localPosition);\n h = h == -1.0f ?\n 1.0f :\n smoothstep(\n 0.0f, 1.0f, 0.5f + 0.5f * (smoothDistance - distanceToPoint) / params.smoothness);\n float correctionFactor = params.smoothness * h * (1.0f - h);\n smoothDistance = mix(smoothDistance, distanceToPoint, h) - correctionFactor;\n correctionFactor /= 1.0f + 3.0f * params.smoothness;\n float3 cellColor = hash_float_to_vec3(cellPosition + cellOffset);\n smoothColor = mix(smoothColor, cellColor, h) - correctionFactor;\n smoothPosition = mix(smoothPosition, pointPosition, h) - correctionFactor;\n }\n\n VoronoiOutput octave;\n octave.Distance = smoothDistance;\n octave.Color = smoothColor;\n octave.Position = voronoi_position(cellPosition + smoothPosition);\n return octave;\n}\n\nVoronoiOutput voronoi_f2(VoronoiParams params, float coord)\n{\n float cellPosition = floor(coord);\n float localPosition = coord - cellPosition;\n\n float distanceF1 = FLT_MAX;\n float distanceF2 = FLT_MAX;\n float offsetF1 = 0.0f;\n float positionF1 = 0.0f;\n float offsetF2 = 0.0f;\n float positionF2 = 0.0f;\n for (int i = -1; i <= 1; i++) {\n float cellOffset = float(i);\n float pointPosition = cellOffset +\n hash_float_to_float(cellPosition + cellOffset) * params.randomness;\n float distanceToPoint = voronoi_distance(pointPosition, localPosition);\n if (distanceToPoint < distanceF1) {\n distanceF2 = distanceF1;\n distanceF1 = distanceToPoint;\n offsetF2 = offsetF1;\n offsetF1 = cellOffset;\n positionF2 = positionF1;\n positionF1 = pointPosition;\n }\n else if (distanceToPoint < distanceF2) {\n distanceF2 = distanceToPoint;\n offsetF2 = cellOffset;\n positionF2 = pointPosition;\n }\n }\n\n VoronoiOutput octave;\n octave.Distance = distanceF2;\n octave.Color = hash_float_to_vec3(cellPosition + offsetF2);\n octave.Position = voronoi_position(positionF2 + cellPosition);\n return octave;\n}\n\nfloat voronoi_distance_to_edge(VoronoiParams params, float coord)\n{\n float cellPosition = floor(coord);\n float localPosition = coord - cellPosition;\n\n float midPointPosition = hash_float_to_float(cellPosition) * params.randomness;\n float leftPointPosition = -1.0f + hash_float_to_float(cellPosition - 1.0f) * params.randomness;\n float rightPointPosition = 1.0f + hash_float_to_float(cellPosition + 1.0f) * params.randomness;\n float distanceToMidLeft = abs((midPointPosition + leftPointPosition) / 2.0f - localPosition);\n float distanceToMidRight = abs((midPointPosition + rightPointPosition) / 2.0f - localPosition);\n\n return min(distanceToMidLeft, distanceToMidRight);\n}\n\nfloat voronoi_n_sphere_radius(VoronoiParams params, float coord)\n{\n float cellPosition = floor(coord);\n float localPosition = coord - cellPosition;\n\n float closestPoint = 0.0f;\n float closestPointOffset = 0.0f;\n float minDistance = FLT_MAX;\n for (int i = -1; i <= 1; i++) {\n float cellOffset = float(i);\n float pointPosition = cellOffset +\n hash_float_to_float(cellPosition + cellOffset) * params.randomness;\n float distanceToPoint = abs(pointPosition - localPosition);\n if (distanceToPoint < minDistance) {\n minDistance = distanceToPoint;\n closestPoint = pointPosition;\n closestPointOffset = cellOffset;\n }\n }\n\n minDistance = FLT_MAX;\n float closestPointToClosestPoint = 0.0f;\n for (int i = -1; i <= 1; i++) {\n if (i == 0) {\n continue;\n }\n float cellOffset = float(i) + closestPointOffset;\n float pointPosition = cellOffset +\n hash_float_to_float(cellPosition + cellOffset) * params.randomness;\n float distanceToPoint = abs(closestPoint - pointPosition);\n if (distanceToPoint < minDistance) {\n minDistance = distanceToPoint;\n closestPointToClosestPoint = pointPosition;\n }\n }\n\n return abs(closestPointToClosestPoint - closestPoint) / 2.0f;\n}\nfloat4 voronoi_position(float2 coord)\n{\n return float4(coord.x, coord.y, 0.0f, 0.0f);\n}\n\nVoronoiOutput voronoi_f1(VoronoiParams params, float2 coord)\n{\n float2 cellPosition_f = floor(coord);\n float2 localPosition = coord - cellPosition_f;\n int2 cellPosition = int2(cellPosition_f);\n\n float minDistance = FLT_MAX;\n int2 targetOffset = int2(0);\n float2 targetPosition = float2(0.0f);\n for (int j = -1; j <= 1; j++) {\n for (int i = -1; i <= 1; i++) {\n int2 cellOffset = int2(i, j);\n float2 pointPosition = float2(cellOffset) +\n hash_int2_to_vec2(cellPosition + cellOffset) * params.randomness;\n float distanceToPoint = voronoi_distance(pointPosition, localPosition, params);\n if (distanceToPoint < minDistance) {\n targetOffset = cellOffset;\n minDistance = distanceToPoint;\n targetPosition = pointPosition;\n }\n }\n }\n\n VoronoiOutput octave;\n octave.Distance = minDistance;\n octave.Color = hash_int2_to_vec3(cellPosition + targetOffset);\n octave.Position = voronoi_position(targetPosition + cellPosition_f);\n return octave;\n}\n\nVoronoiOutput voronoi_smooth_f1(VoronoiParams params, float2 coord)\n{\n float2 cellPosition_f = floor(coord);\n float2 localPosition = coord - cellPosition_f;\n int2 cellPosition = int2(cellPosition_f);\n\n float smoothDistance = 0.0f;\n float3 smoothColor = float3(0.0f);\n float2 smoothPosition = float2(0.0f);\n float h = -1.0f;\n for (int j = -2; j <= 2; j++) {\n for (int i = -2; i <= 2; i++) {\n int2 cellOffset = int2(i, j);\n float2 pointPosition = float2(cellOffset) +\n hash_int2_to_vec2(cellPosition + cellOffset) * params.randomness;\n float distanceToPoint = voronoi_distance(pointPosition, localPosition, params);\n h = h == -1.0f ?\n 1.0f :\n smoothstep(0.0f,\n 1.0f,\n 0.5f + 0.5f * (smoothDistance - distanceToPoint) / params.smoothness);\n float correctionFactor = params.smoothness * h * (1.0f - h);\n smoothDistance = mix(smoothDistance, distanceToPoint, h) - correctionFactor;\n correctionFactor /= 1.0f + 3.0f * params.smoothness;\n float3 cellColor = hash_int2_to_vec3(cellPosition + cellOffset);\n smoothColor = mix(smoothColor, cellColor, h) - correctionFactor;\n smoothPosition = mix(smoothPosition, pointPosition, h) - correctionFactor;\n }\n }\n\n VoronoiOutput octave;\n octave.Distance = smoothDistance;\n octave.Color = smoothColor;\n octave.Position = voronoi_position(cellPosition_f + smoothPosition);\n return octave;\n}\n\nVoronoiOutput voronoi_f2(VoronoiParams params, float2 coord)\n{\n float2 cellPosition_f = floor(coord);\n float2 localPosition = coord - cellPosition_f;\n int2 cellPosition = int2(cellPosition_f);\n\n float distanceF1 = FLT_MAX;\n float distanceF2 = FLT_MAX;\n int2 offsetF1 = int2(0);\n float2 positionF1 = float2(0.0f);\n int2 offsetF2 = int2(0);\n float2 positionF2 = float2(0.0f);\n for (int j = -1; j <= 1; j++) {\n for (int i = -1; i <= 1; i++) {\n int2 cellOffset = int2(i, j);\n float2 pointPosition = float2(cellOffset) +\n hash_int2_to_vec2(cellPosition + cellOffset) * params.randomness;\n float distanceToPoint = voronoi_distance(pointPosition, localPosition, params);\n if (distanceToPoint < distanceF1) {\n distanceF2 = distanceF1;\n distanceF1 = distanceToPoint;\n offsetF2 = offsetF1;\n offsetF1 = cellOffset;\n positionF2 = positionF1;\n positionF1 = pointPosition;\n }\n else if (distanceToPoint < distanceF2) {\n distanceF2 = distanceToPoint;\n offsetF2 = cellOffset;\n positionF2 = pointPosition;\n }\n }\n }\n\n VoronoiOutput octave;\n octave.Distance = distanceF2;\n octave.Color = hash_int2_to_vec3(cellPosition + offsetF2);\n octave.Position = voronoi_position(positionF2 + cellPosition_f);\n return octave;\n}\n\nfloat voronoi_distance_to_edge(VoronoiParams params, float2 coord)\n{\n float2 cellPosition_f = floor(coord);\n float2 localPosition = coord - cellPosition_f;\n int2 cellPosition = int2(cellPosition_f);\n\n float2 vectorToClosest = float2(0.0f);\n float minDistance = FLT_MAX;\n for (int j = -1; j <= 1; j++) {\n for (int i = -1; i <= 1; i++) {\n int2 cellOffset = int2(i, j);\n float2 vectorToPoint = float2(cellOffset) +\n hash_int2_to_vec2(cellPosition + cellOffset) * params.randomness -\n localPosition;\n float distanceToPoint = dot(vectorToPoint, vectorToPoint);\n if (distanceToPoint < minDistance) {\n minDistance = distanceToPoint;\n vectorToClosest = vectorToPoint;\n }\n }\n }\n\n minDistance = FLT_MAX;\n for (int j = -1; j <= 1; j++) {\n for (int i = -1; i <= 1; i++) {\n int2 cellOffset = int2(i, j);\n float2 vectorToPoint = float2(cellOffset) +\n hash_int2_to_vec2(cellPosition + cellOffset) * params.randomness -\n localPosition;\n float2 perpendicularToEdge = vectorToPoint - vectorToClosest;\n if (dot(perpendicularToEdge, perpendicularToEdge) > 0.0001f) {\n float distanceToEdge = dot((vectorToClosest + vectorToPoint) / 2.0f,\n normalize(perpendicularToEdge));\n minDistance = min(minDistance, distanceToEdge);\n }\n }\n }\n\n return minDistance;\n}\n\nfloat voronoi_n_sphere_radius(VoronoiParams params, float2 coord)\n{\n float2 cellPosition_f = floor(coord);\n float2 localPosition = coord - cellPosition_f;\n int2 cellPosition = int2(cellPosition_f);\n\n float2 closestPoint = float2(0.0f);\n int2 closestPointOffset = int2(0);\n float minDistance = FLT_MAX;\n for (int j = -1; j <= 1; j++) {\n for (int i = -1; i <= 1; i++) {\n int2 cellOffset = int2(i, j);\n float2 pointPosition = float2(cellOffset) +\n hash_int2_to_vec2(cellPosition + cellOffset) * params.randomness;\n float distanceToPoint = distance(pointPosition, localPosition);\n if (distanceToPoint < minDistance) {\n minDistance = distanceToPoint;\n closestPoint = pointPosition;\n closestPointOffset = cellOffset;\n }\n }\n }\n\n minDistance = FLT_MAX;\n float2 closestPointToClosestPoint = float2(0.0f);\n for (int j = -1; j <= 1; j++) {\n for (int i = -1; i <= 1; i++) {\n if (i == 0 && j == 0) {\n continue;\n }\n int2 cellOffset = int2(i, j) + closestPointOffset;\n float2 pointPosition = float2(cellOffset) +\n hash_int2_to_vec2(cellPosition + cellOffset) * params.randomness;\n float distanceToPoint = distance(closestPoint, pointPosition);\n if (distanceToPoint < minDistance) {\n minDistance = distanceToPoint;\n closestPointToClosestPoint = pointPosition;\n }\n }\n }\n\n return distance(closestPointToClosestPoint, closestPoint) / 2.0f;\n}\nfloat4 voronoi_position(float3 coord)\n{\n return float4(coord.x, coord.y, coord.z, 0.0f);\n}\n\nVoronoiOutput voronoi_f1(VoronoiParams params, float3 coord)\n{\n float3 cellPosition_f = floor(coord);\n float3 localPosition = coord - cellPosition_f;\n int3 cellPosition = int3(cellPosition_f);\n\n float minDistance = FLT_MAX;\n int3 targetOffset = int3(0);\n float3 targetPosition = float3(0.0f);\n for (int k = -1; k <= 1; k++) {\n for (int j = -1; j <= 1; j++) {\n for (int i = -1; i <= 1; i++) {\n int3 cellOffset = int3(i, j, k);\n float3 pointPosition = float3(cellOffset) +\n hash_int3_to_vec3(cellPosition + cellOffset) * params.randomness;\n float distanceToPoint = voronoi_distance(pointPosition, localPosition, params);\n if (distanceToPoint < minDistance) {\n targetOffset = cellOffset;\n minDistance = distanceToPoint;\n targetPosition = pointPosition;\n }\n }\n }\n }\n\n VoronoiOutput octave;\n octave.Distance = minDistance;\n octave.Color = hash_int3_to_vec3(cellPosition + targetOffset);\n octave.Position = voronoi_position(targetPosition + cellPosition_f);\n return octave;\n}\n\nVoronoiOutput voronoi_smooth_f1(VoronoiParams params, float3 coord)\n{\n float3 cellPosition_f = floor(coord);\n float3 localPosition = coord - cellPosition_f;\n int3 cellPosition = int3(cellPosition_f);\n\n float smoothDistance = 0.0f;\n float3 smoothColor = float3(0.0f);\n float3 smoothPosition = float3(0.0f);\n float h = -1.0f;\n for (int k = -2; k <= 2; k++) {\n for (int j = -2; j <= 2; j++) {\n for (int i = -2; i <= 2; i++) {\n int3 cellOffset = int3(i, j, k);\n float3 pointPosition = float3(cellOffset) +\n hash_int3_to_vec3(cellPosition + cellOffset) * params.randomness;\n float distanceToPoint = voronoi_distance(pointPosition, localPosition, params);\n h = h == -1.0f ?\n 1.0f :\n smoothstep(0.0f,\n 1.0f,\n 0.5f + 0.5f * (smoothDistance - distanceToPoint) / params.smoothness);\n float correctionFactor = params.smoothness * h * (1.0f - h);\n smoothDistance = mix(smoothDistance, distanceToPoint, h) - correctionFactor;\n correctionFactor /= 1.0f + 3.0f * params.smoothness;\n float3 cellColor = hash_int3_to_vec3(cellPosition + cellOffset);\n smoothColor = mix(smoothColor, cellColor, h) - correctionFactor;\n smoothPosition = mix(smoothPosition, pointPosition, h) - correctionFactor;\n }\n }\n }\n\n VoronoiOutput octave;\n octave.Distance = smoothDistance;\n octave.Color = smoothColor;\n octave.Position = voronoi_position(cellPosition_f + smoothPosition);\n return octave;\n}\n\nVoronoiOutput voronoi_f2(VoronoiParams params, float3 coord)\n{\n float3 cellPosition_f = floor(coord);\n float3 localPosition = coord - cellPosition_f;\n int3 cellPosition = int3(cellPosition_f);\n\n float distanceF1 = FLT_MAX;\n float distanceF2 = FLT_MAX;\n int3 offsetF1 = int3(0);\n float3 positionF1 = float3(0.0f);\n int3 offsetF2 = int3(0);\n float3 positionF2 = float3(0.0f);\n for (int k = -1; k <= 1; k++) {\n for (int j = -1; j <= 1; j++) {\n for (int i = -1; i <= 1; i++) {\n int3 cellOffset = int3(i, j, k);\n float3 pointPosition = float3(cellOffset) +\n hash_int3_to_vec3(cellPosition + cellOffset) * params.randomness;\n float distanceToPoint = voronoi_distance(pointPosition, localPosition, params);\n if (distanceToPoint < distanceF1) {\n distanceF2 = distanceF1;\n distanceF1 = distanceToPoint;\n offsetF2 = offsetF1;\n offsetF1 = cellOffset;\n positionF2 = positionF1;\n positionF1 = pointPosition;\n }\n else if (distanceToPoint < distanceF2) {\n distanceF2 = distanceToPoint;\n offsetF2 = cellOffset;\n positionF2 = pointPosition;\n }\n }\n }\n }\n\n VoronoiOutput octave;\n octave.Distance = distanceF2;\n octave.Color = hash_int3_to_vec3(cellPosition + offsetF2);\n octave.Position = voronoi_position(positionF2 + cellPosition_f);\n return octave;\n}\n\nfloat voronoi_distance_to_edge(VoronoiParams params, float3 coord)\n{\n float3 cellPosition_f = floor(coord);\n float3 localPosition = coord - cellPosition_f;\n int3 cellPosition = int3(cellPosition_f);\n\n float3 vectorToClosest = float3(0.0f);\n float minDistance = FLT_MAX;\n for (int k = -1; k <= 1; k++) {\n for (int j = -1; j <= 1; j++) {\n for (int i = -1; i <= 1; i++) {\n int3 cellOffset = int3(i, j, k);\n float3 vectorToPoint = float3(cellOffset) +\n hash_int3_to_vec3(cellPosition + cellOffset) * params.randomness -\n localPosition;\n float distanceToPoint = dot(vectorToPoint, vectorToPoint);\n if (distanceToPoint < minDistance) {\n minDistance = distanceToPoint;\n vectorToClosest = vectorToPoint;\n }\n }\n }\n }\n\n minDistance = FLT_MAX;\n for (int k = -1; k <= 1; k++) {\n for (int j = -1; j <= 1; j++) {\n for (int i = -1; i <= 1; i++) {\n int3 cellOffset = int3(i, j, k);\n float3 vectorToPoint = float3(cellOffset) +\n hash_int3_to_vec3(cellPosition + cellOffset) * params.randomness -\n localPosition;\n float3 perpendicularToEdge = vectorToPoint - vectorToClosest;\n if (dot(perpendicularToEdge, perpendicularToEdge) > 0.0001f) {\n float distanceToEdge = dot((vectorToClosest + vectorToPoint) / 2.0f,\n normalize(perpendicularToEdge));\n minDistance = min(minDistance, distanceToEdge);\n }\n }\n }\n }\n\n return minDistance;\n}\n\nfloat voronoi_n_sphere_radius(VoronoiParams params, float3 coord)\n{\n float3 cellPosition_f = floor(coord);\n float3 localPosition = coord - cellPosition_f;\n int3 cellPosition = int3(cellPosition_f);\n\n float3 closestPoint = float3(0.0f);\n int3 closestPointOffset = int3(0);\n float minDistance = FLT_MAX;\n for (int k = -1; k <= 1; k++) {\n for (int j = -1; j <= 1; j++) {\n for (int i = -1; i <= 1; i++) {\n int3 cellOffset = int3(i, j, k);\n float3 pointPosition = float3(cellOffset) +\n hash_int3_to_vec3(cellPosition + cellOffset) * params.randomness;\n float distanceToPoint = distance(pointPosition, localPosition);\n if (distanceToPoint < minDistance) {\n minDistance = distanceToPoint;\n closestPoint = pointPosition;\n closestPointOffset = cellOffset;\n }\n }\n }\n }\n\n minDistance = FLT_MAX;\n float3 closestPointToClosestPoint = float3(0.0f);\n for (int k = -1; k <= 1; k++) {\n for (int j = -1; j <= 1; j++) {\n for (int i = -1; i <= 1; i++) {\n if (i == 0 && j == 0 && k == 0) {\n continue;\n }\n int3 cellOffset = int3(i, j, k) + closestPointOffset;\n float3 pointPosition = float3(cellOffset) +\n hash_int3_to_vec3(cellPosition + cellOffset) * params.randomness;\n float distanceToPoint = distance(closestPoint, pointPosition);\n if (distanceToPoint < minDistance) {\n minDistance = distanceToPoint;\n closestPointToClosestPoint = pointPosition;\n }\n }\n }\n }\n\n return distance(closestPointToClosestPoint, closestPoint) / 2.0f;\n}\nfloat4 voronoi_position(float4 coord)\n{\n return coord;\n}\n\nVoronoiOutput voronoi_f1(VoronoiParams params, float4 coord)\n{\n float4 cellPosition_f = floor(coord);\n float4 localPosition = coord - cellPosition_f;\n int4 cellPosition = int4(cellPosition_f);\n\n float minDistance = FLT_MAX;\n int4 targetOffset = int4(0);\n float4 targetPosition = float4(0.0f);\n for (int u = -1; u <= 1; u++) {\n for (int k = -1; k <= 1; k++) {\n for (int j = -1; j <= 1; j++) {\n for (int i = -1; i <= 1; i++) {\n int4 cellOffset = int4(i, j, k, u);\n float4 pointPosition = float4(cellOffset) +\n hash_int4_to_vec4(cellPosition + cellOffset) * params.randomness;\n float distanceToPoint = voronoi_distance(pointPosition, localPosition, params);\n if (distanceToPoint < minDistance) {\n targetOffset = cellOffset;\n minDistance = distanceToPoint;\n targetPosition = pointPosition;\n }\n }\n }\n }\n }\n\n VoronoiOutput octave;\n octave.Distance = minDistance;\n octave.Color = hash_int4_to_vec3(cellPosition + targetOffset);\n octave.Position = voronoi_position(targetPosition + cellPosition_f);\n return octave;\n}\n\nVoronoiOutput voronoi_smooth_f1(VoronoiParams params, float4 coord)\n{\n float4 cellPosition_f = floor(coord);\n float4 localPosition = coord - cellPosition_f;\n int4 cellPosition = int4(cellPosition_f);\n\n float smoothDistance = 0.0f;\n float3 smoothColor = float3(0.0f);\n float4 smoothPosition = float4(0.0f);\n float h = -1.0f;\n for (int u = -2; u <= 2; u++) {\n for (int k = -2; k <= 2; k++) {\n for (int j = -2; j <= 2; j++) {\n for (int i = -2; i <= 2; i++) {\n int4 cellOffset = int4(i, j, k, u);\n float4 pointPosition = float4(cellOffset) +\n hash_int4_to_vec4(cellPosition + cellOffset) * params.randomness;\n float distanceToPoint = voronoi_distance(pointPosition, localPosition, params);\n h = h == -1.0f ?\n 1.0f :\n smoothstep(0.0f,\n 1.0f,\n 0.5f + 0.5f * (smoothDistance - distanceToPoint) / params.smoothness);\n float correctionFactor = params.smoothness * h * (1.0f - h);\n smoothDistance = mix(smoothDistance, distanceToPoint, h) - correctionFactor;\n correctionFactor /= 1.0f + 3.0f * params.smoothness;\n float3 cellColor = hash_int4_to_vec3(cellPosition + cellOffset);\n smoothColor = mix(smoothColor, cellColor, h) - correctionFactor;\n smoothPosition = mix(smoothPosition, pointPosition, h) - correctionFactor;\n }\n }\n }\n }\n\n VoronoiOutput octave;\n octave.Distance = smoothDistance;\n octave.Color = smoothColor;\n octave.Position = voronoi_position(cellPosition_f + smoothPosition);\n return octave;\n}\n\nVoronoiOutput voronoi_f2(VoronoiParams params, float4 coord)\n{\n float4 cellPosition_f = floor(coord);\n float4 localPosition = coord - cellPosition_f;\n int4 cellPosition = int4(cellPosition_f);\n\n float distanceF1 = FLT_MAX;\n float distanceF2 = FLT_MAX;\n int4 offsetF1 = int4(0);\n float4 positionF1 = float4(0.0f);\n int4 offsetF2 = int4(0);\n float4 positionF2 = float4(0.0f);\n for (int u = -1; u <= 1; u++) {\n for (int k = -1; k <= 1; k++) {\n for (int j = -1; j <= 1; j++) {\n for (int i = -1; i <= 1; i++) {\n int4 cellOffset = int4(i, j, k, u);\n float4 pointPosition = float4(cellOffset) +\n hash_int4_to_vec4(cellPosition + cellOffset) * params.randomness;\n float distanceToPoint = voronoi_distance(pointPosition, localPosition, params);\n if (distanceToPoint < distanceF1) {\n distanceF2 = distanceF1;\n distanceF1 = distanceToPoint;\n offsetF2 = offsetF1;\n offsetF1 = cellOffset;\n positionF2 = positionF1;\n positionF1 = pointPosition;\n }\n else if (distanceToPoint < distanceF2) {\n distanceF2 = distanceToPoint;\n offsetF2 = cellOffset;\n positionF2 = pointPosition;\n }\n }\n }\n }\n }\n\n VoronoiOutput octave;\n octave.Distance = distanceF2;\n octave.Color = hash_int4_to_vec3(cellPosition + offsetF2);\n octave.Position = voronoi_position(positionF2 + cellPosition_f);\n return octave;\n}\n\nfloat voronoi_distance_to_edge(VoronoiParams params, float4 coord)\n{\n float4 cellPosition_f = floor(coord);\n float4 localPosition = coord - cellPosition_f;\n int4 cellPosition = int4(cellPosition_f);\n\n float4 vectorToClosest = float4(0.0f);\n float minDistance = FLT_MAX;\n for (int u = -1; u <= 1; u++) {\n for (int k = -1; k <= 1; k++) {\n for (int j = -1; j <= 1; j++) {\n for (int i = -1; i <= 1; i++) {\n int4 cellOffset = int4(i, j, k, u);\n float4 vectorToPoint = float4(cellOffset) +\n hash_int4_to_vec4(cellPosition + cellOffset) * params.randomness -\n localPosition;\n float distanceToPoint = dot(vectorToPoint, vectorToPoint);\n if (distanceToPoint < minDistance) {\n minDistance = distanceToPoint;\n vectorToClosest = vectorToPoint;\n }\n }\n }\n }\n }\n\n minDistance = FLT_MAX;\n for (int u = -1; u <= 1; u++) {\n for (int k = -1; k <= 1; k++) {\n for (int j = -1; j <= 1; j++) {\n for (int i = -1; i <= 1; i++) {\n int4 cellOffset = int4(i, j, k, u);\n float4 vectorToPoint = float4(cellOffset) +\n hash_int4_to_vec4(cellPosition + cellOffset) * params.randomness -\n localPosition;\n float4 perpendicularToEdge = vectorToPoint - vectorToClosest;\n if (dot(perpendicularToEdge, perpendicularToEdge) > 0.0001f) {\n float distanceToEdge = dot((vectorToClosest + vectorToPoint) / 2.0f,\n normalize(perpendicularToEdge));\n minDistance = min(minDistance, distanceToEdge);\n }\n }\n }\n }\n }\n\n return minDistance;\n}\n\nfloat voronoi_n_sphere_radius(VoronoiParams params, float4 coord)\n{\n float4 cellPosition_f = floor(coord);\n float4 localPosition = coord - cellPosition_f;\n int4 cellPosition = int4(cellPosition_f);\n\n float4 closestPoint = float4(0.0f);\n int4 closestPointOffset = int4(0);\n float minDistance = FLT_MAX;\n for (int u = -1; u <= 1; u++) {\n for (int k = -1; k <= 1; k++) {\n for (int j = -1; j <= 1; j++) {\n for (int i = -1; i <= 1; i++) {\n int4 cellOffset = int4(i, j, k, u);\n float4 pointPosition = float4(cellOffset) +\n hash_int4_to_vec4(cellPosition + cellOffset) * params.randomness;\n float distanceToPoint = distance(pointPosition, localPosition);\n if (distanceToPoint < minDistance) {\n minDistance = distanceToPoint;\n closestPoint = pointPosition;\n closestPointOffset = cellOffset;\n }\n }\n }\n }\n }\n\n minDistance = FLT_MAX;\n float4 closestPointToClosestPoint = float4(0.0f);\n for (int u = -1; u <= 1; u++) {\n for (int k = -1; k <= 1; k++) {\n for (int j = -1; j <= 1; j++) {\n for (int i = -1; i <= 1; i++) {\n if (i == 0 && j == 0 && k == 0 && u == 0) {\n continue;\n }\n int4 cellOffset = int4(i, j, k, u) + closestPointOffset;\n float4 pointPosition = float4(cellOffset) +\n hash_int4_to_vec4(cellPosition + cellOffset) * params.randomness;\n float distanceToPoint = distance(closestPoint, pointPosition);\n if (distanceToPoint < minDistance) {\n minDistance = distanceToPoint;\n closestPointToClosestPoint = pointPosition;\n }\n }\n }\n }\n }\n\n return distance(closestPointToClosestPoint, closestPoint) / 2.0f;\n}"
|
|
292
|
+
},
|
|
293
|
+
"gpu_shader_material_tex_wave.glsl": {
|
|
294
|
+
"deps": [
|
|
295
|
+
"gpu_shader_math_constants_lib.glsl",
|
|
296
|
+
"gpu_shader_common_hash.glsl",
|
|
297
|
+
"gpu_shader_material_fractal_noise.glsl",
|
|
298
|
+
"gpu_shader_material_noise.glsl"
|
|
299
|
+
],
|
|
300
|
+
"code": "float calc_wave(float3 p,\n float distortion,\n float detail,\n float detail_scale,\n float detail_roughness,\n float phase,\n int wave_type,\n int bands_dir,\n int rings_dir,\n int wave_profile)\n{\n\n p = (p + 0.000001f) * 0.999999f;\n\n float n;\n\n if (wave_type == 0) {\n if (bands_dir == 0) {\n n = p.x * 20.0f;\n }\n else if (bands_dir == 1) {\n n = p.y * 20.0f;\n }\n else if (bands_dir == 2) {\n n = p.z * 20.0f;\n }\n else {\n n = (p.x + p.y + p.z) * 10.0f;\n }\n }\n else {\n float3 rp = p;\n if (rings_dir == 0) {\n rp *= float3(0.0f, 1.0f, 1.0f);\n }\n else if (rings_dir == 1) {\n rp *= float3(1.0f, 0.0f, 1.0f);\n }\n else if (rings_dir == 2) {\n rp *= float3(1.0f, 1.0f, 0.0f);\n }\n n = length(rp) * 20.0f;\n }\n\n n += phase;\n\n if (distortion != 0.0f) {\n n += distortion *\n (noise_fbm(p * detail_scale, detail, detail_roughness, 2.0f, 0.0f, 0.0f, true) * 2.0f -\n 1.0f);\n }\n\n if (wave_profile == 0) {\n return 0.5f + 0.5f * sin(n - M_PI_2);\n }\n else if (wave_profile == 1) {\n n /= 2.0f * M_PI;\n return n - floor(n);\n }\n else {\n n /= 2.0f * M_PI;\n return abs(n - floor(n + 0.5f)) * 2.0f;\n }\n}\nvoid node_tex_wave(float3 co,\n float scale,\n float distortion,\n float detail,\n float detail_scale,\n float detail_roughness,\n float phase,\n float wave_type,\n float bands_dir,\n float rings_dir,\n float wave_profile,\n _ref(float4 ,color),\n _ref(float ,fac))\n{\n float f;\n f = calc_wave(co * scale,\n distortion,\n detail,\n detail_scale,\n detail_roughness,\n phase,\n int(wave_type),\n int(bands_dir),\n int(rings_dir),\n int(wave_profile));\n\n color = float4(f, f, f, 1.0f);\n fac = f;\n}"
|
|
301
|
+
},
|
|
302
|
+
"gpu_shader_material_tex_white_noise.glsl": {
|
|
303
|
+
"deps": [
|
|
304
|
+
"gpu_shader_math_constants_lib.glsl",
|
|
305
|
+
"gpu_shader_common_hash.glsl"
|
|
306
|
+
],
|
|
307
|
+
"code": "void node_white_noise_1d(float3 vector, float w, _ref(float ,value), _ref(float4 ,color))\n{\n value = hash_float_to_float(w);\n color = float4(hash_float_to_vec3(w), 1.0f);\n}\nvoid node_white_noise_2d(float3 vector, float w, _ref(float ,value), _ref(float4 ,color))\n{\n value = hash_vec2_to_float(vector.xy);\n color = float4(hash_vec2_to_vec3(vector.xy), 1.0f);\n}\nvoid node_white_noise_3d(float3 vector, float w, _ref(float ,value), _ref(float4 ,color))\n{\n value = hash_vec3_to_float(vector);\n color = float4(hash_vec3_to_vec3(vector), 1.0f);\n}\nvoid node_white_noise_4d(float3 vector, float w, _ref(float ,value), _ref(float4 ,color))\n{\n value = hash_vec4_to_float(float4(vector, w));\n color = float4(hash_vec4_to_vec3(float4(vector, w)), 1.0f);\n}"
|
|
308
|
+
},
|
|
309
|
+
"gpu_shader_material_vector_math.glsl": {
|
|
310
|
+
"deps": [
|
|
311
|
+
"gpu_shader_math_constants_lib.glsl",
|
|
312
|
+
"gpu_shader_math_vector_safe_lib.glsl"
|
|
313
|
+
],
|
|
314
|
+
"code": "float3 vector_math_safe_normalize(float3 a)\n{\n\n float length_sqr = dot(a, a);\n return (length_sqr > 1e-35f) ? a * inversesqrt(length_sqr) : float3(0.0f);\n}\nvoid vector_math_add(float3 a, float3 b, float3 c, float scale, _ref(float3 ,outVector), _ref(float ,outValue))\n{\n outVector = a + b;\n}\nvoid vector_math_subtract(\n float3 a, float3 b, float3 c, float scale, _ref(float3 ,outVector), _ref(float ,outValue))\n{\n outVector = a - b;\n}\nvoid vector_math_multiply(\n float3 a, float3 b, float3 c, float scale, _ref(float3 ,outVector), _ref(float ,outValue))\n{\n outVector = a * b;\n}\nvoid vector_math_divide(\n float3 a, float3 b, float3 c, float scale, _ref(float3 ,outVector), _ref(float ,outValue))\n{\n outVector = safe_divide(a, b);\n}\nvoid vector_math_cross(\n float3 a, float3 b, float3 c, float scale, _ref(float3 ,outVector), _ref(float ,outValue))\n{\n outVector = cross(a, b);\n}\nvoid vector_math_project(\n float3 a, float3 b, float3 c, float scale, _ref(float3 ,outVector), _ref(float ,outValue))\n{\n float lenSquared = dot(b, b);\n outVector = (lenSquared != 0.0f) ? (dot(a, b) / lenSquared) * b : float3(0.0f);\n}\nvoid vector_math_reflect(\n float3 a, float3 b, float3 c, float scale, _ref(float3 ,outVector), _ref(float ,outValue))\n{\n outVector = reflect(a, vector_math_safe_normalize(b));\n}\nvoid vector_math_dot(float3 a, float3 b, float3 c, float scale, _ref(float3 ,outVector), _ref(float ,outValue))\n{\n outValue = dot(a, b);\n}\nvoid vector_math_distance(\n float3 a, float3 b, float3 c, float scale, _ref(float3 ,outVector), _ref(float ,outValue))\n{\n outValue = distance(a, b);\n}\nvoid vector_math_length(\n float3 a, float3 b, float3 c, float scale, _ref(float3 ,outVector), _ref(float ,outValue))\n{\n outValue = length(a);\n}\nvoid vector_math_scale(\n float3 a, float3 b, float3 c, float scale, _ref(float3 ,outVector), _ref(float ,outValue))\n{\n outVector = a * scale;\n}\nvoid vector_math_normalize(\n float3 a, float3 b, float3 c, float scale, _ref(float3 ,outVector), _ref(float ,outValue))\n{\n outVector = a;\n\n float lenSquared = dot(a, a);\n if (lenSquared > 0.0f) {\n outVector *= inversesqrt(lenSquared);\n }\n}\nvoid vector_math_snap(\n float3 a, float3 b, float3 c, float scale, _ref(float3 ,outVector), _ref(float ,outValue))\n{\n outVector = floor(safe_divide(a, b)) * b;\n}\nvoid vector_math_floor(\n float3 a, float3 b, float3 c, float scale, _ref(float3 ,outVector), _ref(float ,outValue))\n{\n outVector = floor(a);\n}\nvoid vector_math_ceil(\n float3 a, float3 b, float3 c, float scale, _ref(float3 ,outVector), _ref(float ,outValue))\n{\n outVector = ceil(a);\n}\nvoid vector_math_modulo(\n float3 a, float3 b, float3 c, float scale, _ref(float3 ,outVector), _ref(float ,outValue))\n{\n outVector = compatible_mod(a, b);\n}\nvoid vector_math_wrap(\n float3 a, float3 b, float3 c, float scale, _ref(float3 ,outVector), _ref(float ,outValue))\n{\n outVector = wrap(a, b, c);\n}\nvoid vector_math_fraction(\n float3 a, float3 b, float3 c, float scale, _ref(float3 ,outVector), _ref(float ,outValue))\n{\n outVector = fract(a);\n}\nvoid vector_math_absolute(\n float3 a, float3 b, float3 c, float scale, _ref(float3 ,outVector), _ref(float ,outValue))\n{\n outVector = abs(a);\n}\nvoid vector_math_power(\n float3 a, float3 b, float3 c, float scale, _ref(float3 ,outVector), _ref(float ,outValue))\n{\n outVector = compatible_pow(a, b);\n}\nvoid vector_math_sign(\n float3 a, float3 b, float3 c, float scale, _ref(float3 ,outVector), _ref(float ,outValue))\n{\n outVector = sign(a);\n}\nvoid vector_math_round(\n float3 a, float3 b, float3 c, float scale, _ref(float3 ,outVector), _ref(float ,outValue))\n{\n outVector = floor(a + 0.5f);\n}\nvoid vector_math_minimum(\n float3 a, float3 b, float3 c, float scale, _ref(float3 ,outVector), _ref(float ,outValue))\n{\n outVector = min(a, b);\n}\nvoid vector_math_maximum(\n float3 a, float3 b, float3 c, float scale, _ref(float3 ,outVector), _ref(float ,outValue))\n{\n outVector = max(a, b);\n}\nvoid vector_math_sine(\n float3 a, float3 b, float3 c, float scale, _ref(float3 ,outVector), _ref(float ,outValue))\n{\n outVector = sin(a);\n}\nvoid vector_math_cosine(\n float3 a, float3 b, float3 c, float scale, _ref(float3 ,outVector), _ref(float ,outValue))\n{\n outVector = cos(a);\n}\nvoid vector_math_tangent(\n float3 a, float3 b, float3 c, float scale, _ref(float3 ,outVector), _ref(float ,outValue))\n{\n outVector = tan(a);\n}\nvoid vector_math_refract(\n float3 a, float3 b, float3 c, float scale, _ref(float3 ,outVector), _ref(float ,outValue))\n{\n outVector = refract(a, vector_math_safe_normalize(b), scale);\n}\nvoid vector_math_faceforward(\n float3 a, float3 b, float3 c, float scale, _ref(float3 ,outVector), _ref(float ,outValue))\n{\n outVector = faceforward(a, b, c);\n}\nvoid vector_math_multiply_add(\n float3 a, float3 b, float3 c, float scale, _ref(float3 ,outVector), _ref(float ,outValue))\n{\n outVector = a * b + c;\n}"
|
|
315
|
+
},
|
|
316
|
+
"gpu_shader_material_vector_rotate.glsl": {
|
|
317
|
+
"deps": [
|
|
318
|
+
"gpu_shader_math_constants_lib.glsl",
|
|
319
|
+
"gpu_shader_math_euler_lib.glsl",
|
|
320
|
+
"gpu_shader_math_matrix_construct_lib.glsl"
|
|
321
|
+
],
|
|
322
|
+
"code": "float3 rotate_around_axis(float3 p, float3 axis, float angle)\n{\n float costheta = cos(angle);\n float sintheta = sin(angle);\n float3 r;\n\n r.x = ((costheta + (1.0f - costheta) * axis.x * axis.x) * p.x) +\n (((1.0f - costheta) * axis.x * axis.y - axis.z * sintheta) * p.y) +\n (((1.0f - costheta) * axis.x * axis.z + axis.y * sintheta) * p.z);\n\n r.y = (((1.0f - costheta) * axis.x * axis.y + axis.z * sintheta) * p.x) +\n ((costheta + (1.0f - costheta) * axis.y * axis.y) * p.y) +\n (((1.0f - costheta) * axis.y * axis.z - axis.x * sintheta) * p.z);\n\n r.z = (((1.0f - costheta) * axis.x * axis.z - axis.y * sintheta) * p.x) +\n (((1.0f - costheta) * axis.y * axis.z + axis.x * sintheta) * p.y) +\n ((costheta + (1.0f - costheta) * axis.z * axis.z) * p.z);\n\n return r;\n}\nvoid node_vector_rotate_axis_angle(float3 vector_in,\n float3 center,\n float3 axis,\n float angle,\n float3 rotation,\n float invert,\n _ref(float3 ,vec))\n{\n vec = (length(axis) != 0.0f) ?\n rotate_around_axis(vector_in - center, normalize(axis), angle * invert) + center :\n vector_in;\n}\nvoid node_vector_rotate_axis_x(float3 vector_in,\n float3 center,\n float3 axis,\n float angle,\n float3 rotation,\n float invert,\n _ref(float3 ,vec))\n{\n vec = rotate_around_axis(vector_in - center, float3(1.0f, 0.0f, 0.0f), angle * invert) + center;\n}\nvoid node_vector_rotate_axis_y(float3 vector_in,\n float3 center,\n float3 axis,\n float angle,\n float3 rotation,\n float invert,\n _ref(float3 ,vec))\n{\n vec = rotate_around_axis(vector_in - center, float3(0.0f, 1.0f, 0.0f), angle * invert) + center;\n}\nvoid node_vector_rotate_axis_z(float3 vector_in,\n float3 center,\n float3 axis,\n float angle,\n float3 rotation,\n float invert,\n _ref(float3 ,vec))\n{\n vec = rotate_around_axis(vector_in - center, float3(0.0f, 0.0f, 1.0f), angle * invert) + center;\n}\nvoid node_vector_rotate_euler_xyz(float3 vector_in,\n float3 center,\n float3 axis,\n float angle,\n float3 rotation,\n float invert,\n _ref(float3 ,vec))\n{\n float3x3 rmat = (invert < 0.0f) ? transpose(from_rotation(EulerXYZ_from_float3(rotation))) :\n from_rotation(EulerXYZ_from_float3(rotation));\n vec = rmat * (vector_in - center) + center;\n}"
|
|
323
|
+
},
|
|
324
|
+
"gpu_shader_material_normal_map.glsl": {
|
|
325
|
+
"deps": [
|
|
326
|
+
"gpu_shader_math_constants_lib.glsl"
|
|
327
|
+
],
|
|
328
|
+
"code": "void input_normal_displaced(_ref(float3 ,outnormal))\n{\n#ifdef MAT_DISPLACEMENT_BUMP\n outnormal = g_data.N;\n#else\n outnormal = g_data.Ni;\n#endif\n}\nvoid input_normal_original(_ref(float3 ,outnormal))\n{\n outnormal = g_data.Ni;\n}\nvoid node_normal_map(\n float4 tangent, float strength, float3 texnormal, float3 input_normal, _ref(float3 ,outnormal))\n{\n if (all(equal(tangent, float4(0.0f, 0.0f, 0.0f, 1.0f)))) {\n outnormal = input_normal;\n return;\n }\n tangent *= (FrontFacing ? 1.0f : -1.0f);\n float3 B = tangent.w * cross(input_normal, tangent.xyz);\n B *= (object_infos_get().flag & OBJECT_NEGATIVE_SCALE) != 0u ? -1.0f : 1.0f;\n texnormal.xy *= strength;\n texnormal.z = mix(1.0f, texnormal.z, clamp(strength, 0.0f, 1.0f));\n\n outnormal = texnormal.x * tangent.xyz + texnormal.y * B + texnormal.z * input_normal;\n outnormal = normalize(outnormal);\n}\nvoid color_to_normal_new_shading(float3 color, _ref(float3 ,normal))\n{\n normal = float3(2.0f) * color - float3(1.0f);\n}\nvoid color_to_blender_normal_new_shading(float3 color, _ref(float3 ,normal))\n{\n normal = float3(2.0f, -2.0f, -2.0f) * color - float3(1.0f);\n}\nvoid color_invert_green_channel(float3 color, _ref(float3 ,result))\n{\n result = float3(color.x, -color.y, color.z);\n}\nvoid node_normal_map_mix(float strength, float3 newnormal, _ref(float3 ,outnormal))\n{\n outnormal = normalize(mix(g_data.N, newnormal, max(0.0f, strength)));\n}"
|
|
329
|
+
},
|
|
330
|
+
"gpu_shader_material_bump.glsl": {
|
|
331
|
+
"deps": [
|
|
332
|
+
"gpu_shader_math_constants_lib.glsl"
|
|
333
|
+
],
|
|
334
|
+
"code": "void differentiate_texco(float3 v, _ref(float3 ,df))\n{\n\n df = v + dF_impl(v);\n}\nvoid differentiate_texco(float4 v, _ref(float3 ,df))\n{\n\n df = v.xyz + dF_impl(v.xyz);\n}\nvoid node_bump(float strength,\n float dist,\n float filter_width,\n float height,\n float3 N,\n float2 height_xy,\n float invert,\n _ref(float3 ,result))\n{\n N = normalize(N);\n dist *= FrontFacing ? invert : -invert;\n\n#ifdef GPU_FRAGMENT_SHADER\n float3 dPdx = gpu_dfdx(g_data.P) * derivative_scale_get();\n float3 dPdy = gpu_dfdy(g_data.P) * derivative_scale_get();\n float3 Rx = cross(dPdy, N);\n float3 Ry = cross(N, dPdx);\n float det = dot(dPdx, Rx);\n\n float2 dHd = height_xy - float2(height);\n float3 surfgrad = dHd.x * Rx + dHd.y * Ry;\n\n strength = max(strength, 0.0f);\n\n result = normalize(filter_width * abs(det) * N - dist * sign(det) * surfgrad);\n result = normalize(mix(N, result, strength));\n#else\n result = N;\n#endif\n}"
|
|
335
|
+
},
|
|
336
|
+
"gpu_shader_material_geometry.glsl": {
|
|
337
|
+
"deps": [
|
|
338
|
+
"gpu_shader_math_constants_lib.glsl",
|
|
339
|
+
"gpu_shader_material_tangent.glsl"
|
|
340
|
+
],
|
|
341
|
+
"code": "void node_geometry(float3 orco_attr,\n _ref(float3 ,position),\n _ref(float3 ,normal),\n _ref(float3 ,tangent),\n _ref(float3 ,true_normal),\n _ref(float3 ,incoming),\n _ref(float3 ,parametric),\n _ref(float ,backfacing),\n _ref(float ,pointiness),\n _ref(float ,random_per_island))\n{\n\n incoming = coordinate_incoming(g_data.P);\n position = g_data.P;\n normal = g_data.N;\n true_normal = g_data.Ng;\n\n if (g_data.is_strand) {\n tangent = g_data.curve_T;\n }\n else {\n tangent_orco_z(orco_attr, orco_attr);\n node_tangent(orco_attr, tangent);\n }\n\n parametric = float3(g_data.barycentric_coords, 0.0f);\n backfacing = (FrontFacing) ? 0.0f : 1.0f;\n pointiness = 0.5f;\n random_per_island = 0.0f;\n}"
|
|
342
|
+
},
|
|
343
|
+
"gpu_shader_material_tangent.glsl": {
|
|
344
|
+
"deps": [
|
|
345
|
+
"gpu_shader_math_constants_lib.glsl",
|
|
346
|
+
"gpu_shader_material_transform_utils.glsl"
|
|
347
|
+
],
|
|
348
|
+
"code": "void tangent_orco_x(float3 orco_in, _ref(float3 ,orco_out))\n{\n orco_out = orco_in.xzy * float3(0.0f, -0.5f, 0.5f) + float3(0.0f, 0.25f, -0.25f);\n}\nvoid tangent_orco_y(float3 orco_in, _ref(float3 ,orco_out))\n{\n orco_out = orco_in.zyx * float3(-0.5f, 0.0f, 0.5f) + float3(0.25f, 0.0f, -0.25f);\n}\nvoid tangent_orco_z(float3 orco_in, _ref(float3 ,orco_out))\n{\n orco_out = orco_in.yxz * float3(-0.5f, 0.5f, 0.0f) + float3(0.25f, -0.25f, 0.0f);\n}\nvoid node_tangentmap(float4 attr_tangent, _ref(float3 ,tangent))\n{\n tangent = normalize(attr_tangent.xyz);\n}\nvoid node_tangent(float3 orco, _ref(float3 ,T))\n{\n direction_transform_object_to_world(orco, T);\n T = cross(g_data.N, normalize(cross(T, g_data.N)));\n}"
|
|
349
|
+
},
|
|
350
|
+
"gpu_shader_material_transform_utils.glsl": {
|
|
351
|
+
"deps": [
|
|
352
|
+
"gpu_shader_math_constants_lib.glsl"
|
|
353
|
+
],
|
|
354
|
+
"code": "void normal_transform_object_to_world(float3 vin, _ref(float3 ,vout))\n{\n ObjectMatrices obj = object_matrices_get();\n\n vout = vin * to_float3x3(obj.model_inverse);\n}\nvoid normal_transform_world_to_object(float3 vin, _ref(float3 ,vout))\n{\n ObjectMatrices obj = object_matrices_get();\n\n vout = vin * to_float3x3(obj.model);\n}\nvoid normal_transform_object_to_view(float3 vin, _ref(float3 ,vout))\n{\n ObjectMatrices obj = object_matrices_get();\n ViewMatrices view = view_matrices_get();\n vout = vin * to_float3x3(obj.model_inverse);\n vout = to_float3x3(view.viewmat) * vout;\n}\nvoid normal_transform_view_to_world(float3 vin, _ref(float3 ,vout))\n{\n ViewMatrices view = view_matrices_get();\n vout = to_float3x3(view.viewinv) * vin;\n}\nvoid normal_transform_view_to_object(float3 vin, _ref(float3 ,vout))\n{\n ObjectMatrices obj = object_matrices_get();\n ViewMatrices view = view_matrices_get();\n vout = to_float3x3(view.viewinv) * vin;\n vout = vout * to_float3x3(obj.model);\n}\nvoid normal_transform_world_to_view(float3 vin, _ref(float3 ,vout))\n{\n ViewMatrices view = view_matrices_get();\n vout = to_float3x3(view.viewmat) * vin;\n}\nvoid direction_transform_object_to_world(float3 vin, _ref(float3 ,vout))\n{\n ObjectMatrices obj = object_matrices_get();\n vout = to_float3x3(obj.model) * vin;\n}\nvoid direction_transform_object_to_view(float3 vin, _ref(float3 ,vout))\n{\n ObjectMatrices obj = object_matrices_get();\n ViewMatrices view = view_matrices_get();\n vout = to_float3x3(obj.model) * vin;\n vout = to_float3x3(view.viewmat) * vout;\n}\nvoid direction_transform_view_to_world(float3 vin, _ref(float3 ,vout))\n{\n ViewMatrices view = view_matrices_get();\n vout = to_float3x3(view.viewinv) * vin;\n}\nvoid direction_transform_view_to_object(float3 vin, _ref(float3 ,vout))\n{\n ObjectMatrices obj = object_matrices_get();\n ViewMatrices view = view_matrices_get();\n vout = to_float3x3(view.viewinv) * vin;\n vout = to_float3x3(obj.model_inverse) * vout;\n}\nvoid direction_transform_world_to_view(float3 vin, _ref(float3 ,vout))\n{\n ViewMatrices view = view_matrices_get();\n vout = to_float3x3(view.viewmat) * vin;\n}\nvoid direction_transform_world_to_object(float3 vin, _ref(float3 ,vout))\n{\n ObjectMatrices obj = object_matrices_get();\n vout = to_float3x3(obj.model_inverse) * vin;\n}\nvoid point_transform_object_to_world(float3 vin, _ref(float3 ,vout))\n{\n ObjectMatrices obj = object_matrices_get();\n vout = (obj.model * float4(vin, 1.0f)).xyz;\n}\nvoid point_transform_object_to_view(float3 vin, _ref(float3 ,vout))\n{\n ObjectMatrices obj = object_matrices_get();\n ViewMatrices view = view_matrices_get();\n vout = (view.viewmat * (obj.model * float4(vin, 1.0f))).xyz;\n}\nvoid point_transform_view_to_world(float3 vin, _ref(float3 ,vout))\n{\n ViewMatrices view = view_matrices_get();\n vout = (view.viewinv * float4(vin, 1.0f)).xyz;\n}\nvoid point_transform_view_to_object(float3 vin, _ref(float3 ,vout))\n{\n ObjectMatrices obj = object_matrices_get();\n ViewMatrices view = view_matrices_get();\n vout = (obj.model_inverse * (view.viewinv * float4(vin, 1.0f))).xyz;\n}\nvoid point_transform_world_to_view(float3 vin, _ref(float3 ,vout))\n{\n ViewMatrices view = view_matrices_get();\n vout = (view.viewmat * float4(vin, 1.0f)).xyz;\n}\nvoid point_transform_world_to_object(float3 vin, _ref(float3 ,vout))\n{\n ObjectMatrices obj = object_matrices_get();\n vout = (obj.model_inverse * float4(vin, 1.0f)).xyz;\n}"
|
|
355
|
+
},
|
|
356
|
+
"gpu_shader_material_attribute.glsl": {
|
|
357
|
+
"deps": [
|
|
358
|
+
"gpu_shader_math_constants_lib.glsl",
|
|
359
|
+
"gpu_shader_common_math.glsl"
|
|
360
|
+
],
|
|
361
|
+
"code": "void node_attribute_color(float4 attr, _ref(float4 ,out_attr))\n{\n out_attr = attr_load_color_post(attr);\n}\nvoid node_attribute_temperature(float4 attr, _ref(float4 ,out_attr))\n{\n float temperature = attr_load_temperature_post(attr.x);\n out_attr.x = temperature;\n out_attr.y = temperature;\n out_attr.z = temperature;\n out_attr.w = 1.0f;\n}\nvoid node_attribute_density(float4 attr, _ref(float ,out_attr))\n{\n out_attr = attr.x;\n}\nvoid node_attribute_flame(float4 attr, _ref(float ,out_attr))\n{\n out_attr = attr.x;\n}\nvoid node_attribute_uniform(float4 attr, const float attr_hash, _ref(float4 ,out_attr))\n{\n out_attr = attr_load_uniform(attr, floatBitsToUint(attr_hash));\n}\n\nfloat4 attr_load_layer(const uint attr_hash)\n{\n#ifdef VLATTR_LIB\n\n uint left = 0, right = drw_layer_attrs[0].buffer_length;\n\n while (left < right) {\n uint mid = (left + right) / 2;\n uint hash = drw_layer_attrs[mid].hash_code;\n\n if (hash < attr_hash) {\n left = mid + 1;\n }\n else if (hash > attr_hash) {\n right = mid;\n }\n else {\n return drw_layer_attrs[mid].data;\n }\n }\n#endif\n\n return float4(0.0f);\n}\nvoid node_attribute(float4 attr, _ref(float4 ,outcol), _ref(float3 ,outvec), _ref(float ,outf), _ref(float ,outalpha))\n{\n outcol = float4(attr.xyz, 1.0f);\n outvec = attr.xyz;\n outf = math_average(attr.xyz);\n outalpha = attr.w;\n}"
|
|
362
|
+
},
|
|
363
|
+
"gpu_shader_material_vertex_color.glsl": {
|
|
364
|
+
"deps": [
|
|
365
|
+
"gpu_shader_math_constants_lib.glsl"
|
|
366
|
+
],
|
|
367
|
+
"code": "void node_vertex_color(float4 vertexColor, _ref(float4 ,outColor), _ref(float ,outAlpha))\n{\n outColor = vertexColor;\n outAlpha = vertexColor.a;\n}"
|
|
368
|
+
},
|
|
369
|
+
"gpu_shader_material_tex_image.glsl": {
|
|
370
|
+
"deps": [
|
|
371
|
+
"gpu_shader_math_constants_lib.glsl",
|
|
372
|
+
"gpu_shader_bicubic_sampler_lib.glsl",
|
|
373
|
+
"gpu_shader_tiled_image_lookup_lib.glsl"
|
|
374
|
+
],
|
|
375
|
+
"code": "void point_texco_remap_square(float3 vin, _ref(float3 ,vout))\n{\n vout = vin * 2.0f - 1.0f;\n}\nvoid point_texco_clamp(float3 vin, sampler2D ima, _ref(float3 ,vout))\n{\n float2 half_texel_size = 0.5f / float2(textureSize(ima, 0).xy);\n vout = clamp(vin, half_texel_size.xyy, 1.0f - half_texel_size.xyy);\n}\nvoid point_map_to_sphere(float3 vin, _ref(float3 ,vout))\n{\n float len = length(vin);\n float v, u;\n if (len > 0.0f) {\n if (vin.x == 0.0f && vin.y == 0.0f) {\n u = 0.0f;\n }\n else {\n u = (1.0f - atan(vin.x, vin.y) / M_PI) / 2.0f;\n }\n\n v = 1.0f - acos(vin.z / len) / M_PI;\n }\n else {\n v = u = 0.0f;\n }\n\n vout = float3(u, v, 0.0f);\n}\nvoid point_map_to_tube(float3 vin, _ref(float3 ,vout))\n{\n float u, v;\n v = (vin.z + 1.0f) * 0.5f;\n float len = sqrt(vin.x * vin.x + vin.y * vin[1]);\n if (len > 0.0f) {\n u = (1.0f - (atan(vin.x / len, vin.y / len) / M_PI)) * 0.5f;\n }\n else {\n v = u = 0.0f;\n }\n\n vout = float3(u, v, 0.0f);\n}\nvoid node_tex_image_linear(float3 co, sampler2D ima, _ref(float4 ,color), _ref(float ,alpha))\n{\n#ifdef GPU_FRAGMENT_SHADER\n float2 dx = gpu_dfdx(co.xy) * texture_lod_bias_get();\n float2 dy = gpu_dfdy(co.xy) * texture_lod_bias_get();\n\n color = textureGrad(ima, co.xy, dx, dy);\n#else\n color = texture(ima, co.xy);\n#endif\n\n alpha = color.a;\n}\nvoid node_tex_image_cubic(float3 co, sampler2D ima, _ref(float4 ,color), _ref(float ,alpha))\n{\n color = texture_bicubic(ima, co.xy);\n alpha = color.a;\n}\nvoid tex_box_sample_linear(\n float3 texco, float3 N, sampler2D ima, _ref(float4 ,color1), _ref(float4 ,color2), _ref(float4 ,color3))\n{\n\n float2 uv = texco.yz;\n if (N.x < 0.0f) {\n uv.x = 1.0f - uv.x;\n }\n color1 = texture(ima, uv);\n\n uv = texco.xz;\n if (N.y > 0.0f) {\n uv.x = 1.0f - uv.x;\n }\n color2 = texture(ima, uv);\n\n uv = texco.yx;\n if (N.z > 0.0f) {\n uv.x = 1.0f - uv.x;\n }\n color3 = texture(ima, uv);\n}\nvoid tex_box_sample_cubic(\n float3 texco, float3 N, sampler2D ima, _ref(float4 ,color1), _ref(float4 ,color2), _ref(float4 ,color3))\n{\n float alpha;\n\n float2 uv = texco.yz;\n if (N.x < 0.0f) {\n uv.x = 1.0f - uv.x;\n }\n node_tex_image_cubic(uv.xyy, ima, color1, alpha);\n\n uv = texco.xz;\n if (N.y > 0.0f) {\n uv.x = 1.0f - uv.x;\n }\n node_tex_image_cubic(uv.xyy, ima, color2, alpha);\n\n uv = texco.yx;\n if (N.z > 0.0f) {\n uv.x = 1.0f - uv.x;\n }\n node_tex_image_cubic(uv.xyy, ima, color3, alpha);\n}\nvoid tex_box_blend(float3 N,\n float4 color1,\n float4 color2,\n float4 color3,\n float blend,\n _ref(float4 ,color),\n _ref(float ,alpha))\n{\n\n N = abs(N);\n N /= dot(N, float3(1.0f));\n float limit = 0.5f + 0.5f * blend;\n\n float3 weight;\n weight = N.xyz / (N.xyx + N.yzz);\n weight = clamp((weight - 0.5f * (1.0f - blend)) / max(1e-8f, blend), 0.0f, 1.0f);\n if (N.z < (1.0f - limit) * (N.y + N.x)) {\n weight.z = 0.0f;\n weight.y = 1.0f - weight.x;\n }\n else if (N.x < (1.0f - limit) * (N.y + N.z)) {\n weight.x = 0.0f;\n weight.z = 1.0f - weight.y;\n }\n else if (N.y < (1.0f - limit) * (N.x + N.z)) {\n weight.y = 0.0f;\n weight.x = 1.0f - weight.z;\n }\n else {\n\n weight = ((2.0f - limit) * N + (limit - 1.0f)) / max(1e-8f, blend);\n }\n\n color = weight.x * color1 + weight.y * color2 + weight.z * color3;\n alpha = color.a;\n}\nvoid node_tex_image_empty(float3 co, _ref(float4 ,color), _ref(float ,alpha))\n{\n color = float4(0.0f);\n alpha = 1.0f;\n}"
|
|
376
|
+
},
|
|
377
|
+
"gpu_shader_bicubic_sampler_lib.glsl": {
|
|
378
|
+
"deps": [
|
|
379
|
+
"gpu_shader_math_constants_lib.glsl"
|
|
380
|
+
],
|
|
381
|
+
"code": "void cubic_bspline_coefficients(float2 f, _ref(float2 ,w0), _ref(float2 ,w1), _ref(float2 ,w2), _ref(float2 ,w3))\n{\n float2 f2 = f * f;\n float2 f3 = f2 * f;\n\n w3 = f3 / 6.0f;\n w0 = -w3 + f2 * 0.5f - f * 0.5f + 1.0f / 6.0f;\n w1 = f3 * 0.5f - f2 * 1.0f + 2.0f / 3.0f;\n w2 = 1.0f - w0 - w1 - w3;\n}\nfloat4 texture_bicubic(sampler2D sampler_2d, float2 coordinates)\n{\n float2 texture_size = float2(textureSize(sampler_2d, 0).xy);\n coordinates.xy *= texture_size;\n\n float2 w0, w1, w2, w3;\n float2 texel_center = floor(coordinates.xy - 0.5f) + 0.5f;\n cubic_bspline_coefficients(coordinates.xy - texel_center, w0, w1, w2, w3);\n\n#if 1\n float2 s0 = w0 + w1;\n float2 s1 = w2 + w3;\n\n float2 f0 = w1 / (w0 + w1);\n float2 f1 = w3 / (w2 + w3);\n\n float4 sampling_coordinates;\n sampling_coordinates.xy = texel_center - 1.0f + f0;\n sampling_coordinates.zw = texel_center + 1.0f + f1;\n\n sampling_coordinates /= texture_size.xyxy;\n\n float4 sampled_color = textureLod(sampler_2d, sampling_coordinates.xy, 0.0f) * s0.x * s0.y;\n sampled_color += textureLod(sampler_2d, sampling_coordinates.zy, 0.0f) * s1.x * s0.y;\n sampled_color += textureLod(sampler_2d, sampling_coordinates.xw, 0.0f) * s0.x * s1.y;\n sampled_color += textureLod(sampler_2d, sampling_coordinates.zw, 0.0f) * s1.x * s1.y;\n\n return sampled_color;\n\n#else\n float4 color = texelFetch(sampler_2d, int2(texel_center + float2(-1.0f, -1.0f)), 0) * w0.x *\n w0.y;\n color += texelFetch(sampler_2d, int2(texel_center + float2(0.0f, -1.0f)), 0) * w1.x * w0.y;\n color += texelFetch(sampler_2d, int2(texel_center + float2(1.0f, -1.0f)), 0) * w2.x * w0.y;\n color += texelFetch(sampler_2d, int2(texel_center + float2(2.0f, -1.0f)), 0) * w3.x * w0.y;\n\n color += texelFetch(sampler_2d, int2(texel_center + float2(-1.0f, 0.0f)), 0) * w0.x * w1.y;\n color += texelFetch(sampler_2d, int2(texel_center + float2(0.0f, 0.0f)), 0) * w1.x * w1.y;\n color += texelFetch(sampler_2d, int2(texel_center + float2(1.0f, 0.0f)), 0) * w2.x * w1.y;\n color += texelFetch(sampler_2d, int2(texel_center + float2(2.0f, 0.0f)), 0) * w3.x * w1.y;\n\n color += texelFetch(sampler_2d, int2(texel_center + float2(-1.0f, 1.0f)), 0) * w0.x * w2.y;\n color += texelFetch(sampler_2d, int2(texel_center + float2(0.0f, 1.0f)), 0) * w1.x * w2.y;\n color += texelFetch(sampler_2d, int2(texel_center + float2(1.0f, 1.0f)), 0) * w2.x * w2.y;\n color += texelFetch(sampler_2d, int2(texel_center + float2(2.0f, 1.0f)), 0) * w3.x * w2.y;\n\n color += texelFetch(sampler_2d, int2(texel_center + float2(-1.0f, 2.0f)), 0) * w0.x * w3.y;\n color += texelFetch(sampler_2d, int2(texel_center + float2(0.0f, 2.0f)), 0) * w1.x * w3.y;\n color += texelFetch(sampler_2d, int2(texel_center + float2(1.0f, 2.0f)), 0) * w2.x * w3.y;\n color += texelFetch(sampler_2d, int2(texel_center + float2(2.0f, 2.0f)), 0) * w3.x * w3.y;\n\n return color;\n#endif\n}"
|
|
382
|
+
},
|
|
383
|
+
"gpu_shader_tiled_image_lookup_lib.glsl": {
|
|
384
|
+
"deps": [
|
|
385
|
+
"gpu_shader_math_constants_lib.glsl"
|
|
386
|
+
],
|
|
387
|
+
"code": ""
|
|
388
|
+
},
|
|
389
|
+
"gpu_shader_material_implicit_defaults.glsl": {
|
|
390
|
+
"deps": [
|
|
391
|
+
"gpu_shader_math_constants_lib.glsl"
|
|
392
|
+
],
|
|
393
|
+
"code": "void world_normals_get(_ref(float3 ,N))\n{\n N = g_data.N;\n}\nvoid world_position_get(_ref(float3 ,P))\n{\n P = g_data.P;\n}"
|
|
394
|
+
},
|
|
395
|
+
"gpu_shader_common_curves.glsl": {
|
|
396
|
+
"deps": [
|
|
397
|
+
"gpu_shader_math_constants_lib.glsl"
|
|
398
|
+
],
|
|
399
|
+
"code": "float4 white_balance(float4 color, float4 black_level, float4 white_level)\n{\n float4 range = max(white_level - black_level, float4(1e-5f));\n return (color - black_level) / range;\n}\n\nfloat extrapolate_if_needed(float parameter, float value, float start_slope, float end_slope)\n{\n if (parameter < 0.0f) {\n return value + parameter * start_slope;\n }\n\n if (parameter > 1.0f) {\n return value + (parameter - 1.0f) * end_slope;\n }\n\n return value;\n}\nfloat3 extrapolate_if_needed(float3 parameters,\n float3 values,\n float3 start_slopes,\n float3 end_slopes)\n{\n float3 end_or_zero_slopes = mix(float3(0.0f), end_slopes, greaterThan(parameters, float3(1.0f)));\n float3 slopes = mix(end_or_zero_slopes, start_slopes, lessThan(parameters, float3(0.0f)));\n parameters = parameters - mix(float3(0.0f), float3(1.0f), greaterThan(parameters, float3(1.0f)));\n return values + parameters * slopes;\n}\nfloat compute_curve_map_coordinates(float parameter)\n{\n float sampler_offset = 0.5f / 257.0f;\n float sampler_scale = 1.0f - (1.0f / 257.0f);\n return parameter * sampler_scale + sampler_offset;\n}\nfloat3 compute_curve_map_coordinates(float3 parameters)\n{\n float sampler_offset = 0.5f / 257.0f;\n float sampler_scale = 1.0f - (1.0f / 257.0f);\n return parameters * sampler_scale + sampler_offset;\n}\nvoid curves_combined_rgb(float factor,\n float4 color,\n float4 black_level,\n float4 white_level,\n sampler2D curve_map,\n const float layer,\n float4 range_minimums,\n float4 range_dividers,\n float4 start_slopes,\n float4 end_slopes,\n _ref(float4 ,result))\n{\n float4 balanced = white_balance(color, black_level, white_level);\n float3 parameters = (balanced.rgb - range_minimums.aaa) * range_dividers.aaa;\n float3 coordinates = compute_curve_map_coordinates(parameters);\n result.r = texture(curve_map, float2(coordinates.x, layer)).a;\n result.g = texture(curve_map, float2(coordinates.y, layer)).a;\n result.b = texture(curve_map, float2(coordinates.z, layer)).a;\n result.rgb = extrapolate_if_needed(parameters, result.rgb, start_slopes.aaa, end_slopes.aaa);\n parameters = (result.rgb - range_minimums.rgb) * range_dividers.rgb;\n coordinates = compute_curve_map_coordinates(parameters);\n result.r = texture(curve_map, float2(coordinates.r, layer)).r;\n result.g = texture(curve_map, float2(coordinates.g, layer)).g;\n result.b = texture(curve_map, float2(coordinates.b, layer)).b;\n result.rgb = extrapolate_if_needed(parameters, result.rgb, start_slopes.rgb, end_slopes.rgb);\n\n result.a = color.a;\n\n result = mix(color, result, factor);\n}\nvoid curves_combined_rgb_compositor(float4 color,\n float factor,\n float4 black_level,\n float4 white_level,\n sampler2D curve_map,\n const float layer,\n float4 range_minimums,\n float4 range_dividers,\n float4 start_slopes,\n float4 end_slopes,\n _ref(float4 ,result))\n{\n curves_combined_rgb(factor,\n color,\n black_level,\n white_level,\n curve_map,\n layer,\n range_minimums,\n range_dividers,\n start_slopes,\n end_slopes,\n result);\n}\nvoid curves_combined_only(float factor,\n float4 color,\n float4 black_level,\n float4 white_level,\n sampler2D curve_map,\n const float layer,\n float range_minimum,\n float range_divider,\n float start_slope,\n float end_slope,\n _ref(float4 ,result))\n{\n float4 balanced = white_balance(color, black_level, white_level);\n float3 parameters = (balanced.rgb - float3(range_minimum)) * float3(range_divider);\n float3 coordinates = compute_curve_map_coordinates(parameters);\n result.r = texture(curve_map, float2(coordinates.x, layer)).a;\n result.g = texture(curve_map, float2(coordinates.y, layer)).a;\n result.b = texture(curve_map, float2(coordinates.z, layer)).a;\n result.rgb = extrapolate_if_needed(\n parameters, result.rgb, float3(start_slope), float3(end_slope));\n\n result.a = color.a;\n\n result = mix(color, result, factor);\n}\nvoid curves_combined_only_compositor(float4 color,\n float factor,\n float4 black_level,\n float4 white_level,\n sampler2D curve_map,\n const float layer,\n float range_minimum,\n float range_divider,\n float start_slope,\n float end_slope,\n _ref(float4 ,result))\n{\n curves_combined_only(factor,\n color,\n black_level,\n white_level,\n curve_map,\n layer,\n range_minimum,\n range_divider,\n start_slope,\n end_slope,\n result);\n}\nvoid curves_film_like(float factor,\n float4 color,\n float4 black_level,\n float4 white_level,\n sampler2D curve_map,\n const float layer,\n float range_minimum,\n float range_divider,\n float start_slope,\n float end_slope,\n _ref(float4 ,result))\n{\n float4 balanced = white_balance(color, black_level, white_level);\n float minimum = min(balanced.r, min(balanced.g, balanced.b));\n float maximum = max(balanced.r, max(balanced.g, balanced.b));\n float median = max(min(balanced.r, balanced.g), min(balanced.b, max(balanced.r, balanced.g)));\n float min_parameter = (minimum - range_minimum) * range_divider;\n float max_parameter = (maximum - range_minimum) * range_divider;\n float min_coordinates = compute_curve_map_coordinates(min_parameter);\n float max_coordinates = compute_curve_map_coordinates(max_parameter);\n float new_min = texture(curve_map, float2(min_coordinates, layer)).a;\n float new_max = texture(curve_map, float2(max_coordinates, layer)).a;\n new_min = extrapolate_if_needed(min_parameter, new_min, start_slope, end_slope);\n new_max = extrapolate_if_needed(max_parameter, new_max, start_slope, end_slope);\n float scaling_ratio = (new_max - new_min) / (maximum - minimum);\n float new_median = new_min + (median - minimum) * scaling_ratio;\n bool3 channel_is_min = equal(balanced.rgb, float3(minimum));\n float3 median_or_min = mix(float3(new_median), float3(new_min), channel_is_min);\n bool3 channel_is_max = equal(balanced.rgb, float3(maximum));\n result.rgb = mix(median_or_min, float3(new_max), channel_is_max);\n\n result.a = color.a;\n\n result = mix(color, result, clamp(factor, 0.0f, 1.0f));\n}\nvoid curves_film_like_compositor(float4 color,\n float factor,\n float4 black_level,\n float4 white_level,\n sampler2D curve_map,\n const float layer,\n float range_minimum,\n float range_divider,\n float start_slope,\n float end_slope,\n _ref(float4 ,result))\n{\n curves_film_like(factor,\n color,\n black_level,\n white_level,\n curve_map,\n layer,\n range_minimum,\n range_divider,\n start_slope,\n end_slope,\n result);\n}\nvoid curves_vector(float3 vector,\n sampler2D curve_map,\n const float layer,\n float3 range_minimums,\n float3 range_dividers,\n float3 start_slopes,\n float3 end_slopes,\n _ref(float3 ,result))\n{\n float3 parameters = (vector - range_minimums) * range_dividers;\n float3 coordinates = compute_curve_map_coordinates(parameters);\n result.x = texture(curve_map, float2(coordinates.x, layer)).x;\n result.y = texture(curve_map, float2(coordinates.y, layer)).y;\n result.z = texture(curve_map, float2(coordinates.z, layer)).z;\n result = extrapolate_if_needed(parameters, result, start_slopes, end_slopes);\n}\nvoid curves_vector_mixed(float factor,\n float3 vector,\n sampler2D curve_map,\n const float layer,\n float3 range_minimums,\n float3 range_dividers,\n float3 start_slopes,\n float3 end_slopes,\n _ref(float3 ,result))\n{\n curves_vector(\n vector, curve_map, layer, range_minimums, range_dividers, start_slopes, end_slopes, result);\n result = mix(vector, result, factor);\n}\nvoid curves_float(float value,\n sampler2D curve_map,\n const float layer,\n float range_minimum,\n float range_divider,\n float start_slope,\n float end_slope,\n _ref(float ,result))\n{\n\n float parameter = (value - range_minimum) * range_divider;\n float coordinates = compute_curve_map_coordinates(parameter);\n result = texture(curve_map, float2(coordinates, layer)).x;\n result = extrapolate_if_needed(parameter, result, start_slope, end_slope);\n}\nvoid curves_float_mixed(float factor,\n float value,\n sampler2D curve_map,\n const float layer,\n float range_minimum,\n float range_divider,\n float start_slope,\n float end_slope,\n _ref(float ,result))\n{\n curves_float(\n value, curve_map, layer, range_minimum, range_divider, start_slope, end_slope, result);\n result = mix(value, result, factor);\n}"
|
|
400
|
+
}
|
|
401
|
+
};
|