Normals in Godot?

Discuss issues pertaining to the various game/web runtimes of Creature here.
Post Reply
cm343
Posts: 9
Joined: Fri Dec 15, 2017 1:45 pm

Normals in Godot?

Post by cm343 » Sat Jul 28, 2018 12:00 pm

Is it possible to use normals from Sprite Bump in Godot? I know there is a way to define a normal map for a 'sprite' node in Godot, but I can't see anywhere to define a normal map in a CreatureGodot node.

Thanks in advance!

chong
Posts: 1178
Joined: Thu Feb 19, 2015 2:21 am

Re: Normals in Godot?

Post by chong » Sat Jul 28, 2018 4:57 pm

Hello,

I am not sure how Godot's shader or nomals system works, I know there definitely is one. This might be more of a general Godot-related question than anything else.

Essentially the creature character when rendered in Godot already contains UVs per vertex, you wil need to figure out in Godot how to use those UVs to sample the normal map you want and then modify the normal. Since the characters are essentially a flat plane ( 2D to 3D ), you will just be modifying some unit vector (0, 0, 1) for example that gets changed via the normal map. That is the simplest example I can think of. However you should take a look at the Godot shader docs to see how it can be done.

Thanks

cm343
Posts: 9
Joined: Fri Dec 15, 2017 1:45 pm

Re: Normals in Godot?

Post by cm343 » Sat Jul 28, 2018 6:41 pm

Thanks for that - haven't looked much at shaders at all.

It's really straightforward for a simple 2D sprite in Godot - just add the sprite texture, the normal map and a Light 2D and it's job done. I was hoping there might be a simple, magical way to do it with the Creature runtime :)

Image

HeroicNate
Posts: 9
Joined: Wed Apr 14, 2021 3:51 am

Re: Normals in Godot?

Post by HeroicNate » Wed Apr 14, 2021 3:55 am

Is it still the case that the only way to get normals on animation is to write our own shader for it?

chong
Posts: 1178
Joined: Thu Feb 19, 2015 2:21 am

Re: Normals in Godot?

Post by chong » Wed Apr 14, 2021 7:58 am

Hello,
yes because Creature exposes it as a regular Godot Mesh. So you should be using Godot's own material system to achieve that.
You can also export as GLTF to take advantage of their 3D renderer for that.

Thanks

HeroicNate
Posts: 9
Joined: Wed Apr 14, 2021 3:51 am

Re: Normals in Godot?

Post by HeroicNate » Wed Apr 14, 2021 6:01 pm

GLTF is super cool, but my game is 2d. I did find a shader tutorial that got the lights working, so yay! I'll put it here for reference in case anyone else wants/needs to know how to do it.

Modified from https://www.gdquest.com/tutorial/godot/ ... rmal-maps/:

1) Expand the Creature node’s Material in the Inspector and create a new Shader Material
Image

2) Add a new Shader in the corresponding property.
Image

3) Click the Shader to open the shader editor and paste this code into it:
Image

Code: Select all

// Mandatory line to define 2D shaders
shader_type canvas_item;

// Allows us to assign a normal map to the shader in the Inspector
uniform sampler2D normal_map;

void fragment(){
	// Converts the texture data into a unit vector, with each channel in the [-1, 1] range

NORMAL = 2.0 * texture(normal_map, UV).rgb - 1.0;
}
4) Drag your normal map texture into the new normal shader param that was created.
Image

Bam, your creature animation should be lit now.
Image
Please ignore this horrible animation that was quickly done for testing.
Image

Post Reply