distort screen uvs based on normal map?
Asked Answered
L

2

0

im trying to make blood screen have a distort effect based on a normal map.
it works but as u can see in the code
the uvs are only shifted to the left.
how to distort based on the normal map?


uniform sampler2D basecolor : hint_default_black;
uniform vec4 coloroverlay : source_color;
uniform sampler2D normalmap : hint_normal;
uniform float alphablend : hint_range(0.0, 1.0, 0.01) = 1.0;
uniform float strenght : hint_range(0.0, 1, 0.01) = 0.05;


void fragment() {

	vec2 distortUV = (texture(normalmap, SCREEN_UV).xy * strenght) * strenght * 0.5;
	
	vec2 uv = FRAGCOORD.xy / (1.0 / SCREEN_PIXEL_SIZE).xy + distortUV;// + shifts to the left?
	
    vec3 col = texture(SCREEN_TEXTURE,uv).xyz * coloroverlay.xyz ;
	vec4 albedo_tex = texture(basecolor,uv);
	
	COLOR = vec4(col,alphablend * albedo_tex.a);
	
}
Layne answered 3/12, 2022 at 19:46 Comment(0)
U
0

Try ((texture(normalmap, SCREEN_UV).xy - 0.5) * strenght) * strenght * 2.0 - 1.0; and if that's too weak then remove the last subtraction of 1. Sometimes you need that extra subtraction for normalization other times not, I'm not sure if it's necessary in this case since this is quickly off the cuff.

Also I'm a bit bothered by that strength getting multiplied twice the way it is. If you need it to be squared that's fine I guess but I still feel like it could have been squared before it's use in that line...

Ustulation answered 3/12, 2022 at 21:48 Comment(0)
L
0

tnx for your answer
this seems to work best >

vec2 distortUV = ((texture(normalmap, SCREEN_UV).xy - 0.5) * strenght) * 2.0;
Layne answered 4/12, 2022 at 3:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.