+1 vote

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.

in Engine by (244 points)
edited by

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

2 Answers

+4 votes
Best answer

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));
by (1,556 points)
selected by

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

–5 votes

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.

by (452 points)
edited by

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!

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.


Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.