For resolving normal issues with models, could we pre-bake raycasting from a fixed perspective?

I’m working on a top down game. I have been dealing with a lot of 3D issues related to normals in models and having see-through surfaces which have been hard to deal with. I was wondering how hard it would be to pre-bake some kind of raycast interpretation of the face order from a few perspectives and then simply lookup the order using a shader (or maybe a native extension if it’s possible to delve that deep into the rendering process.) Anyone considered something like this or know how feasible it might be?

I’m not an expert, but I don’t think that’s feasible with Defold. You would need some way to identify each face and look up it’s order in some data structure. As far as I know it’s still not possible to send a ton of arbitrary information to the shader like that, and quite a big nuisance just to identify specific vertices.

I think what you’re saying practically amounts to baking your models out into 2d sprites.

If you’re having issues with normals, you should probably figure out those issues rather than trying to work around the whole render pipeline. Have you tried using Blender instead of Wings? If you’re still trying to use double-sided planes, the easiest solution is to not do that. Or you can turn off backface culling for everything in your render script.

1 Like

Thanks for responding! I’ve tried Blender and Wings 3D but have issues with both, however, I’m new to 3D modeling so it’s difficult to create good models which the engine accepts. I prefer Wings 3D at least for creating the models since it implements a lot of modeling tools more intuitively for me (such as mirroring an object across a face normal.) I tried disabling backface culling in my render script to see if that could be a solution for this but I get a strange result:

With it on, these models appear normal (they don’t have any normals issues / double sided planes.)

After enabling it:

Please upload a sample of one of these meshes in all of its versions that you are using. You may have before but I missed it. It’s possible there is a situation that is happening with the model importer similar to the last time I inspected a model of yours, that not all or not the proper model info is being imported for some reason.

1 Like

Sure, here’s the model for the column. It’s pretty basic:

I know I have too many tris for the side edges, I think it happened when exporting it. Hopefully that shouldn’t cause an issue, but I’ll likely remake that model to use less in the final version.

Immediately on importing it in a blank scene there is a lot of extra data in it which is probably not a good idea to include. You can see this when editing the file with a text editor too. You should try removing all of this and see if it helps at all.

The mesh itself doesn’t have any obvious problems to me. I checked its faces, material, normals.

1 Like

I removed all but the Cube element in Blender and re-exported but the same behavior as shown in the screenshots is taking place.

The screenshots with backface culling disabled you mean? The faces are not double sided that I could see.

For your original issue, is it other models that are having see through faces happening?

1 Like

Yeah the backface culling issue. The models shown in this screenshot have no see-through face issues with it enabled.

Generally you want to enable backface culling unless you are drawing certain render predicates with elements like transparent materials where you might want to draw the entire model.

What does the renderscript related to drawing models look like?

Here’s the code which relates to the model rendering (including the sprite/tile rendering predicates/state changes in between:

render.enable_state(render.STATE_CULL_FACE)
render.disable_state(render.STATE_DEPTH_TEST)
render.disable_state(render.STATE_STENCIL_TEST)
render.draw(self.under_model_pred)

--render.enable_state(render.STATE_DEPTH_TEST)
render.enable_state(render.STATE_BLEND)
render.set_blend_func(render.BLEND_SRC_ALPHA, render.BLEND_ONE_MINUS_DST_ALPHA)
render.disable_state(render.STATE_CULL_FACE)
render.draw(self.tile_pred)
render.draw(self.sprite_pred)

render.enable_state(render.STATE_CULL_FACE)
render.disable_state(render.STATE_BLEND)
render.draw(self.model_pred)
render.draw(self.top_model_pred)

This is all being rendered to an off-screen target for post-fx. Also, there are no under_model_pred instances in the scene shown if that would affect things.

You should re-enable the depth test for drawing models (and for sprites if you’re drawing them in between models). With no backface culling and no depth test, it will draw all front and back faces in a semi-random order. There’s no depth test, so further faces can be drawn in front of closer faces.

3 Likes

Thanks, I tried this now but there’s no difference :frowning: I have the depth mask set to true, and I’m clearing the render.BUFFER_DEPTH_BIT to 1 prior to drawing the buffer.

Hmm…I don’t suppose you can share the project?