Skip to content

Commit 3b4c93e

Browse files
authored
Merge pull request #11 from paddy-exe/more-funcs
Added functions and added provided function list to README
2 parents 643e681 + 1c3dc12 commit 3b4c93e

File tree

4 files changed

+136
-0
lines changed

4 files changed

+136
-0
lines changed

README.md

+63
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,66 @@ use specific functions, you can copy and paste it inside your shader code still.
2626

2727
## ℹ️ Contributing
2828
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.
29+
30+
## Provided Functions
31+
32+
<details>
33+
<summary>
34+
Click me to enlarge
35+
</summary>
36+
37+
### Color
38+
#### Blend Modes
39+
* `blend_normal`
40+
* `blend_dissolve`
41+
* `blend_multiply`
42+
* `blend_screen`
43+
* `blend_overlay`
44+
* `blend_hard_light`
45+
* `blend_soft_light`
46+
* `blend_burn`
47+
* `blend_dodge`
48+
* `blend_lighten`
49+
* `blend_darken`
50+
* `blend_difference`
51+
* `blend_additive`
52+
* `blend_addsub`
53+
* `blend_linear_light`
54+
* `blend_vivid_light`
55+
* `blend_pin_light`
56+
* `blend_hard_mix`
57+
* `blend_exclusion`
58+
59+
#### Color Conversion
60+
* `greyscale`
61+
* `hsv_to_rgb`
62+
* `rgb_to_hsv`
63+
64+
### Noise
65+
* `psrdnoise3_with_gradient`
66+
* `psrdnoise3`
67+
* `psrdnoise2_with_gradient`
68+
* `psrdnoise2`
69+
70+
### Utility
71+
* `linear_scene_depth_*`
72+
* `distance_fade`
73+
* `proximity_fade_*`
74+
* `random_range`
75+
* `remap`
76+
77+
### UV
78+
* `uv_panning`
79+
* `uv_scaling`
80+
* `uv_polar_coord_*`
81+
* `uv_flipbook`
82+
* `uv_twirl`
83+
84+
### Wave
85+
* `sawtooth_wave`
86+
* `sine_wave`
87+
* `sine_wave_angular`
88+
* `square_wave`
89+
* `triangle_wave`
90+
91+
</details>

addons/ShaderFunction-Extras/UV/LicenseInfo.md

+28
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# License Information
22

33
## uv.gdshaderinc
4+
`uv_panning`, `uv_scaling`
45
```md
56
/**************************************************************************/
67
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
@@ -26,3 +27,30 @@
2627
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
2728
/**************************************************************************/
2829
```
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+
```

addons/ShaderFunction-Extras/UV/uv.gdshaderinc

+26
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,29 @@ vec2 uv_polar_coord_spatial(vec2 uv, vec2 center, float zoom, float repeat) {
1919
float angle = atan(dir.y, dir.x) * 1.0/(PI * 2.0);
2020
return vec2(radius * zoom, angle * repeat);
2121
}
22+
23+
vec2 uv_flipbook(vec2 uv, int columns, int rows, int starting_frame, int ending_frame, float anim_speed) {
24+
starting_frame += int(fract(TIME * anim_speed) * float(ending_frame));
25+
float frame = float(clamp(starting_frame, 0, ending_frame));
26+
vec2 offPerFrame = vec2((1.0 / float(columns)), (1.0 / float(rows)));
27+
28+
vec2 sprite_size = vec2(uv.x / float(columns), uv.y / float(rows));
29+
vec2 current_sprite = vec2(0.0, 1.0 - offPerFrame.y);
30+
current_sprite.x += frame * offPerFrame.x;
31+
float rowIndex;
32+
float _mod = modf(frame / float(columns), rowIndex);
33+
current_sprite.y -= rowIndex * offPerFrame.y;
34+
current_sprite.x -= rowIndex * float(columns) * offPerFrame.x;
35+
36+
vec2 sprite_uv = (sprite_size + current_sprite);
37+
38+
return sprite_uv;
39+
}
40+
41+
vec2 uv_twirl(vec2 uv, vec2 center, float strength, vec2 offset) {
42+
vec2 __delta = uv - center;
43+
float __angle = strength * length(__delta);
44+
float __x = cos(__angle) * __delta.x - sin(__angle) * __delta.y;
45+
float __y = sin(__angle) * __delta.x + cos(__angle) * __delta.y;
46+
return vec2(__x + center.x + offset.x, __y + center.y + offset.y);
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
}

0 commit comments

Comments
 (0)