Normal map vs Rotating Camera in 2D

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By pospathos
:warning: Old Version Published before Godot 3 was released.

Does any one know why normal map on sprite in 2d won’t update position when Camera angle is not zero. It seems that normal map is calculated in apsolute (editor?) coordinates competely ignoring position of light when Camera angle is changed.
Example:
https://drive.google.com/file/d/0B98I-429KNtNZUtmRm5KMGtzeTQ/view?usp=sharing

Do I need to include Camera angle in normal map shader? And if so, does anyone have an example?

pospathos | 2017-05-18 11:30

Might be related to this.

vtepe | 2017-05-19 11:39

:bust_in_silhouette: Reply From: Bishop

Why are you using a normal map in 2d ?..that’s bullshit for me, it won’t work…if you need to create bump-like surface use Gimp…or Krita and create bumpiness there(shades of gray displace map…normal map is a 3d stuff- RGB colors = xyz = 3d
to be clear…for the correct normal maps on surface you need vertices and faces.

I’m not huge fan of combining pixel/2d art with shaders, but I just want to experiment to see what I can get from it. I use normal maps becose there are in examples project and I’m not good with writing shaders. After all many games wiht pixel art use normal maps and it is working ok for the most part (aesthetically speaking) if you are not overusing it.

Can you tell me how to write a bumpmap shader or give some directions. If I use bumpmaps instead of normalmaps do I get corect shading even if Camera2D is rotaded, does that solve my problem at all. Thanks!

pospathos | 2017-05-19 07:08

I’m sorry…I have no experience with normal maps in 2d…only in 3d I often use normal maps and I do’nt knowledge for writing shaders, maybe by that look angle I answer for first…and when normal maps are used in 2D games that will have some sense.
…but in Gimp or Krita you can do amazing textures that look like using normal map, I think it all you need just for 2d…and when you add some post-processing filter etc. chromatic aberration for example no need normal map.



Bishop | 2017-05-19 11:04

:bust_in_silhouette: Reply From: mollusca

This lighting shader should look very close or identical to the default normal map shader but with camera angle included in the calculation. The fragment shader is identical to the one in the demo. You’ll need to pass the camera angle to the shader with set_shader_param().

uniform float cam_rot = 0.0;
mat2 rot_mat = mat2(vec2(cos(cam_rot), sin(cam_rot)), vec2(-sin(cam_rot), cos(cam_rot)));
vec3 light_dir = normalize(vec3(rot_mat * -LIGHT_VEC, LIGHT_HEIGHT));
float NdotL = max(0.0, dot(NORMAL, light_dir));
LIGHT = mix(COLOR * LIGHT_COLOR, COLOR * NdotL * LIGHT_COLOR, 1.0);

Mollusca, thank you a alot !! It works perfectly. You saved my day! :slight_smile:

pospathos | 2017-05-19 10:28