├── .gitattributes
├── .github
├── FUNDING.yml
└── workflows
│ └── release.yml
├── .gitignore
├── LICENSE.md
├── README.md
├── addons
└── ShaderFunction-Extras
│ ├── Color
│ ├── LicenseInfo.md
│ ├── blend_modes.gdshaderinc
│ └── color_adjustment.gdshaderinc
│ ├── Noise
│ ├── LicenseInfo.md
│ └── noise.gdshaderinc
│ ├── ShaderFunction-Logo.svg
│ ├── ShaderFunction-Logo.svg.import
│ ├── Shapes
│ ├── LicenseInfo.md
│ └── shapes.gdshaderinc
│ ├── UV
│ ├── LicenseInfo.md
│ └── uv.gdshaderinc
│ ├── Utility
│ ├── LicenseInfo.md
│ └── utility.gdshaderinc
│ └── Wave
│ └── wave.gdshaderinc
└── project.godot
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Normalize EOL for all files that Git considers text files.
2 | * text=auto eol=lf
3 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | ko_fi: flamelizard
--------------------------------------------------------------------------------
/.github/workflows/release.yml:
--------------------------------------------------------------------------------
1 | name: Release
2 |
3 | on: [push]
4 |
5 | jobs:
6 | build:
7 | runs-on: ubuntu-latest
8 | name: Create Release
9 |
10 | steps:
11 |
12 | - name: Checkout project
13 | uses: actions/checkout@v3
14 |
15 | - name: Move License
16 | shell: bash
17 | run: |
18 | mv LICENSE.md README.md ${{ github.workspace }}/addons/ShaderFunction-Extras
19 |
20 | - name: Directory info
21 | shell: bash
22 | run: |
23 | pwd
24 | ls -R
25 |
26 | - name: Upload artifact
27 | uses: actions/upload-artifact@v3
28 | with:
29 | name: ${{ github.event.repository.name }}
30 | path: |
31 | ${{ github.workspace }}/addons/ShaderFunction-Extras/*
32 |
33 | - name: Directory info
34 | shell: bash
35 | run: |
36 | pwd
37 | ls
38 |
39 | - name: Zip the folder
40 | uses: vimtor/action-zip@v1.1
41 | with:
42 | files: addons/ShaderFunction-Extras/
43 | dest: ShaderFunction-Extras.zip
44 |
45 | - name: Directory info
46 | shell: bash
47 | run: |
48 | pwd
49 | ls
50 |
51 | - name: Upload zip to release
52 | uses: ncipollo/release-action@v1
53 | with:
54 | allowUpdates: true
55 | artifacts: "ShaderFunction-Extras.zip"
56 | omitNameDuringUpdate: true
57 | omitBodyDuringUpdate: true
58 | token: ${{ secrets.GITHUB_TOKEN }}
59 | if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
60 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Godot 4+ specific ignores
2 | .godot/
3 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2023 Patrick Exner (FlameLizard)
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ShaderFunction-Extras
2 |
13 |
14 | 
15 |
16 |
17 | This project aims to help Godot developers writing custom written shaders by providing high-level functions which are often used.
18 |
19 | ## :tada: Using the addon
20 | Download the source (releases and AssetLib version are still WIP) and put the `ShaderFunction-Extras` inside
21 | your `addons` folder. If you don't have one, create it or put the whole addons folder inside your project directory.
22 |
23 | After that, you can include the include files you need in your shader like this:
24 | 
25 |
26 |
27 | ## 🔢 Versioning
28 | This repository is only meant for projects created with Godot 4.0 and upwards. However, if you are using Godot 3.x and want to
29 | use specific functions, you can copy and paste it inside your shader code still.
30 |
31 | ## ℹ️ Contributing
32 | All these shader functions are based on publicly available shader functions (open-source licensed with permissive licenses such as MIT). If you want to contribute a function, create an issue starting with `Proposal: ...` describing the shader function and why you think it should be included in here. We can then discuss on how this function and its parameters should be called (for clarity of the users). After that you are open to create a PR (Pull Request) with the dicussed details of the proposal.
33 |
34 | ## Provided Functions
35 |
36 |
37 |
38 | Click me to enlarge
39 |
40 |
41 | ### Color
42 | #### Blend Modes
43 | * `blend_normal`
44 | * `blend_dissolve`
45 | * `blend_multiply`
46 | * `blend_screen`
47 | * `blend_overlay`
48 | * `blend_hard_light`
49 | * `blend_soft_light`
50 | * `blend_burn`
51 | * `blend_dodge`
52 | * `blend_lighten`
53 | * `blend_darken`
54 | * `blend_difference`
55 | * `blend_additive`
56 | * `blend_addsub`
57 | * `blend_linear_light`
58 | * `blend_vivid_light`
59 | * `blend_pin_light`
60 | * `blend_hard_mix`
61 | * `blend_exclusion`
62 |
63 | #### Color Adjustment
64 | * `greyscale`
65 | * `hsv_to_rgb`
66 | * `rgb_to_hsv`
67 | * `hsv_adjustment`
68 |
69 | ### Noise
70 | * `psrdnoise3_with_gradient`
71 | * `psrdnoise3`
72 | * `psrdnoise2_with_gradient`
73 | * `psrdnoise2`
74 |
75 | ### Utility
76 | * `depth_camera_*`
77 | * `depth_vertex_*`
78 | * `linear_scene_depth_*`
79 | * `distance_fade`
80 | * `proximity_camera_fade_*`
81 | * `proximity_vertex_fade_*`
82 | * `world_position_from_depth_*`
83 | * `screen_normal_world_space`
84 | * `rotation_matrix_by_axis`
85 | * `rotate_by_axis`
86 | * `random_range`
87 | * `remap`
88 | * `fresnel`
89 | * `fresnel_glow`
90 | * `smooth_clamp`
91 | * `soft_clamp`
92 | * `saturate`
93 | * `vertex_billboard`
94 |
95 | ### UV
96 | * `uv_panning`
97 | * `uv_scaling`
98 | * `uv_rotate`
99 | * `uv_polar_coord_*`
100 | * `uv_flipbook`
101 | * `uv_twirl`
102 | * `uv_grid_tiler`
103 |
104 | ### Wave
105 | * `sawtooth_wave`
106 | * `sine_wave`
107 | * `sine_wave_angular`
108 | * `square_wave`
109 | * `triangle_wave`
110 |
111 | ### Shapes
112 | * `polygon`
113 | * `circle`
114 | * `square`
115 | * `square_stroke`
116 | * `square_rounded`
117 | * `swirl`
118 | * `line`
119 |
120 |
121 |
--------------------------------------------------------------------------------
/addons/ShaderFunction-Extras/Color/LicenseInfo.md:
--------------------------------------------------------------------------------
1 | # License Information
2 |
3 | ## blend_modes.gdshaderinc
4 | ```md
5 | # MIT License
6 |
7 | Copyright (c) 2018-2021 Rodolphe Suescun and contributors
8 |
9 | Permission is hereby granted, free of charge, to any person obtaining a copy
10 | of this software and associated documentation files (the "Software"), to deal
11 | in the Software without restriction, including without limitation the rights
12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | copies of the Software, and to permit persons to whom the Software is
14 | furnished to do so, subject to the following conditions:
15 |
16 | The above copyright notice and this permission notice shall be included in all
17 | copies or substantial portions of the Software.
18 |
19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | SOFTWARE.
26 | ```
27 |
28 | ## color_conversion.gdshaderinc
29 | ```md
30 | /**************************************************************************/
31 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
32 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
33 | /* */
34 | /* Permission is hereby granted, free of charge, to any person obtaining */
35 | /* a copy of this software and associated documentation files (the */
36 | /* "Software"), to deal in the Software without restriction, including */
37 | /* without limitation the rights to use, copy, modify, merge, publish, */
38 | /* distribute, sublicense, and/or sell copies of the Software, and to */
39 | /* permit persons to whom the Software is furnished to do so, subject to */
40 | /* the following conditions: */
41 | /* */
42 | /* The above copyright notice and this permission notice shall be */
43 | /* included in all copies or substantial portions of the Software. */
44 | /* */
45 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
46 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
47 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
48 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
49 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
50 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
51 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
52 | /**************************************************************************/
53 | ```
54 |
--------------------------------------------------------------------------------
/addons/ShaderFunction-Extras/Color/blend_modes.gdshaderinc:
--------------------------------------------------------------------------------
1 | #include "res://addons/ShaderFunction-Extras/Utility/utility.gdshaderinc"
2 |
3 | vec3 blend_normal(vec3 c1, vec3 c2, float opacity) {
4 | return opacity*c1 + (1.0-opacity)*c2;
5 | }
6 |
7 | vec3 blend_dissolve(vec3 seed, vec3 c1, vec3 c2, float opacity) {
8 | if (random_range(vec3(seed), 0.0, 1.0) < opacity) {
9 | return c1;
10 | } else {
11 | return c2;
12 | }
13 | }
14 |
15 | vec3 blend_multiply(vec3 c1, vec3 c2, float opacity) {
16 | return opacity*c1*c2 + (1.0-opacity)*c2;
17 | }
18 |
19 | vec3 blend_screen(vec3 c1, vec3 c2, float opacity) {
20 | return opacity*(1.0-(1.0-c1)*(1.0-c2)) + (1.0-opacity)*c2;
21 | }
22 |
23 | float blend_overlay_f(float c1, float c2) {
24 | return (c1 < 0.5) ? (2.0*c1*c2) : (1.0-2.0*(1.0-c1)*(1.0-c2));
25 | }
26 |
27 | vec3 blend_overlay(vec3 c1, vec3 c2, float opacity) {
28 | return opacity*vec3(blend_overlay_f(c1.x, c2.x), blend_overlay_f(c1.y, c2.y), blend_overlay_f(c1.z, c2.z)) + (1.0-opacity)*c2;
29 | }
30 |
31 | vec3 blend_hard_light(vec3 c1, vec3 c2, float opacity) {
32 | return opacity*0.5*(c1*c2+blend_overlay(c1, c2, 1.0)) + (1.0-opacity)*c2;
33 | }
34 |
35 | float blend_soft_light_f(float c1, float c2) {
36 | return (c2 < 0.5) ? (2.0*c1*c2+c1*c1*(1.0-2.0*c2)) : 2.0*c1*(1.0-c2)+sqrt(c1)*(2.0*c2-1.0);
37 | }
38 |
39 | vec3 blend_soft_light(vec3 c1, vec3 c2, float opacity) {
40 | return opacity*vec3(blend_soft_light_f(c1.x, c2.x), blend_soft_light_f(c1.y, c2.y), blend_soft_light_f(c1.z, c2.z)) + (1.0-opacity)*c2;
41 | }
42 |
43 | float blend_burn_f(float c1, float c2) {
44 | return (c1==0.0)?c1:max((1.0-((1.0-c2)/c1)),0.0);
45 | }
46 |
47 | vec3 blend_burn(vec3 c1, vec3 c2, float opacity) {
48 | return opacity*vec3(blend_burn_f(c1.x, c2.x), blend_burn_f(c1.y, c2.y), blend_burn_f(c1.z, c2.z)) + (1.0-opacity)*c2;
49 | }
50 |
51 | float blend_dodge_f(float c1, float c2) {
52 | return (c1==1.0)?c1:min(c2/(1.0-c1),1.0);
53 | }
54 |
55 | vec3 blend_dodge(vec3 c1, vec3 c2, float opacity) {
56 | return opacity*vec3(blend_dodge_f(c1.x, c2.x), blend_dodge_f(c1.y, c2.y), blend_dodge_f(c1.z, c2.z)) + (1.0-opacity)*c2;
57 | }
58 |
59 | vec3 blend_lighten(vec3 c1, vec3 c2, float opacity) {
60 | return opacity*max(c1, c2) + (1.0-opacity)*c2;
61 | }
62 |
63 | vec3 blend_darken(vec3 c1, vec3 c2, float opacity) {
64 | return opacity*min(c1, c2) + (1.0-opacity)*c2;
65 | }
66 |
67 | vec3 blend_difference(vec3 c1, vec3 c2, float opacity) {
68 | return opacity*clamp(c2-c1, vec3(0.0), vec3(1.0)) + (1.0-opacity)*c2;
69 | }
70 |
71 | vec3 blend_additive(vec3 c1, vec3 c2, float oppacity) {
72 | return c2 + c1 * oppacity;
73 | }
74 |
75 | vec3 blend_addsub(vec3 c1, vec3 c2, float oppacity) {
76 | return c2 + (c1 - .5) * 2.0 * oppacity;
77 | }
78 |
79 | float blend_linear_light_f(float c1, float c2) {
80 | return (c1 + 2.0 * c2) - 1.0;
81 | }
82 |
83 | vec3 blend_linear_light(vec2 uv, vec3 c1, vec3 c2, float opacity) {
84 | return opacity*vec3(blend_linear_light_f(c1.x, c2.x), blend_linear_light_f(c1.y, c2.y), blend_linear_light_f(c1.z, c2.z)) + (1.0-opacity)*c2;
85 | }
86 |
87 | float blend_vivid_light_f(float c1, float c2) {
88 | return (c1 < 0.5) ? 1.0 - (1.0 - c2) / (2.0 * c1) : c2 / (2.0 * (1.0 - c1));
89 | }
90 |
91 | vec3 blend_vivid_light(vec3 c1, vec3 c2, float opacity) {
92 | return opacity*vec3(blend_vivid_light_f(c1.x, c2.x), blend_vivid_light_f(c1.y, c2.y), blend_vivid_light_f(c1.z, c2.z)) + (1.0-opacity)*c2;
93 | }
94 |
95 | float blend_pin_light_f( float c1, float c2) {
96 | return (2.0 * c1 - 1.0 > c2) ? 2.0 * c1 - 1.0 : ((c1 < 0.5 * c2) ? 2.0 * c1 : c2);
97 | }
98 |
99 | vec3 blend_pin_light(vec3 c1, vec3 c2, float opacity) {
100 | return opacity*vec3(blend_pin_light_f(c1.x, c2.x), blend_pin_light_f(c1.y, c2.y), blend_pin_light_f(c1.z, c2.z)) + (1.0-opacity)*c2;
101 | }
102 |
103 | float blend_hard_mix_f(float c1, float c2) {
104 | return floor(c1 + c2);
105 | }
106 |
107 | vec3 blend_hard_mix(vec2 uv, vec3 c1, vec3 c2, float opacity) {
108 | return opacity*vec3(blend_hard_mix_f(c1.x, c2.x), blend_hard_mix_f(c1.y, c2.y), blend_hard_mix_f(c1.z, c2.z)) + (1.0-opacity)*c2;
109 | }
110 |
111 | float blend_exclusion_f(float c1, float c2) {
112 | return c1 + c2 - 2.0 * c1 * c2;
113 | }
114 |
115 | vec3 blend_exclusion(vec2 uv, vec3 c1, vec3 c2, float opacity) {
116 | return opacity*vec3(blend_exclusion_f(c1.x, c2.x), blend_exclusion_f(c1.y, c2.y), blend_exclusion_f(c1.z, c2.z)) + (1.0-opacity)*c2;
117 | }
--------------------------------------------------------------------------------
/addons/ShaderFunction-Extras/Color/color_adjustment.gdshaderinc:
--------------------------------------------------------------------------------
1 | float grayscale(vec3 color) {
2 | float max1 = max(color.r, color.g);
3 | float max2 = max(max1, color.b);
4 | return max2;
5 | }
6 |
7 | vec3 hsv_to_rgb(vec3 color) {
8 | vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
9 | vec3 p = abs(fract(color.xxx + K.xyz) * 6.0 - K.www);
10 | return color.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), color.y);
11 | }
12 |
13 | vec3 rgb_to_hsv(vec3 color) {
14 | vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
15 | vec4 p = mix(vec4(color.bg, K.wz), vec4(color.gb, K.xy), step(color.b, color.g));
16 | vec4 q = mix(vec4(p.xyw, color.r), vec4(color.r, p.yzx), step(p.x, color.r));
17 | float d = q.x - min(q.w, q.y);
18 | float e = 1.0e-10;
19 | return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
20 | }
21 |
22 | vec3 hsv_adjustment(vec3 col, float hue_offset, float sat_offset, float val_offset) {
23 | vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
24 | vec4 p = mix(vec4(col.bg, K.wz), vec4(col.gb, K.xy), step(col.b, col.g));
25 | vec4 q = mix(vec4(p.xyw, col.r), vec4(col.r, p.yzx), step(p.x, col.r));
26 | float d = q.x - min(q.w, q.y);
27 | float e = 1.0e-10;
28 | vec3 hsv = vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
29 | hsv.x += hue_offset / 360.0;
30 | hsv.y += sat_offset;
31 | hsv.z += val_offset;
32 | return hsv;
33 | }
34 |
--------------------------------------------------------------------------------
/addons/ShaderFunction-Extras/Noise/LicenseInfo.md:
--------------------------------------------------------------------------------
1 | # License Information
2 |
3 | ## noise.gdshaderinc
4 |
5 | ```md
6 | Copyright 2021, Stefan Gustavson and Ian MacEwan (stefan.gustavson@gmail.com, ijm567@gmail.com)
7 |
8 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11 |
12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13 | ```
14 |
--------------------------------------------------------------------------------
/addons/ShaderFunction-Extras/Noise/noise.gdshaderinc:
--------------------------------------------------------------------------------
1 | // psrdnoise (c) Stefan Gustavson and Ian McEwan,
2 | // ver. 2021-12-02, published under the MIT license:
3 | // https://github.com/stegu/psrdnoise/
4 |
5 | vec4 __psrdnoise3_permute(vec4 i) {
6 | vec4 im = mod(i, 289.0);
7 | return mod(((im*34.0)+10.0)*im, 289.0);
8 | }
9 |
10 | float psrdnoise3_with_gradient(vec3 x, vec3 period, float alpha, out vec3 gradient)
11 | {
12 | const mat3 M = mat3(vec3(0.0, 1.0, 1.0), vec3(1.0, 0.0, 1.0), vec3(1.0, 1.0, 0.0));
13 | const mat3 Mi = mat3(vec3(-0.5, 0.5, 0.5), vec3(0.5,-0.5, 0.5), vec3(0.5, 0.5,-0.5));
14 | vec3 uvw = M * x;
15 | vec3 i0 = floor(uvw), f0 = fract(uvw);
16 | vec3 g_ = step(f0.xyx, f0.yzz), l_ = 1.0 - g_;
17 | vec3 g = vec3(l_.z, g_.xy), l = vec3(l_.xy, g_.z);
18 | vec3 o1 = min( g, l ), o2 = max( g, l );
19 | vec3 i1 = i0 + o1, i2 = i0 + o2, i3 = i0 + vec3(1.0);
20 | vec3 v0 = Mi * i0, v1 = Mi * i1, v2 = Mi * i2, v3 = Mi * i3;
21 | vec3 x0 = x - v0, x1 = x - v1, x2 = x - v2, x3 = x - v3;
22 | if(any(greaterThan(period, vec3(0.0)))) {
23 | vec4 vx = vec4(v0.x, v1.x, v2.x, v3.x);
24 | vec4 vy = vec4(v0.y, v1.y, v2.y, v3.y);
25 | vec4 vz = vec4(v0.z, v1.z, v2.z, v3.z);
26 | if(period.x > 0.0) vx = mod(vx, period.x);
27 | if(period.y > 0.0) vy = mod(vy, period.y);
28 | if(period.z > 0.0) vz = mod(vz, period.z);
29 | i0 = floor(M * vec3(vx.x, vy.x, vz.x) + 0.5);
30 | i1 = floor(M * vec3(vx.y, vy.y, vz.y) + 0.5);
31 | i2 = floor(M * vec3(vx.z, vy.z, vz.z) + 0.5);
32 | i3 = floor(M * vec3(vx.w, vy.w, vz.w) + 0.5);
33 | }
34 | vec4 hash = __psrdnoise3_permute( __psrdnoise3_permute( __psrdnoise3_permute(
35 | vec4(i0.z, i1.z, i2.z, i3.z ))
36 | + vec4(i0.y, i1.y, i2.y, i3.y ))
37 | + vec4(i0.x, i1.x, i2.x, i3.x ));
38 | vec4 theta = hash * 3.883222077;
39 | vec4 sz = hash * -0.006920415 + 0.996539792;
40 | vec4 psi = hash * 0.108705628;
41 | vec4 Ct = cos(theta), St = sin(theta);
42 | vec4 sz_prime = sqrt( 1.0 - sz*sz );
43 | vec4 gx, gy, gz;
44 | if(alpha != 0.0) {
45 | vec4 px = Ct * sz_prime, py = St * sz_prime, pz = sz;
46 | vec4 Sp = sin(psi), Cp = cos(psi), Ctp = St*Sp - Ct*Cp;
47 | vec4 qx = mix( Ctp*St, Sp, sz), qy = mix(-Ctp*Ct, Cp, sz);
48 | vec4 qz = -(py*Cp + px*Sp);
49 | vec4 Sa = vec4(sin(alpha)), Ca = vec4(cos(alpha));
50 | gx = Ca*px + Sa*qx; gy = Ca*py + Sa*qy; gz = Ca*pz + Sa*qz;
51 | }
52 | else {
53 | gx = Ct * sz_prime; gy = St * sz_prime; gz = sz;
54 | }
55 | vec3 g0 = vec3(gx.x, gy.x, gz.x), g1 = vec3(gx.y, gy.y, gz.y);
56 | vec3 g2 = vec3(gx.z, gy.z, gz.z), g3 = vec3(gx.w, gy.w, gz.w);
57 | vec4 w = 0.5-vec4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3));
58 | w = max(w, 0.0); vec4 w2 = w * w, w3 = w2 * w;
59 | vec4 gdotx = vec4(dot(g0,x0), dot(g1,x1), dot(g2,x2), dot(g3,x3));
60 | float n = dot(w3, gdotx);
61 | vec4 dw = -6.0 * w2 * gdotx;
62 | vec3 dn0 = w3.x * g0 + dw.x * x0;
63 | vec3 dn1 = w3.y * g1 + dw.y * x1;
64 | vec3 dn2 = w3.z * g2 + dw.z * x2;
65 | vec3 dn3 = w3.w * g3 + dw.w * x3;
66 | gradient = 39.5 * (dn0 + dn1 + dn2 + dn3);
67 | return 39.5 * n;
68 | }
69 |
70 | float psrdnoise3(vec3 x, vec3 period, float alpha)
71 | {
72 | vec3 gradient;
73 | return psrdnoise3_with_gradient(x, period, alpha, gradient);
74 | }
75 |
76 | float psrdnoise2_with_gradient(vec2 x, vec2 period, float alpha, out vec2 gradient)
77 | {
78 | vec2 uv = vec2(x.x+x.y*0.5, x.y);
79 | vec2 i0 = floor(uv), f0 = fract(uv);
80 | float cmp = step(f0.y, f0.x);
81 | vec2 o1 = vec2(cmp, 1.0-cmp);
82 | vec2 i1 = i0 + o1, i2 = i0 + 1.0;
83 | vec2 v0 = vec2(i0.x - i0.y*0.5, i0.y);
84 | vec2 v1 = vec2(v0.x + o1.x - o1.y*0.5, v0.y + o1.y);
85 | vec2 v2 = vec2(v0.x + 0.5, v0.y + 1.0);
86 | vec2 x0 = x - v0, x1 = x - v1, x2 = x - v2;
87 | vec3 iu, iv, xw, yw;
88 | if(any(greaterThan(period, vec2(0.0)))) {
89 | xw = vec3(v0.x, v1.x, v2.x);
90 | yw = vec3(v0.y, v1.y, v2.y);
91 | if(period.x > 0.0)
92 | xw = mod(vec3(v0.x, v1.x, v2.x), period.x);
93 | if(period.y > 0.0)
94 | yw = mod(vec3(v0.y, v1.y, v2.y), period.y);
95 | iu = floor(xw + 0.5*yw + 0.5); iv = floor(yw + 0.5);
96 | } else {
97 | iu = vec3(i0.x, i1.x, i2.x); iv = vec3(i0.y, i1.y, i2.y);
98 | }
99 | vec3 hash = mod(iu, 289.0);
100 | hash = mod((hash*51.0 + 2.0)*hash + iv, 289.0);
101 | hash = mod((hash*34.0 + 10.0)*hash, 289.0);
102 | vec3 psi = hash*0.07482 + alpha;
103 | vec3 gx = cos(psi); vec3 gy = sin(psi);
104 | vec2 g0 = vec2(gx.x, gy.x);
105 | vec2 g1 = vec2(gx.y, gy.y);
106 | vec2 g2 = vec2(gx.z, gy.z);
107 | vec3 w = 0.8 - vec3(dot(x0, x0), dot(x1, x1), dot(x2, x2));
108 | w = max(w, 0.0); vec3 w2 = w*w; vec3 w4 = w2*w2;
109 | vec3 gdotx = vec3(dot(g0, x0), dot(g1, x1), dot(g2, x2));
110 | float n = dot(w4, gdotx);
111 | vec3 w3 = w2*w; vec3 dw = -8.0*w3*gdotx;
112 | vec2 dn0 = w4.x*g0 + dw.x*x0;
113 | vec2 dn1 = w4.y*g1 + dw.y*x1;
114 | vec2 dn2 = w4.z*g2 + dw.z*x2;
115 | gradient = 10.9*(dn0 + dn1 + dn2);
116 | return 10.9*n;
117 | }
118 |
119 | float psrdnoise2(vec2 x, vec2 period, float alpha)
120 | {
121 | vec2 gradient;
122 | return psrdnoise2_with_gradient(x, period, alpha, gradient);
123 | }
124 |
--------------------------------------------------------------------------------
/addons/ShaderFunction-Extras/ShaderFunction-Logo.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/addons/ShaderFunction-Extras/ShaderFunction-Logo.svg.import:
--------------------------------------------------------------------------------
1 | [remap]
2 |
3 | importer="texture"
4 | type="CompressedTexture2D"
5 | uid="uid://b4tiifecubl47"
6 | path="res://.godot/imported/ShaderFunction-Logo.svg-488ad0c0401905dcd41a26a6d017865d.ctex"
7 | metadata={
8 | "vram_texture": false
9 | }
10 |
11 | [deps]
12 |
13 | source_file="res://addons/ShaderFunction-Extras/ShaderFunction-Logo.svg"
14 | dest_files=["res://.godot/imported/ShaderFunction-Logo.svg-488ad0c0401905dcd41a26a6d017865d.ctex"]
15 |
16 | [params]
17 |
18 | compress/mode=0
19 | compress/high_quality=false
20 | compress/lossy_quality=0.7
21 | compress/hdr_compression=1
22 | compress/normal_map=0
23 | compress/channel_pack=0
24 | mipmaps/generate=false
25 | mipmaps/limit=-1
26 | roughness/mode=0
27 | roughness/src_normal=""
28 | process/fix_alpha_border=true
29 | process/premult_alpha=false
30 | process/normal_map_invert_y=false
31 | process/hdr_as_srgb=false
32 | process/hdr_clamp_exposure=false
33 | process/size_limit=0
34 | detect_3d/compress_to=1
35 | svg/scale=1.0
36 | editor/scale_with_editor_scale=false
37 | editor/convert_colors_with_editor_theme=false
38 |
--------------------------------------------------------------------------------
/addons/ShaderFunction-Extras/Shapes/LicenseInfo.md:
--------------------------------------------------------------------------------
1 | # License Information
2 |
3 | ## shapes.gdshaderinc
4 | ```md
5 | /**************************************************************************/
6 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
7 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
8 | /* */
9 | /* Permission is hereby granted, free of charge, to any person obtaining */
10 | /* a copy of this software and associated documentation files (the */
11 | /* "Software"), to deal in the Software without restriction, including */
12 | /* without limitation the rights to use, copy, modify, merge, publish, */
13 | /* distribute, sublicense, and/or sell copies of the Software, and to */
14 | /* permit persons to whom the Software is furnished to do so, subject to */
15 | /* the following conditions: */
16 | /* */
17 | /* The above copyright notice and this permission notice shall be */
18 | /* included in all copies or substantial portions of the Software. */
19 | /* */
20 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
21 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
22 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
23 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
24 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
25 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
26 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
27 | /**************************************************************************/
28 | ```
29 |
--------------------------------------------------------------------------------
/addons/ShaderFunction-Extras/Shapes/shapes.gdshaderinc:
--------------------------------------------------------------------------------
1 | float polygon(vec2 uv, float width, int sides) {
2 | uv = uv * 2.0 - 1.0;
3 | float angle = atan(uv.x, uv.y);
4 | float radius = 6.28318530718 / float(sides);
5 | float dist = cos(floor(0.5 + angle / radius) * radius - angle) * length(uv);
6 | return step(width, dist);
7 | }
8 |
9 | float circle(vec2 uv, float radius, float feather) {
10 | return smoothstep(radius, radius + feather, dot(uv, uv) * 4.0);
11 | }
12 |
13 | float square(vec2 uv, float width) {
14 | uv = uv * 2.0 - 1.0;
15 | vec2 abs_uv = abs(uv.xy);
16 | return step(width, max(abs_uv.x, abs_uv.y));
17 | }
18 |
19 | float square_stroke(vec2 uv, float width, float stroke_width) {
20 | uv = uv * 2.0 - 1.0;
21 | vec2 abs_uv = abs(uv.xy);
22 | float dist = max(abs_uv.x, abs_uv.y);
23 | return 1.0 - (step(width, dist) - step(width + stroke_width, dist));
24 | }
25 |
26 | float square_rounded(vec2 uv, float width, float radius) {
27 | uv = uv * 2.0 - 1.0;
28 | radius *= width;
29 | vec2 abs_uv = abs(uv.xy) - radius;
30 | vec2 dist = vec2(max(abs_uv.xy, 0.0));
31 | return step(width - radius, length(dist));
32 | }
33 |
34 | float swirl(vec2 uv, float size, int arms) {
35 | float angle = atan(-uv.y + 0.5, uv.x - 0.5);
36 | float len = length(uv - vec2(0.5, 0.5));
37 | return sin(len * size + angle * float(arms));
38 | }
39 |
40 | float line(vec2 uv, vec2 p1, vec2 p2, float width) {
41 | float dist = distance(p1, p2);
42 | float dist_uv = distance(p1, uv);
43 | return 1.0 - floor(1.0 - (0.001 * width) + distance (mix(p1, p2, clamp(dist_uv / dist, 0.0, 1.0)), uv));
44 | }
45 |
46 | float border(vec2 uv, float border_width) {
47 | vec2 bottom_left = step(vec2(border_width), uv);
48 | vec2 top_right = step(vec2(border_width), 1.0 - uv);
49 | return bottom_left.x * bottom_left.y * top_right.x * top_right.y;
50 | }
51 |
52 |
--------------------------------------------------------------------------------
/addons/ShaderFunction-Extras/UV/LicenseInfo.md:
--------------------------------------------------------------------------------
1 | # License Information
2 |
3 | ## uv.gdshaderinc
4 | `uv_panning`, `uv_scaling`
5 | ```md
6 | /**************************************************************************/
7 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
8 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
9 | /* */
10 | /* Permission is hereby granted, free of charge, to any person obtaining */
11 | /* a copy of this software and associated documentation files (the */
12 | /* "Software"), to deal in the Software without restriction, including */
13 | /* without limitation the rights to use, copy, modify, merge, publish, */
14 | /* distribute, sublicense, and/or sell copies of the Software, and to */
15 | /* permit persons to whom the Software is furnished to do so, subject to */
16 | /* the following conditions: */
17 | /* */
18 | /* The above copyright notice and this permission notice shall be */
19 | /* included in all copies or substantial portions of the Software. */
20 | /* */
21 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
22 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
23 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
24 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
25 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
26 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
27 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
28 | /**************************************************************************/
29 | ```
30 |
31 | `uv_flipbook`
32 | ````md
33 | from https://github.com/thnewlands/unity-surfaceshader-flipbook
34 |
35 | MIT License
36 |
37 | Copyright (c) 2017 Thomas Newlands
38 |
39 | Permission is hereby granted, free of charge, to any person obtaining a copy
40 | of this software and associated documentation files (the "Software"), to deal
41 | in the Software without restriction, including without limitation the rights
42 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
43 | copies of the Software, and to permit persons to whom the Software is
44 | furnished to do so, subject to the following conditions:
45 |
46 | The above copyright notice and this permission notice shall be included in all
47 | copies or substantial portions of the Software.
48 |
49 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
50 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
51 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
52 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
53 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
54 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
55 | SOFTWARE.
56 | ```
57 |
--------------------------------------------------------------------------------
/addons/ShaderFunction-Extras/UV/uv.gdshaderinc:
--------------------------------------------------------------------------------
1 | vec2 uv_panning(vec2 uv, vec2 scale, vec2 offset) {
2 | return offset * scale + uv;
3 | }
4 |
5 | vec2 uv_scaling(vec2 uv, vec2 scale, vec2 pivot) {
6 | return (uv - pivot) * scale + pivot;
7 | }
8 |
9 | vec2 uv_rotate(vec2 uv, vec2 pivot, float angle) {
10 | mat2 rotation = mat2(vec2(sin(angle), -cos(angle)), vec2(cos(angle), sin(angle)));
11 | uv -= pivot;
12 | uv = uv * rotation;
13 | uv += pivot;
14 | return uv;
15 | }
16 |
17 | vec2 uv_polar_coord_canvas(vec2 uv, vec2 center, float zoom, float repeat) {
18 | vec2 dir = uv - center;
19 | float radius = length(dir) * 2.0;
20 | float angle = atan(dir.y, dir.x) * 1.0/(PI * 2.0);
21 | return mod(vec2(radius * zoom, angle * repeat), 1.0);
22 | }
23 |
24 | vec2 uv_polar_coord_spatial(vec2 uv, vec2 center, float zoom, float repeat) {
25 | vec2 dir = uv - center;
26 | float radius = length(dir) * 2.0;
27 | float angle = atan(dir.y, dir.x) * 1.0/(PI * 2.0);
28 | return vec2(radius * zoom, angle * repeat);
29 | }
30 |
31 | vec2 uv_flipbook(vec2 uv, int columns, int rows, int starting_frame, int ending_frame, float anim_speed) {
32 | starting_frame += int(fract(TIME * anim_speed) * float(ending_frame));
33 | float frame = float(clamp(starting_frame, 0, ending_frame));
34 | vec2 offPerFrame = vec2((1.0 / float(columns)), (1.0 / float(rows)));
35 |
36 | vec2 sprite_size = vec2(uv.x / float(columns), uv.y / float(rows));
37 | vec2 current_sprite = vec2(0.0, 1.0 - offPerFrame.y);
38 | current_sprite.x += frame * offPerFrame.x;
39 | float rowIndex;
40 | float _mod = modf(frame / float(columns), rowIndex);
41 | current_sprite.y -= rowIndex * offPerFrame.y;
42 | current_sprite.x -= rowIndex * float(columns) * offPerFrame.x;
43 |
44 | vec2 sprite_uv = (sprite_size + current_sprite);
45 |
46 | return sprite_uv;
47 | }
48 |
49 | vec2 uv_twirl(vec2 uv, vec2 center, float strength, vec2 offset) {
50 | vec2 __delta = uv - center;
51 | float __angle = strength * length(__delta);
52 | float __x = cos(__angle) * __delta.x - sin(__angle) * __delta.y;
53 | float __y = sin(__angle) * __delta.x + cos(__angle) * __delta.y;
54 | return vec2(__x + center.x + offset.x, __y + center.y + offset.y);
55 | }
56 |
57 | vec2 uv_grid_tiler(vec2 uv, float columns, float rows) {
58 | return fract(vec2(uv.x * columns, uv.y * rows));
59 | }
60 |
--------------------------------------------------------------------------------
/addons/ShaderFunction-Extras/Utility/LicenseInfo.md:
--------------------------------------------------------------------------------
1 | # License Information
2 |
3 | ## utility.gdshaderinc
4 | ```md
5 | /**************************************************************************/
6 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
7 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
8 | /* */
9 | /* Permission is hereby granted, free of charge, to any person obtaining */
10 | /* a copy of this software and associated documentation files (the */
11 | /* "Software"), to deal in the Software without restriction, including */
12 | /* without limitation the rights to use, copy, modify, merge, publish, */
13 | /* distribute, sublicense, and/or sell copies of the Software, and to */
14 | /* permit persons to whom the Software is furnished to do so, subject to */
15 | /* the following conditions: */
16 | /* */
17 | /* The above copyright notice and this permission notice shall be */
18 | /* included in all copies or substantial portions of the Software. */
19 | /* */
20 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
21 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
22 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
23 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
24 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
25 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
26 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
27 | /**************************************************************************/
28 | ```
29 |
--------------------------------------------------------------------------------
/addons/ShaderFunction-Extras/Utility/utility.gdshaderinc:
--------------------------------------------------------------------------------
1 | vec4 depth_camera_vulkan(sampler2D depth_tex, vec2 screen_uv, mat4 inv_proj_mat) {
2 | vec4 depth = texture(depth_tex, screen_uv);
3 | return inv_proj_mat * vec4(screen_uv * 2.0 - 1.0, depth.x, 1.0);
4 | }
5 |
6 | vec4 depth_camera_gles(sampler2D depth_tex, vec2 screen_uv, mat4 inv_proj_mat) {
7 | vec4 depth = texture(depth_tex, screen_uv);
8 | return inv_proj_mat * vec4(vec3(screen_uv, depth.x) * 2.0 - 1.0, 1.0);
9 | }
10 |
11 | vec4 depth_vertex_vulkan(sampler2D depth_tex, vec2 screen_uv, mat4 inv_proj_mat) {
12 | vec4 depth_world_pos = depth_camera_vulkan(depth_tex, screen_uv, inv_proj_mat);
13 | depth_world_pos.xyz /= depth_world_pos.w;
14 | return depth_world_pos;
15 | }
16 |
17 | vec4 depth_vertex_gles(sampler2D depth_tex, vec2 screen_uv, mat4 inv_proj_mat) {
18 | vec4 depth_world_pos = depth_camera_gles(depth_tex, screen_uv, inv_proj_mat);
19 | depth_world_pos.xyz /= depth_world_pos.w;
20 | return depth_world_pos;
21 | }
22 |
23 | float linear_scene_depth_vulkan(sampler2D depth_tex, vec2 screen_uv, mat4 inv_proj_mat) {
24 | vec4 depth_world_pos = depth_vertex_vulkan(depth_tex, screen_uv, inv_proj_mat);
25 | return -depth_world_pos.z;
26 | }
27 |
28 | float linear_scene_depth_gles(sampler2D depth_tex, vec2 screen_uv, mat4 inv_proj_mat) {
29 | vec4 depth_world_pos = depth_vertex_gles(depth_tex, screen_uv, inv_proj_mat);
30 | return -depth_world_pos.z;
31 | }
32 |
33 | float distance_fade(float min_dist, float max_dist, vec3 vertex) {
34 | return clamp(smoothstep(min_dist, max_dist, -vertex.z), 0.0, 1.0);
35 | }
36 |
37 | float proximity_camera_fade_vulkan(sampler2D depth_tex, vec2 screen_uv, mat4 inv_proj_mat, vec3 vertex, float fade_dist) {
38 | vec4 depth_world_pos = depth_camera_vulkan(depth_tex, screen_uv, inv_proj_mat);
39 | return clamp(1.0 - smoothstep(depth_world_pos.z + fade_dist, depth_world_pos.z, vertex.z), 0.0, 1.0);
40 | }
41 |
42 | float proximity_camera_fade_gles(sampler2D depth_tex, vec2 screen_uv, mat4 inv_proj_mat, vec3 vertex, float fade_dist) {
43 | vec4 depth_world_pos = depth_camera_gles(depth_tex, screen_uv, inv_proj_mat);
44 | return clamp(1.0 - smoothstep(depth_world_pos.z + fade_dist, depth_world_pos.z, vertex.z), 0.0, 1.0);
45 | }
46 |
47 | float proximity_vertex_fade_vulkan(sampler2D depth_tex, vec2 screen_uv, mat4 inv_proj_mat, vec3 vertex, float fade_dist) {
48 | vec4 depth_world_pos = depth_vertex_vulkan(depth_tex, screen_uv, inv_proj_mat);
49 | return clamp(1.0 - smoothstep(depth_world_pos.z + fade_dist, depth_world_pos.z, vertex.z), 0.0, 1.0);
50 | }
51 |
52 | float proximity_vertex_fade_gles(sampler2D depth_tex, vec2 screen_uv, mat4 inv_proj_mat, vec3 vertex, float fade_dist) {
53 | vec4 depth_world_pos = depth_vertex_gles(depth_tex, screen_uv, inv_proj_mat);
54 | return clamp(1.0 - smoothstep(depth_world_pos.z + fade_dist, depth_world_pos.z, vertex.z), 0.0, 1.0);
55 | }
56 |
57 | vec3 world_position_from_depth_vulkan(sampler2D depth_tex, vec2 screen_uv, mat4 inv_proj_mat, mat4 inv_view_mat) {
58 | vec4 depth_world_pos = depth_vertex_vulkan(depth_tex, screen_uv, inv_proj_mat);
59 | return (inv_view_mat * depth_world_pos).xyz;
60 | }
61 |
62 | vec3 world_position_from_depth_gles(sampler2D depth_tex, vec2 screen_uv, mat4 inv_proj_mat, mat4 inv_view_mat) {
63 | vec4 depth_world_pos = depth_vertex_gles(depth_tex, screen_uv, inv_proj_mat);
64 | return (inv_view_mat * depth_world_pos).xyz;
65 | }
66 |
67 | vec3 screen_normal_world_space(sampler2D normal_rough_tex, vec2 screen_uv, mat4 inv_view_mat) {
68 | vec3 normals = texture(normal_rough_tex, screen_uv).xyz;
69 | return mat3(inv_view_mat) * (normals * 2.0 - 1.0);
70 | }
71 |
72 | mat4 rotation_matrix_by_axis(float angle, vec3 axis) {
73 | vec3 n_axis = normalize(axis);
74 | mat3 rot_matrix = mat3(
75 | vec3(
76 | cos(angle) + n_axis.x * n_axis.x * (1.0 - cos(angle)),
77 | n_axis.x * n_axis.y * (1.0 - cos(angle)) - n_axis.z * sin(angle),
78 | n_axis.x * n_axis.z * (1.0 - cos(angle)) + n_axis.y * sin(angle)
79 | ),
80 | vec3(
81 | n_axis.y * n_axis.x * (1.0 - cos(angle)) + n_axis.z * sin(angle),
82 | cos(angle) + n_axis.y * n_axis.y * (1.0 - cos(angle)),
83 | n_axis.y * n_axis.z * (1.0 - cos(angle)) - n_axis.x * sin(angle)
84 | ),
85 | vec3(
86 | n_axis.z * n_axis.x * (1.0 - cos(angle)) - n_axis.y * sin(angle),
87 | n_axis.z * n_axis.y * (1.0 - cos(angle)) + n_axis.x * sin(angle),
88 | cos(angle) + n_axis.z * n_axis.z * (1.0 - cos(angle))
89 | )
90 | );
91 | return mat4(rot_matrix);
92 | }
93 |
94 | vec3 rotate_by_axis(vec3 input, float angle, vec3 axis) {
95 | return input * mat3(rotation_matrix_by_axis(angle, axis));
96 | }
97 |
98 | // 3D Noise with friendly permission by Inigo Quilez\n";
99 | vec3 hash_noise_range(vec3 p) {
100 | p *= mat3(vec3(127.1, 311.7, -53.7), vec3(269.5, 183.3, 77.1), vec3(-301.7, 27.3, 215.3));
101 | return 2.0 * fract(fract(p)*4375.55) -1.;
102 | }
103 |
104 | float random_range(vec3 seed, float min, float max) {
105 | return mix(min, max, hash_noise_range(seed).x);
106 | }
107 |
108 | float remap(float value, float input_min, float input_max, float output_min, float output_max) {
109 | float _input_range = input_max - input_min;
110 | float _output_range = output_max - output_min;
111 | return output_min + _output_range * ((value - input_min) / _input_range);
112 | }
113 |
114 | float fresnel(float amount, vec3 normal, vec3 view) {
115 | return pow((1.0 - clamp(dot(normalize(normal), normalize(view)), 0.0, 1.0 )), amount);
116 | }
117 |
118 | vec3 fresnel_glow(float amount, float intensity, vec3 color, vec3 normal, vec3 view) {
119 | return pow((1.0 - dot(normalize(normal), normalize(view))), amount) * color * intensity;
120 | }
121 |
122 | float smooth_clamp(float value, float min, float max) {
123 | return smoothstep(0.0, 1.0, (value - min) / (max - min)) * (max - min) + min;
124 | }
125 |
126 | float soft_clamp(float value, float min, float max) {
127 | return smoothstep(0.0, 1.0, (2.0 / 3.0) * (value - min) / (max - min) + (1.0 / 6.0)) * (max - min) + min;
128 | }
129 |
130 | float saturate(float value, float scale) {
131 | return clamp(((value - 0.5) * scale) + 0.5, 0.0, 1.0);
132 | }
133 |
134 | vec3 vertex_billboard(vec2 uv, mat4 view_mat, vec3 vertex, float scale) {
135 | uv.x = remap(uv.x, 0.0, 1.0, -1.0, 1.0);
136 | uv.y = remap(uv.y, 0.0, 1.0, -1.0, 1.0);
137 | uv *= scale;
138 | return vertex + ((vec4(uv, 0.0, 0.0) * view_mat)).xyz;
139 | }
140 |
--------------------------------------------------------------------------------
/addons/ShaderFunction-Extras/Wave/wave.gdshaderinc:
--------------------------------------------------------------------------------
1 | float sawtooth_wave(float IN, float amplitude, float frequency, float height) {
2 | return 2.0 * amplitude * ((IN/frequency) - floor((1.0/2.0) + (IN / frequency))) + height;
3 | }
4 |
5 | float sine_wave(float IN, float amplitude, float frequency, float phase, float height) {
6 | return amplitude * sin(2.0 * PI * frequency * IN + phase) + height;
7 | }
8 |
9 | float sine_wave_angular(float IN, float amplitude, float __ang_frequency, float phase, float height) {
10 | return amplitude * sin(__ang_frequency * IN + phase) + height;
11 | }
12 |
13 | float square_wave(float IN, float amplitude, float frequency, float height) {
14 | return amplitude*sign(sin(2.0 * PI * IN * frequency)) + height;
15 | }
16 |
17 | float triangle_wave(float IN, float amplitude, float frequency, float height) {
18 | return 1.0 - amplitude * abs(round(IN / frequency) - (IN / frequency)) + height;
19 | }
20 |
--------------------------------------------------------------------------------
/project.godot:
--------------------------------------------------------------------------------
1 | ; Engine configuration file.
2 | ; It's best edited using the editor UI and not directly,
3 | ; since the parameters that go here are not all obvious.
4 | ;
5 | ; Format:
6 | ; [section] ; section goes between []
7 | ; param=value ; assign values to parameters
8 |
9 | config_version=5
10 |
11 | [application]
12 |
13 | config/name="ShaderFunction-Extras"
14 | config/features=PackedStringArray("4.2", "Forward Plus")
15 | config/icon="res://addons/ShaderFunction-Extras/ShaderFunction-Logo.svg"
16 |
--------------------------------------------------------------------------------