Hi,
I want to add (optical) glasses to my character in my game, and have the effect of the 3d space behind the glasses being magnified bigger, with some specular effects. Optionally, I would also like a “fish eye” effect, with the centre of the lens distorted to be larger.
shader_type spatial;
render_mode blend_mix,depth_draw_opaque,cull_disabled,diffuse_burley,specular_schlick_ggx,unshaded;
uniform vec4 albedo : source_color = vec4(1.0, 1.0, 1.0, 0.0);
uniform float specular;
varying flat vec3 norm;
varying flat float norm_val;
uniform sampler2D SCREEN_TEXTURE: hint_screen_texture,filter_linear_mipmap;
void vertex() {
norm = NORMAL;
}
vec2 scale(vec2 uv, float x, float y)
{
mat2 scale = mat2(vec2(x, 0.0), vec2(0.0, y));
uv -= 0.5;
uv = uv * scale;
uv += 0.5;
return uv;
}
vec2 shift(vec2 uv){
return uv;
}
void fragment() {
vec3 normx = NORMAL;
NORMAL = norm;
vec4 alpha = vec4(1.0);
alpha = texture(SCREEN_TEXTURE, scale(SCREEN_UV, 0.7,0.7));
ALBEDO = mix(alpha.rgb, albedo.rgb, albedo.a);
SPECULAR = specular;
}
This is what I’ve got so far. The problem in the picture is obvious, I shouldn’t be able to see the glasses themselves magnified in the lens. And I know that this is because the UV increases from it’s centre, not the shader’s local centre.
In my head I know what I need to do. I think I just need to shift the uv slightly to follow the meshs position relative to the camera. But for the life of me I can’t figure it out, none-of-the-less apply a fishbowl effect over it.
Many thanks for your time. - Godot shader noob.