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;
}