shaderlib: Implement a simple pixelate function (effects.gdshaderinc), examples/hsv.gdshader -> color_and_pixelate.gdshader; implements #30
This commit is contained in:
parent
6c48c9fe72
commit
4d12ad4432
4 changed files with 30 additions and 10 deletions
13
examples/color_and_pixelate.gdshader
Normal file
13
examples/color_and_pixelate.gdshader
Normal file
|
@ -0,0 +1,13 @@
|
|||
shader_type canvas_item;
|
||||
|
||||
#include "res://shaderlib/hsv.gdshaderinc"
|
||||
#include "res://shaderlib/effects.gdshaderinc"
|
||||
|
||||
//!load ./swamp.jpg
|
||||
|
||||
void fragment() {
|
||||
COLOR = pixelate(TEXTURE, UV, 200.0);
|
||||
vec4 hsv = rgb2hsv(COLOR);
|
||||
COLOR = hsv_offset(COLOR, 0.65, .42-(hsv.y*.3), -.125);
|
||||
COLOR = hsv_multiply(COLOR, 1.0, 1.0, 1.25);
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
shader_type canvas_item;
|
||||
|
||||
#include "res://shaderlib/hsv.gdshaderinc"
|
||||
|
||||
//!load ./swamp.jpg
|
||||
|
||||
void fragment() {
|
||||
COLOR = hsv_multiply(hsv_offset(COLOR, -0.3, 0.9, 0.0), 1.0, 0.44, 1.0);
|
||||
}
|
14
shaderlib/effects.gdshaderinc
Normal file
14
shaderlib/effects.gdshaderinc
Normal file
|
@ -0,0 +1,14 @@
|
|||
|
||||
// pixelate by lowering uv resolution
|
||||
vec4 pixelate(sampler2D tex, vec2 uv, float resolution_x) {
|
||||
vec2 texture_size = vec2(textureSize(tex, 0));
|
||||
vec2 ratio;
|
||||
if (texture_size.x > texture_size.y) {
|
||||
ratio = vec2(texture_size.x / texture_size.y, 1.0);
|
||||
}
|
||||
else {
|
||||
ratio = vec2(1.0, texture_size.y / texture_size.x);
|
||||
}
|
||||
vec2 r = ratio * resolution_x;
|
||||
return texture(tex, trunc(uv * r) / r);
|
||||
}
|
|
@ -131,12 +131,14 @@ const gdshader_preprocessor = [
|
|||
var shaderlib_regex = {
|
||||
"hsv": RegEx.create_from_string(r'\s*\#include\s+\"res\:\/\/shaderlib\/hsv\.gdshaderinc\"'),
|
||||
"transform": RegEx.create_from_string(r'\s*\#include\s+\"res\:\/\/shaderlib\/transform\.gdshaderinc\"'),
|
||||
"transparency": RegEx.create_from_string(r'\s*\#include\s+\"res\:\/\/shaderlib\/transparency\.gdshaderinc\"')
|
||||
"transparency": RegEx.create_from_string(r'\s*\#include\s+\"res\:\/\/shaderlib\/transparency\.gdshaderinc\"'),
|
||||
"effects": RegEx.create_from_string(r'\s*\#include\s+\"res\:\/\/shaderlib\/effects\.gdshaderinc\"')
|
||||
}
|
||||
const shaderlib_functions = {
|
||||
"hsv": ["rgb2hsv", "hsv2rgb", "hsv_offset", "hsv_multiply"],
|
||||
"transform": ["place_texture"],
|
||||
"transparency": ["alpha_blend"],
|
||||
"effects": ["pixelate"]
|
||||
}
|
||||
#
|
||||
# configure Highlighter
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue