Godot Version
v4.3.dev5.official [89f70e98d]
Question
I want to convert this old godot 3.x shader to Godot 4.3 dev shader .
I tried some new changes like MODEL_MATRIX , but the result is not the same:
This is the source code:
shader_type spatial;
//WORLD_MATRIX rename to MODEL_MATRIX
//WORLD_NORMAL_MATRIX rename to MODEL_NORMAL_MATRIX
//
//CAMERA_MATRIX rename to INV_VIEW_MATRIX
//INV_CAMERA_MATRIX rename to VIEW_MATRIX
uniform sampler2D over_texture : hint_depth_texture;
uniform sampler2D under_texture : hint_depth_texture;
uniform sampler2D surface_normalmap : hint_normal;
uniform vec4 top_color : source_color = vec4(0.6764, 0.980092, 1.0, 1.0);
uniform float depth = 0.1;
uniform float normal_depth = 1.0;
uniform float roughness : hint_range(0.0, 1.0) = 0.0;
uniform float metallic : hint_range(0.0, 1.0) = 0.7;
uniform float refractive_index = 0.1;
float blend_over(float base, float blend) {
float branchless = step (base,0.5);
return (2.0*base*blend)*branchless + (1.0-2.0*(1.0-base)*(1.0-blend))*(1.0-branchless); //This is branchless version
}
vec3 blendOverlay(vec3 base, vec3 blend) {
return vec3(blend_over(base.r,blend.r),blend_over(base.g,blend.g),blend_over(base.b,blend.b));
}
varying vec3 ro;
varying vec3 p;
varying vec3 vertex_normal_ws;
void vertex()
{
ro = (CAMERA_POSITION_WORLD * vec3(0.0, 0.0, 1.0));// Get camera position in World space coordinates
p = ((WORLD_MATRIX)*vec4(VERTEX,1.0)).xyz;// Get fragment position in world space coordinates
vertex_normal_ws = ((WORLD_MATRIX)*vec4(NORMAL,1.0)).xyz;
}
void fragment(){
vec3 normal = texture(surface_normalmap, UV).xyz * 2.0 - 1.0;
NORMALMAP = texture(surface_normalmap, UV).xyz;
NORMALMAP_DEPTH = normal_depth;
vec3 refraction;
vec3 rd = normalize(p - ro - normal * refractive_index) * depth;
vec3 over_color = texture(over_texture, UV).rgb;
vec3 color = blendOverlay(over_color, top_color.rgb);
vec2 offset = rd.xz;
vec3 under_color = texture(under_texture, UV + offset + (normal.xy)).rgb;
ALBEDO = blendOverlay(color, under_color);
ROUGHNESS = roughness;
METALLIC = metallic;
}
Just saw this looking for something else, and I did this myself last year. This is converted from 3.x to 4.x. Here’s the original link to the Parallax Ice Shader.
shader_type spatial;
uniform sampler2D over_texture : source_color;
uniform sampler2D under_texture : source_color;
uniform sampler2D surface_normalmap : hint_normal;
// Here's a free CC0 ice texture -> https://ambientcg.com/view?id=Ice003
// You can use that for the over_texture and surface_normalmap
// Here's another CC0 ice texture -> https://ambientcg.com/view?id=Ice002
// You can use the displacement map of this texture as the under_texture
uniform vec4 top_color : source_color = vec4(0.6764, 0.980092, 1.0, 1.0);
uniform float depth = 0.1;
uniform float normal_depth = 1.0;
uniform float roughness : hint_range(0.0, 1.0) = 0.0;
uniform float metallic : hint_range(0.0, 1.0) = 0.7;
uniform float refractive_index = 0.1;
// ========= ↓↓↓ From u/lexpartizan the GOAT ↓↓↓ ==============
float blendOverlay_f(float base, float blend) {
float branchless = step (base,0.5);
return (2.0*base*blend)*branchless + (1.0-2.0*(1.0-base)*(1.0-blend))*(1.0-branchless); //This is branchless version
}
// ======== ↑↑↑ From u/lexpartizan the GOAT ↑↑↑ ==============
vec3 blendOverlay(vec3 base, vec3 blend) {
return vec3(blendOverlay_f(base.r,blend.r),blendOverlay_f(base.g,blend.g),blendOverlay_f(base.b,blend.b));
}
// ============= ↓↓↓ More from u/lexpartizan the GOAT ========================
varying vec3 ro;
varying vec3 p;
varying vec3 vertex_normal_ws;
void vertex()
{
ro = (INV_VIEW_MATRIX * vec4(0.0, 0.0, 0.0, 1.0)).xyz;// Get camera position in World space coordinates
p = ((MODEL_MATRIX)*vec4(VERTEX,1.0)).xyz;// Get fragment position in world space coordinates
vertex_normal_ws = ((MODEL_MATRIX)*vec4(NORMAL,1.0)).xyz;
}
// ============= ↑↑↑ More from u/lexpartizan the GOAT ↑↑↑ ====================
void fragment(){
vec3 normal = texture(surface_normalmap, UV).xyz * 2.0 - 1.0;
NORMAL_MAP = texture(surface_normalmap, UV).xyz;
NORMAL_MAP_DEPTH = normal_depth;
vec3 rd = normalize(p - ro - normal * refractive_index) * depth;
vec3 over_color = texture(over_texture, UV).rgb;
vec3 color = blendOverlay(over_color, top_color.rgb);
vec2 offset = rd.xz;
vec3 under_color = texture(under_texture, UV + offset + (normal.xy)).rgb;
ALBEDO = blendOverlay(color, under_color);
ROUGHNESS = roughness;
METALLIC = metallic;
}
I included it in a package of ice shaders I did for Godot: Godot 3D Ice Material Shaders and VFX by Dragonforge Development