Hello. I am having problems with outline on mesh with sharp edges. I need both, Sharp edges on surface, and continuous outline. Is it possible at all? I made a second pass material, set front cooling, added "grow" to it, and outline get cracked. I converted material to shader, but don't know what to do with it :) If I understand right, smooth surface contains one normal for each vertex, and sharp surface contains a normal for each face, right? How do I normalize vertex normals in outline shader? (only in outline shader)

Here's how this shader looks now. I edited it to have a constant size outline (well, almost constant:) ):

shader_type spatial;
render_mode blend_mix,cull_front,unshaded;
uniform vec4 albedo : hint_color;
uniform float grow;


void vertex() {
	mat4 campos = INV_CAMERA_MATRIX;
	float offset = abs((campos * WORLD_MATRIX[3]).z)*grow;
	VERTEX+=vec3(NORMAL.x*offset,NORMAL.y*offset,NORMAL.z);
}




void fragment() {
	vec2 base_uv = UV;
	ALBEDO = albedo.rgb;
	ALPHA = albedo.a;
}

Thank you for your attention.

Right, so I approved this post earlier but forgot to add that you should check your mail for a confirmation email if you want to be able to post here in the forums without every message getting captured by the moderation queue.

@Megalomaniak said: Right, so I approved this post earlier but forgot to add that you should check your mail for a confirmation email if you want to be able to post here in the forums without every message getting captured by the moderation queue.

Sorry. I entered wrong mail name. There is no link to deal with administration, so I had to create another user. My fault. Sorry.

@KokusPokus said:

@Megalomaniak said: Right, so I approved this post earlier but forgot to add that you should check your mail for a confirmation email if you want to be able to post here in the forums without every message getting captured by the moderation queue.

Sorry. I entered wrong mail name. There is no link to deal with administration, so I had to create another user. My fault. Sorry.

No problem. :smile:

Do you want us to delete the KokPok account? I'm not totally sure will happen to this thread if the user is deleted but I'm sure we can figure it out. We can also change your account name to KokPok after deleting the other account if you want.

Also, if at any point you need assistance with forum related issues, please let us know! You can private message any of us through the forums by going to our profile and pressing the "Message" button. The list of forum staff discussion has links to the profiles of all current forum staff. You can also contact forum staff via the email on the profile pages of staff members, and/or you can contact me at TwistedTwigleg@RandomMomentania.com with any issues you might have.

@TwistedTwigleg said: Do you want us to delete the KokPok account? I'm not totally sure will happen to this thread if the user is deleted but I'm sure we can figure it out. Yes, you can delete it. And if this thread will disappear, no matter, still no one answered, maybe my question was to silly, or badly explained. :)

@KokusPokus said:

@TwistedTwigleg said: Do you want us to delete the KokPok account? I'm not totally sure will happen to this thread if the user is deleted but I'm sure we can figure it out. Yes, you can delete it. ...

There we go! I left the thread but deleted the user.

... And if this thread will disappear, no matter, still no one answered, maybe my question was to silly, or badly explained. :)

I can assure you that it is not a silly question! I've struggled with this issue in the past for game characters.

The issue is that the faces of a mesh get pulled apart as the mesh expands based in the direction of the normal of the faces, or at least that is the issue I've had. For the project I was working on I got around the issue with by having a smaller grow size and more vertices in the character.

Traditionally outlines are done using a frame buffer, but in Godot 3.1+ there isn't a way to create a user defined frame buffer and/or bit mask (Unity tutorial) and/or stencil (LearnOpenGL). You can kinda get something similar with Color masking and a separate Viewport, though when I tried I couldn't find a way to get decent looking results. In Godot 4.0 I remember reading there is plans to allow for user defined frame buffers, which should make outlines much easier in Godot.

This Unity tutorial shows how to generate an Outline using the depth buffer, which is available in Godot. The tutorial goes on to show how to use view-space-normals, which gives slightly better results (in my opinion), but in Godot there is no good way to get all of the normals within a scene. That said, the effect shown in the tutorial might work since in Godot you can access the depth buffer.

This other Unity tutorial mentions the sharp edge issue, so it might be helpful as well. Here is an Unreal Engine tutorial/article for outlines that looks like it could be interesting, but I'm not sure how applicable it will be to the outline issue. I wasn't able to find any Godot specific solutions, but I'll keep an eye out.

Unfortunately, I don't have a solution to the issue though. I would suggest asking on other Godot communities, like Reddit/Facebook/Discord/etc and see if anyone there knows. You might also want to look into how other game engines solve the outline issue, as I have found that many Godot issues can be solved with solutions for other games engines, generally with a little tweaking.

It's very bad, that Godot community is so fragmented. Facebook's topics are sliding to the /dev/null. Worst place to ask, only onetime questions. Reddit is another strange place to me and this forum and Godot QnA... Man... And they all are separate...

Ok, In Godot I can't use buffers, very sad, but we have what we have. If only Godot would be something like Blender Game Engine, but on sterroids... :) I don't want to switch to another engine, because for my hobbyist digging it is very comfortable. As soon Blender ripped their engine. And still there is a chance that my project will be ready someday and released on as many platforms as possible. Just because. I tried Urho3d - it's an adventure even to create a project. Signals of signals, where it starts and where it ends - no one knows. Buggy editor... To complicated to me. And I don't know another good opensource engine that works in Linux. I stay with Godot. It is a noob friendly.

So. My further investigations leaded me to this wonderful page. I can create smooth terrain, make smooth outline and make faces flat in base material with this simple trick. I don't understand, why and how is it working, why faces becomes flat? If someone will explain it to me at the noob level, it would be wonderful.

3 years later