SHADER
This commit is contained in:
@@ -102,3 +102,26 @@ throw_carry={
|
||||
[rendering]
|
||||
|
||||
rendering_device/driver.windows="d3d12"
|
||||
|
||||
[shader_globals]
|
||||
|
||||
diffuse_curve={
|
||||
"type": "sampler2D",
|
||||
"value": ""
|
||||
}
|
||||
specular_smoothness={
|
||||
"type": "float",
|
||||
"value": 0.05
|
||||
}
|
||||
fresnel_smoothness={
|
||||
"type": "float",
|
||||
"value": 0.05
|
||||
}
|
||||
outline_width={
|
||||
"type": "float",
|
||||
"value": 4.0
|
||||
}
|
||||
outline_color={
|
||||
"type": "color",
|
||||
"value": Color(0, 0, 0, 1)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,199 @@
|
||||
shader_type spatial;
|
||||
|
||||
#define USE_ALPHA 0
|
||||
#define USE_ALPHA_CUTOFF 0
|
||||
#define USE_EMISSION 0
|
||||
#define USE_REFLECTIONS 0
|
||||
#define USE_NORMAL_MAP 0
|
||||
#define USE_OCCLUSION 0
|
||||
#define USE_HEIGHT_MAP 0
|
||||
#define USE_ANISOTROPY 0
|
||||
#define USE_BACKLIGHT 0
|
||||
#define USE_REFRACTION 0
|
||||
|
||||
#if USE_ALPHA
|
||||
render_mode depth_draw_always;
|
||||
#endif
|
||||
|
||||
#include "includes/base-cel-shader.gdshaderinc"
|
||||
|
||||
#if USE_EMISSION
|
||||
#include "includes/emission.gdshaderinc"
|
||||
#endif
|
||||
|
||||
#if USE_REFLECTIONS
|
||||
#include "includes/reflections.gdshaderinc"
|
||||
#endif
|
||||
|
||||
#if USE_NORMAL_MAP
|
||||
#include "includes/normal-map.gdshaderinc"
|
||||
#endif
|
||||
|
||||
#if USE_OCCLUSION
|
||||
#include "includes/occlusion.gdshaderinc"
|
||||
#endif
|
||||
|
||||
#if USE_HEIGHT_MAP
|
||||
#include "includes/height-map.gdshaderinc"
|
||||
#endif
|
||||
|
||||
#if USE_ANISOTROPY
|
||||
#include "includes/anisotropy.gdshaderinc"
|
||||
#endif
|
||||
|
||||
#if USE_BACKLIGHT
|
||||
#include "includes/backlight.gdshaderinc"
|
||||
#endif
|
||||
|
||||
#if USE_REFRACTION
|
||||
#include "includes/refraction.gdshaderinc"
|
||||
#elif !USE_REFRACTION && USE_ALPHA
|
||||
#include "includes/transparency.gdshaderinc"
|
||||
#endif
|
||||
|
||||
group_uniforms BaseProperties;
|
||||
#if USE_ALPHA_CUTOFF
|
||||
uniform float alpha_cutoff: hint_range(0.0, 1.0) = 0.5;
|
||||
#endif
|
||||
uniform vec4 color: source_color = vec4(0.7, 0.12, 0.86, 1.0);
|
||||
uniform sampler2D base_texture: source_color;
|
||||
uniform vec4 specular: source_color = vec4(0.3, 0.3, 0.3, 0.5);
|
||||
uniform sampler2D specular_texture: hint_default_white;
|
||||
uniform vec4 fresnel: source_color = vec4(0.2, 0.2, 0.2, 0.3);
|
||||
uniform sampler2D fresnel_texture: hint_default_white;
|
||||
group_uniforms;
|
||||
|
||||
varying vec3 SPECULAR_COLOR;
|
||||
varying float SPECULAR_STRENGTH;
|
||||
varying vec3 FRESNEL_COLOR;
|
||||
varying float FRESNEL_STRENGTH;
|
||||
|
||||
varying vec2 base_uv;
|
||||
|
||||
group_uniforms Tiling;
|
||||
uniform vec2 uv_scale = vec2(1,1);
|
||||
uniform vec2 uv_offset = vec2(0,0);
|
||||
group_uniforms;
|
||||
|
||||
void vertex() {
|
||||
UV = UV * uv_scale.xy + uv_offset.xy;
|
||||
#if !USE_HEIGHT_MAP
|
||||
base_uv = UV;
|
||||
#endif
|
||||
}
|
||||
|
||||
void fragment() {
|
||||
#if USE_HEIGHT_MAP
|
||||
base_uv = height_map_fragment(UV, VERTEX, TANGENT, BINORMAL, NORMAL);
|
||||
#endif
|
||||
|
||||
#if USE_ALPHA
|
||||
float alpha = color.a * texture(base_texture, base_uv).a;
|
||||
ALBEDO *= alpha;
|
||||
#elif USE_ALPHA_CUTOFF
|
||||
ALPHA = color.a * texture(base_texture, base_uv).a;
|
||||
ALPHA_SCISSOR_THRESHOLD = color.a * texture(base_texture, base_uv).a;
|
||||
#endif
|
||||
|
||||
#if USE_REFRACTION && USE_ALPHA
|
||||
EMISSION += refraction_fragment(alpha, NORMAL, SCREEN_UV, FRAGCOORD.z);
|
||||
#elif !USE_REFRACTION && USE_ALPHA
|
||||
EMISSION += transparency_fragment(alpha, SCREEN_UV);
|
||||
#endif
|
||||
|
||||
SPECULAR_COLOR = specular.rgb * texture(specular_texture, base_uv).rgb;
|
||||
SPECULAR_STRENGTH = specular.a * texture(specular_texture, base_uv).a;
|
||||
FRESNEL_COLOR = fresnel.rgb * texture(fresnel_texture, base_uv).rgb;
|
||||
FRESNEL_STRENGTH = fresnel.a * texture(fresnel_texture, base_uv).a;
|
||||
|
||||
#if USE_EMISSION
|
||||
EMISSION += emission_fragment(base_uv);
|
||||
#endif
|
||||
|
||||
#if USE_REFLECTIONS
|
||||
Surface surf = reflections_fragment(UV);
|
||||
METALLIC = surf.metallic;
|
||||
ROUGHNESS = surf.roughness;
|
||||
#endif
|
||||
|
||||
#if USE_NORMAL_MAP
|
||||
NormalData normal = normal_map_fragment(base_uv, NORMAL, TANGENT, BINORMAL);
|
||||
NORMAL = normal.vector;
|
||||
NORMAL_MAP = normal.map;
|
||||
NORMAL_MAP_DEPTH = normal.depth;
|
||||
#endif
|
||||
|
||||
#if USE_OCCLUSION
|
||||
OcclusionData occlusion = occlusion_fragment(base_uv);
|
||||
AO = occlusion.ao;
|
||||
AO_LIGHT_AFFECT = occlusion.ao_light_affect;
|
||||
#endif
|
||||
|
||||
#if USE_ANISOTROPY
|
||||
AnisotropyData aniso = anisotropy_fragment(UV);
|
||||
ANISOTROPY_DIR = aniso.direction;
|
||||
ANISOTROPY_RATIO = aniso.ratio;
|
||||
#endif
|
||||
|
||||
#if USE_BACKLIGHT
|
||||
BACKLIGHT = backlight_fragment(base_uv);
|
||||
#endif
|
||||
|
||||
ALBEDO = color.rgb * texture(base_texture, base_uv).rgb;
|
||||
}
|
||||
|
||||
void light() {
|
||||
#if USE_BACKLIGHT
|
||||
DIFFUSE_LIGHT += backlight_diffuse(
|
||||
ALBEDO,
|
||||
LIGHT_COLOR,
|
||||
LIGHT,
|
||||
NORMAL,
|
||||
ATTENUATION,
|
||||
BACKLIGHT
|
||||
);
|
||||
#else
|
||||
DIFFUSE_LIGHT += diffuse_light(
|
||||
ALBEDO,
|
||||
LIGHT_COLOR,
|
||||
LIGHT,
|
||||
NORMAL,
|
||||
ATTENUATION
|
||||
);
|
||||
#endif
|
||||
|
||||
#if USE_ANISOTROPY
|
||||
SPECULAR_LIGHT += anisotropy_specular(
|
||||
LIGHT_COLOR,
|
||||
SPECULAR_COLOR,
|
||||
SPECULAR_STRENGTH,
|
||||
NORMAL,
|
||||
VIEW,
|
||||
LIGHT,
|
||||
ATTENUATION,
|
||||
UV,
|
||||
ANISOTROPY_DIR,
|
||||
ANISOTROPY_RATIO
|
||||
);
|
||||
#else
|
||||
SPECULAR_LIGHT += specular_light(
|
||||
LIGHT_COLOR,
|
||||
SPECULAR_COLOR,
|
||||
SPECULAR_STRENGTH,
|
||||
NORMAL,
|
||||
VIEW,
|
||||
LIGHT,
|
||||
ATTENUATION
|
||||
);
|
||||
#endif
|
||||
|
||||
SPECULAR_LIGHT += fresnel_light(
|
||||
LIGHT_COLOR,
|
||||
FRESNEL_COLOR,
|
||||
FRESNEL_STRENGTH,
|
||||
NORMAL,
|
||||
VIEW,
|
||||
LIGHT,
|
||||
ATTENUATION
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://wepsb3f7nni
|
||||
@@ -0,0 +1,54 @@
|
||||
#include "base-cel-shader.gdshaderinc"
|
||||
|
||||
group_uniforms Anisotropy;
|
||||
uniform float anisotropy_ratio: hint_range(-1,1) = 0.0;
|
||||
uniform vec3 anisotropy_direction = vec3(0.0, -1.0, 0.0);
|
||||
uniform float aniso_map_dir_ratio: hint_range(0,1) = 0.0;
|
||||
uniform sampler2D anisotropy_flowmap: hint_anisotropy;
|
||||
group_uniforms;
|
||||
|
||||
varying vec3 ANISOTROPY_DIR;
|
||||
varying float ANISOTROPY_RATIO;
|
||||
|
||||
struct AnisotropyData {
|
||||
vec3 direction;
|
||||
float ratio;
|
||||
};
|
||||
|
||||
AnisotropyData anisotropy_fragment(vec2 uv) {
|
||||
return AnisotropyData(
|
||||
mix(
|
||||
normalize(anisotropy_direction),
|
||||
texture(anisotropy_flowmap, uv).rgb * 2.0 - 1.0,
|
||||
aniso_map_dir_ratio
|
||||
),
|
||||
anisotropy_ratio * texture(anisotropy_flowmap, uv).a
|
||||
);
|
||||
}
|
||||
|
||||
vec3 anisotropy_specular(
|
||||
vec3 light_color,
|
||||
vec3 specular_color,
|
||||
float specular_strength,
|
||||
vec3 normal,
|
||||
vec3 view,
|
||||
vec3 light,
|
||||
float attenuation,
|
||||
vec2 uv,
|
||||
vec3 aniso_dir,
|
||||
float aniso_ratio
|
||||
) {
|
||||
vec3 half = normalize(view + light);
|
||||
float aniso = max(0, sin(dot(normalize(normal + aniso_dir), half) * PI));
|
||||
float spec = mix(dot(normal, half), aniso, aniso_ratio);
|
||||
float spec_gloss = pow(2.0, 8.0 * (1.0 - specular_strength));
|
||||
float spec_intensity = smoothstep(
|
||||
0.05,
|
||||
0.05 + specular_smoothness,
|
||||
pow(spec, spec_gloss * spec_gloss)
|
||||
);
|
||||
return light_color
|
||||
* specular_color
|
||||
* spec_intensity
|
||||
* is_lit(light, normal, attenuation);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://u6yltf3ostgg
|
||||
@@ -0,0 +1,23 @@
|
||||
#include "base-cel-shader.gdshaderinc"
|
||||
|
||||
group_uniforms Backlight;
|
||||
uniform vec3 backlight : source_color;
|
||||
uniform sampler2D backlight_texture : hint_default_white;
|
||||
group_uniforms;
|
||||
|
||||
vec3 backlight_fragment(vec2 uv) {
|
||||
return backlight * texture(backlight_texture, uv).rgb;
|
||||
}
|
||||
|
||||
vec3 backlight_diffuse(
|
||||
vec3 albedo,
|
||||
vec3 light_color,
|
||||
vec3 light,
|
||||
vec3 normal,
|
||||
float attenuation,
|
||||
vec3 backlight_color
|
||||
) {
|
||||
float value = diffuse_sample(light, normal);
|
||||
return albedo * light_color * attenuation
|
||||
* (value + backlight_color * (1.0 - value));
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://81vh3myp0qw
|
||||
@@ -0,0 +1,65 @@
|
||||
global uniform sampler2D diffuse_curve: repeat_disable;
|
||||
global uniform float specular_smoothness;
|
||||
global uniform float fresnel_smoothness;
|
||||
|
||||
float diffuse_sample(vec3 light, vec3 normal) {
|
||||
return texture(diffuse_curve, vec2(dot(light, normal), 0)
|
||||
).r;
|
||||
}
|
||||
|
||||
float is_lit(vec3 light, vec3 normal, float attenuation) {
|
||||
return attenuation * diffuse_sample(light, normal);
|
||||
}
|
||||
|
||||
vec3 diffuse_light(
|
||||
vec3 albedo,
|
||||
vec3 light_color,
|
||||
vec3 light,
|
||||
vec3 normal,
|
||||
float attenuation
|
||||
) {
|
||||
return albedo * light_color * is_lit(light, normal, attenuation);
|
||||
}
|
||||
|
||||
vec3 specular_light(
|
||||
vec3 light_color,
|
||||
vec3 specular_color,
|
||||
float specular_strength,
|
||||
vec3 normal,
|
||||
vec3 view,
|
||||
vec3 light,
|
||||
float attenuation
|
||||
) {
|
||||
vec3 half = normalize(view + light);
|
||||
float gloss = pow(2.0, 8.0 * (1.0 - specular_strength));
|
||||
float intensity = pow(dot(normal, half), gloss * gloss);
|
||||
return light_color
|
||||
* specular_color
|
||||
* is_lit(light, normal, attenuation)
|
||||
* smoothstep(
|
||||
0.05,
|
||||
0.05 + specular_smoothness,
|
||||
intensity
|
||||
);
|
||||
}
|
||||
|
||||
vec3 fresnel_light(
|
||||
vec3 light_color,
|
||||
vec3 fresnel_color,
|
||||
float fresnel_strength,
|
||||
vec3 normal,
|
||||
vec3 view,
|
||||
vec3 light,
|
||||
float attenuation
|
||||
) {
|
||||
float fresnel_dot = 1.0 - dot(normal, view);
|
||||
float fresnel_threshold = pow((1.0 - fresnel_strength), dot(light, normal));
|
||||
return light_color
|
||||
* fresnel_color
|
||||
* is_lit(light, normal, attenuation)
|
||||
* smoothstep(
|
||||
fresnel_threshold - fresnel_smoothness / 2.0,
|
||||
fresnel_threshold + fresnel_smoothness / 2.0,
|
||||
fresnel_dot
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://dm3y4ql7kxkxa
|
||||
@@ -0,0 +1,9 @@
|
||||
group_uniforms Emission;
|
||||
uniform vec4 emission : source_color = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
uniform float emission_energy = 1.0;
|
||||
uniform sampler2D emission_texture : hint_default_black;
|
||||
group_uniforms;
|
||||
|
||||
vec3 emission_fragment(vec2 uv) {
|
||||
return (emission.rgb + texture(emission_texture, uv).rgb) * emission_energy;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://c1rlmi7m6ie71
|
||||
@@ -0,0 +1,33 @@
|
||||
group_uniforms HeightMap;
|
||||
uniform float height_scale: hint_range(-16.0, 16.0) = 5.0;
|
||||
uniform int min_layers = 8;
|
||||
uniform int max_layers = 32;
|
||||
uniform vec2 height_flip = vec2(1, 1);
|
||||
uniform sampler2D height_map: hint_default_black, filter_linear, repeat_enable;
|
||||
group_uniforms;
|
||||
|
||||
vec2 height_map_fragment(vec2 uv, vec3 vertex, vec3 tangent, vec3 binormal, vec3 normal) {
|
||||
vec2 base_uv = uv;
|
||||
{
|
||||
vec3 view_dir = normalize(normalize(-vertex) * mat3(tangent * height_flip.x, -binormal * height_flip.y, normal));
|
||||
float num_layers = mix(float(max_layers),float(min_layers), abs(dot(vec3(0.0, 0.0, 1.0), view_dir)));
|
||||
float layer_depth = 1.0 / num_layers;
|
||||
vec2 P = view_dir.xy * height_scale * 0.01;
|
||||
vec2 delta = P / num_layers;
|
||||
vec2 ofs = base_uv;
|
||||
float depth = 1.0 - texture(height_map, ofs).r;
|
||||
float current_depth = 0.0;
|
||||
while(current_depth < depth) {
|
||||
ofs -= delta;
|
||||
depth = 1.0 - texture(height_map, ofs).r;
|
||||
current_depth += layer_depth;
|
||||
}
|
||||
vec2 prev_ofs = ofs + delta;
|
||||
float after_depth = depth - current_depth;
|
||||
float before_depth = (1.0 - texture(height_map, prev_ofs).r ) - current_depth + layer_depth;
|
||||
float weight = after_depth / (after_depth - before_depth);
|
||||
ofs = mix(ofs,prev_ofs,weight);
|
||||
base_uv = ofs;
|
||||
return base_uv;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://cxjrc82pbspws
|
||||
@@ -0,0 +1,28 @@
|
||||
group_uniforms NormalMap;
|
||||
uniform float normal_scale : hint_range(-16,16) = 1.0;
|
||||
uniform sampler2D normal_map : hint_normal;
|
||||
group_uniforms;
|
||||
|
||||
struct NormalData {
|
||||
vec3 vector;
|
||||
vec3 map;
|
||||
float depth;
|
||||
};
|
||||
|
||||
NormalData normal_map_fragment(
|
||||
vec2 uv,
|
||||
vec3 normal,
|
||||
vec3 tangent,
|
||||
vec3 binormal,
|
||||
) {
|
||||
vec3 map = texture(normal_map, uv).rgb;
|
||||
vec3 vector = map;
|
||||
vector.xy = vector.xy * 2.0 - 1.0;
|
||||
vector.z = sqrt(max(0.0, 1.0 - dot(vector.xy, vector.xy)));
|
||||
vec3 ref_normal = normalize(mix(
|
||||
normal,
|
||||
tangent * vector.x + binormal * vector.y + normal * vector.z,
|
||||
normal_scale
|
||||
));
|
||||
return NormalData(vector, map, normal_scale);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://ds1ojh3qbgv4s
|
||||
@@ -0,0 +1,16 @@
|
||||
group_uniforms Occlusion;
|
||||
uniform float ao_light_affect: hint_range(0,1) = 0.0;
|
||||
uniform sampler2D ao_map : hint_default_white;
|
||||
group_uniforms;
|
||||
|
||||
struct OcclusionData {
|
||||
float ao;
|
||||
float ao_light_affect;
|
||||
};
|
||||
|
||||
OcclusionData occlusion_fragment(vec2 uv) {
|
||||
return OcclusionData(
|
||||
texture(ao_map, uv).r,
|
||||
ao_light_affect
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://hs5e8wk7dna1
|
||||
@@ -0,0 +1,17 @@
|
||||
group_uniforms Reflections;
|
||||
uniform float metallic : hint_range(0,1) = 0.0;
|
||||
uniform float roughness : hint_range(0,1) = 1.0;
|
||||
uniform sampler2D texture_surface : hint_default_white;
|
||||
group_uniforms;
|
||||
|
||||
struct Surface {
|
||||
float metallic;
|
||||
float roughness;
|
||||
};
|
||||
|
||||
Surface reflections_fragment(vec2 uv) {
|
||||
return Surface(
|
||||
metallic * texture(texture_surface, uv).r,
|
||||
roughness * texture(texture_surface, uv).g
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://dy51hoh6i2uqu
|
||||
@@ -0,0 +1,36 @@
|
||||
group_uniforms Refraction;
|
||||
uniform float refraction : hint_range(-16, 16) = 0.05;
|
||||
uniform float blurriness : hint_range(0.0, 1.0) = 0.0;
|
||||
group_uniforms;
|
||||
|
||||
uniform sampler2D screen_texture :
|
||||
hint_screen_texture,
|
||||
repeat_disable,
|
||||
filter_linear_mipmap;
|
||||
|
||||
uniform sampler2D depth_texture :
|
||||
hint_depth_texture,
|
||||
repeat_disable,
|
||||
filter_linear_mipmap;
|
||||
|
||||
vec3 refraction_fragment(
|
||||
float alpha,
|
||||
vec3 normal,
|
||||
vec2 screen_uv,
|
||||
float depth
|
||||
) {
|
||||
float amount = 1.0 - alpha;
|
||||
vec2 offset = screen_uv - normal.xy * refraction;
|
||||
float image_depth = texture(depth_texture, offset).r;
|
||||
return image_depth < depth
|
||||
? textureLod(
|
||||
screen_texture,
|
||||
screen_uv,
|
||||
blurriness * 8.0
|
||||
).rgb * amount
|
||||
: textureLod(
|
||||
screen_texture,
|
||||
offset,
|
||||
blurriness * 8.0
|
||||
).rgb * amount;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://b0c7qptxov8yo
|
||||
@@ -0,0 +1,8 @@
|
||||
uniform sampler2D screen_texture :
|
||||
hint_screen_texture,
|
||||
repeat_disable,
|
||||
filter_linear_mipmap;
|
||||
|
||||
vec3 transparency_fragment(float alpha, vec2 screen_uv) {
|
||||
return (1.0 - alpha) * texture(screen_texture, screen_uv).rgb;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://b6rxwstxjta3c
|
||||
@@ -0,0 +1,25 @@
|
||||
shader_type spatial;
|
||||
|
||||
render_mode cull_front, unshaded, depth_draw_never;
|
||||
|
||||
global uniform vec4 outline_color;
|
||||
global uniform float outline_width;
|
||||
|
||||
void vertex() {
|
||||
vec4 clip_position =
|
||||
PROJECTION_MATRIX *
|
||||
(MODELVIEW_MATRIX * vec4(VERTEX, 1.0));
|
||||
vec3 clip_normal =
|
||||
mat3(PROJECTION_MATRIX) *
|
||||
(mat3(MODELVIEW_MATRIX) * NORMAL);
|
||||
clip_position.xy +=
|
||||
normalize(clip_normal.xy) /
|
||||
VIEWPORT_SIZE *
|
||||
clip_position.w *
|
||||
outline_width;
|
||||
POSITION = clip_position;
|
||||
}
|
||||
|
||||
void fragment() {
|
||||
ALBEDO = outline_color.rgb;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://bbs8x8ygec4lo
|
||||
@@ -1,109 +0,0 @@
|
||||
shader_type spatial;
|
||||
|
||||
group_uniforms Shader.Albedo;
|
||||
uniform vec4 albedo_color : source_color = vec4(1.0);
|
||||
uniform sampler2D albedo_texture;
|
||||
uniform float albedo_affect : hint_range(0.0, 1.0, 0.05) = 0.0;
|
||||
|
||||
group_uniforms Shader.Light;
|
||||
uniform bool use_stepped = true;
|
||||
uniform float steps = 3.0;
|
||||
uniform float step_smoothness : hint_range(0.0, 1.0, 0.05) = 0.3;
|
||||
uniform vec4 shadow_tint : source_color;
|
||||
uniform float shadow_tint_amount : hint_range(0.0, 1.0, 0.1) = 0.4;
|
||||
|
||||
group_uniforms Shader.Specular;
|
||||
uniform float specular : hint_range(0.0, 1.0, 0.05) = 0.0;
|
||||
|
||||
group_uniforms Shader.Normal;
|
||||
uniform float normal_strength : hint_range(0.0, 1.0, 0.05) = 0.0;
|
||||
uniform sampler2D normal_texture;
|
||||
|
||||
group_uniforms Shader.Rim;
|
||||
uniform bool use_rim = true;
|
||||
uniform vec4 rim_color : source_color = vec4(1.0);
|
||||
uniform float rim_amount = 2.0;
|
||||
uniform float rim_smoothness = 0.2;
|
||||
uniform float rim_mask_shadow : hint_range(0.0, 1.0, 0.05) = 1.0;
|
||||
uniform float rim_blend : hint_range(0.0, 1.0, 0.05) = 1.0;
|
||||
|
||||
group_uniforms Shader.Pattern;
|
||||
uniform bool use_pattern = true;
|
||||
uniform sampler2D pattern_texture;
|
||||
uniform int pattern_uv_mode : hint_enum("UV", "Screen", "Local Screen") = 2;
|
||||
uniform float pattern_tiling = 32.0;
|
||||
uniform float pattern_amount : hint_range(0.0, 1.0, 0.05) = 0.5;
|
||||
uniform float pattern_smoothness : hint_range(0.0, 1.0, 0.05) = 0.5;
|
||||
uniform float pattern_blend : hint_range(0.0, 1.0, 0.05) = 0.2;
|
||||
|
||||
varying vec4 node_position;
|
||||
|
||||
float fresnel(float amount, vec3 normal, vec3 view)
|
||||
{
|
||||
return pow((1.0 - clamp(dot(normalize(normal), normalize(view)), 0.0, 1.0 )), amount);
|
||||
}
|
||||
|
||||
vec2 pattern_uv(vec2 uv, vec2 screen_uv){
|
||||
vec2 p_uv = uv;
|
||||
if(pattern_uv_mode == 1) { p_uv = screen_uv; }
|
||||
if(pattern_uv_mode == 2) { p_uv = (screen_uv * 2.0 - 1.0) * node_position.w - node_position.xy; }
|
||||
return p_uv;
|
||||
}
|
||||
|
||||
float shape_value(float value, vec2 uv, vec2 screen_size){
|
||||
float aspect = screen_size.y / screen_size.x;
|
||||
vec2 pattern_uv = uv * pattern_tiling * vec2(1.0, aspect);
|
||||
float shadow_pattern = texture(pattern_texture, pattern_uv).r;
|
||||
shadow_pattern = clamp(smoothstep(shadow_pattern - pattern_smoothness, shadow_pattern + pattern_smoothness, value + pattern_amount), 0.0, value + pattern_amount);
|
||||
return shadow_pattern;
|
||||
}
|
||||
|
||||
void vertex() {
|
||||
node_position = (PROJECTION_MATRIX * vec4(NODE_POSITION_VIEW, 1.0));
|
||||
}
|
||||
|
||||
void fragment() {
|
||||
vec4 albedo = texture(albedo_texture, UV) * albedo_color;
|
||||
vec4 normal_map = texture(normal_texture, UV);
|
||||
|
||||
ALBEDO = albedo.rgb;
|
||||
|
||||
NORMAL_MAP = mix(vec3(0.5,0.5,1.0), normal_map.rgb, normal_strength);
|
||||
|
||||
SPECULAR = specular;
|
||||
}
|
||||
|
||||
void light () {
|
||||
float ndotl = clamp(dot(NORMAL,LIGHT),0.0,1.0) * ATTENUATION;
|
||||
|
||||
float light = ndotl;
|
||||
|
||||
if(use_stepped){
|
||||
float light_mult = light * steps;
|
||||
float step_base = floor(light_mult);
|
||||
float light_factor = light_mult - step_base;
|
||||
|
||||
light_factor = smoothstep(0.5 - step_smoothness, 0.5 + step_smoothness, light_factor);
|
||||
light = (step_base + light_factor) / steps;
|
||||
}
|
||||
|
||||
if(use_pattern){
|
||||
vec2 p_uv = pattern_uv(UV, SCREEN_UV);
|
||||
|
||||
light = mix(light, shape_value(light, p_uv, VIEWPORT_SIZE), pattern_blend);
|
||||
}
|
||||
|
||||
vec3 diffuse = vec3(pow(light, 1.0)) * (LIGHT_COLOR / PI);
|
||||
diffuse = (shadow_tint.rgb * (1.0 - (light)) * shadow_tint_amount) + diffuse * light;
|
||||
|
||||
if(use_rim){
|
||||
float rim_value = fresnel(rim_amount, NORMAL, VIEW);
|
||||
rim_value = smoothstep(0.5 - (rim_smoothness / 2.0), 0.5 + (rim_smoothness / 2.0), rim_value);
|
||||
rim_value = mix(rim_value, rim_value * light, rim_mask_shadow);
|
||||
|
||||
diffuse += rim_color.rgb * rim_value * rim_blend;
|
||||
}
|
||||
|
||||
DIFFUSE_LIGHT += mix(diffuse, ALBEDO * diffuse, albedo_affect);
|
||||
SPECULAR_LIGHT += vec3(pow(light, 50.0)) * specular;
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
uid://rupeboy0gpf2
|
||||
+3
-3
@@ -70,8 +70,8 @@ shader_parameter/cirrus_absorption = 2.0
|
||||
shader_parameter/cirrus_sky_tint_fade = 0.5
|
||||
shader_parameter/cirrus_size = 1.0
|
||||
shader_parameter/cirrus_uv = Vector2(0.16, 0.11)
|
||||
shader_parameter/cirrus_position1 = Vector2(0.7657499, 0.7657499)
|
||||
shader_parameter/cirrus_position2 = Vector2(0.7657499, 0.7657499)
|
||||
shader_parameter/cirrus_position1 = Vector2(0.63425756, 0.63425756)
|
||||
shader_parameter/cirrus_position2 = Vector2(0.63425756, 0.63425756)
|
||||
shader_parameter/cirrus_texture = ExtResource("6_60vd7")
|
||||
shader_parameter/cumulus_visible = true
|
||||
shader_parameter/cumulus_intensity = 0.6
|
||||
@@ -81,7 +81,7 @@ shader_parameter/cumulus_absorption = 2.0
|
||||
shader_parameter/cumulus_noise_freq = 2.7
|
||||
shader_parameter/cumulus_sky_tint_fade = 0.0
|
||||
shader_parameter/cumulus_size = 0.5
|
||||
shader_parameter/cumulus_position = Vector2(3.8291218, 3.8291218)
|
||||
shader_parameter/cumulus_position = Vector2(3.1713274, 3.1713274)
|
||||
shader_parameter/cumulus_texture = ExtResource("7_e63cu")
|
||||
shader_parameter/cumulus_partial_mie_phase = Vector3(0.957564, 1.042436, 0.412)
|
||||
shader_parameter/cumulus_mie_intensity = 1.0
|
||||
|
||||
Reference in New Issue
Block a user