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

**URL:** <https://forum.defold.com/t/for-resolving-normal-issues-with-models-could-we-pre-bake-raycasting-from-a-fixed-perspective/66446>\
**Category:** Questions\
**Created:** [September 26, 2020, 3:46pm UTC](https://forum.defold.com/t/for-resolving-normal-issues-with-models-could-we-pre-bake-raycasting-from-a-fixed-perspective/66446 "2020-09-26T15:46:46Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Epitaph64](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/epitaph64/32/39288_2.png) [@Epitaph64](https://forum.defold.com/u/Epitaph64)\
**Post date:** [September 26, 2020, 3:46pm UTC](https://forum.defold.com/t/for-resolving-normal-issues-with-models-could-we-pre-bake-raycasting-from-a-fixed-perspective/66446/1 "2020-09-26T15:46:46Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ross.grams](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/r/cab0a1/32.png) [@ross.grams](https://forum.defold.com/u/ross.grams)\
**Post date:** [September 26, 2020, 6:02pm UTC](https://forum.defold.com/t/for-resolving-normal-issues-with-models-could-we-pre-bake-raycasting-from-a-fixed-perspective/66446/2 "2020-09-26T18:02:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Epitaph64](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/epitaph64/32/39288_2.png) [@Epitaph64](https://forum.defold.com/u/Epitaph64)\
**Post date:** [September 27, 2020, 12:48am UTC](https://forum.defold.com/t/for-resolving-normal-issues-with-models-could-we-pre-bake-raycasting-from-a-fixed-perspective/66446/3 "2020-09-27T00:48:20Z")

</div>

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:

 ![image](https://forum-defold-uploads.b-cdn.net/original/3X/2/d/2d4db782164a0da713876dea348e1d05b8bd6b41.jpeg)

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

After enabling it:

 ![image](https://forum-defold-uploads.b-cdn.net/original/3X/1/e/1e79988bbba6a856c67b2bd42c4bc57237ab2971.jpeg)

---

<div class="post-metadata">

**Author:** ![Pkeod](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pkeod/32/606_2.png) [@Pkeod](https://forum.defold.com/u/Pkeod)\
**Post date:** [September 27, 2020, 2:40am UTC](https://forum.defold.com/t/for-resolving-normal-issues-with-models-could-we-pre-bake-raycasting-from-a-fixed-perspective/66446/4 "2020-09-27T02:40:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Epitaph64](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/epitaph64/32/39288_2.png) [@Epitaph64](https://forum.defold.com/u/Epitaph64)\
**Post date:** [September 27, 2020, 2:44am UTC](https://forum.defold.com/t/for-resolving-normal-issues-with-models-could-we-pre-bake-raycasting-from-a-fixed-perspective/66446/5 "2020-09-27T02:44:37Z")

</div>

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

> **[Dropbox](https://www.dropbox.com/s/vcahanp6uidb753/column3.dae?dl=0)**

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.

---

<div class="post-metadata">

**Author:** ![Pkeod](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pkeod/32/606_2.png) [@Pkeod](https://forum.defold.com/u/Pkeod)\
**Post date:** [September 27, 2020, 5:58am UTC](https://forum.defold.com/t/for-resolving-normal-issues-with-models-could-we-pre-bake-raycasting-from-a-fixed-perspective/66446/6 "2020-09-27T05:58:46Z")

</div>

![2020-09-26%2022_51_43-Blender](https://forum-defold-uploads.b-cdn.net/original/3X/7/6/7652d5cd0e6853c3ca2cc54dbfc0884eaea3a8fa.png)

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.

---

<div class="post-metadata">

**Author:** ![Epitaph64](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/epitaph64/32/39288_2.png) [@Epitaph64](https://forum.defold.com/u/Epitaph64)\
**Post date:** [September 27, 2020, 6:03am UTC](https://forum.defold.com/t/for-resolving-normal-issues-with-models-could-we-pre-bake-raycasting-from-a-fixed-perspective/66446/7 "2020-09-27T06:03:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Pkeod](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pkeod/32/606_2.png) [@Pkeod](https://forum.defold.com/u/Pkeod)\
**Post date:** [September 27, 2020, 6:09am UTC](https://forum.defold.com/t/for-resolving-normal-issues-with-models-could-we-pre-bake-raycasting-from-a-fixed-perspective/66446/8 "2020-09-27T06:09:48Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Epitaph64](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/epitaph64/32/39288_2.png) [@Epitaph64](https://forum.defold.com/u/Epitaph64)\
**Post date:** [September 27, 2020, 6:37am UTC](https://forum.defold.com/t/for-resolving-normal-issues-with-models-could-we-pre-bake-raycasting-from-a-fixed-perspective/66446/9 "2020-09-27T06:37:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Pkeod](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pkeod/32/606_2.png) [@Pkeod](https://forum.defold.com/u/Pkeod)\
**Post date:** [September 27, 2020, 11:10am UTC](https://forum.defold.com/t/for-resolving-normal-issues-with-models-could-we-pre-bake-raycasting-from-a-fixed-perspective/66446/10 "2020-09-27T11:10:30Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Epitaph64](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/epitaph64/32/39288_2.png) [@Epitaph64](https://forum.defold.com/u/Epitaph64)\
**Post date:** [September 27, 2020, 11:15am UTC](https://forum.defold.com/t/for-resolving-normal-issues-with-models-could-we-pre-bake-raycasting-from-a-fixed-perspective/66446/11 "2020-09-27T11:15:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ross.grams](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/r/cab0a1/32.png) [@ross.grams](https://forum.defold.com/u/ross.grams)\
**Post date:** [September 27, 2020, 11:18am UTC](https://forum.defold.com/t/for-resolving-normal-issues-with-models-could-we-pre-bake-raycasting-from-a-fixed-perspective/66446/12 "2020-09-27T11:18:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Epitaph64](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/epitaph64/32/39288_2.png) [@Epitaph64](https://forum.defold.com/u/Epitaph64)\
**Post date:** [September 27, 2020, 11:29am UTC](https://forum.defold.com/t/for-resolving-normal-issues-with-models-could-we-pre-bake-raycasting-from-a-fixed-perspective/66446/13 "2020-09-27T11:29:16Z")

</div>

Thanks, I tried this now but there’s no difference ☹ I have the depth mask set to true, and I’m clearing the render.BUFFER\_DEPTH\_BIT to 1 prior to drawing the buffer.

---

<div class="post-metadata">

**Author:** ![ross.grams](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/r/cab0a1/32.png) [@ross.grams](https://forum.defold.com/u/ross.grams)\
**Post date:** [September 27, 2020, 11:54am UTC](https://forum.defold.com/t/for-resolving-normal-issues-with-models-could-we-pre-bake-raycasting-from-a-fixed-perspective/66446/14 "2020-09-27T11:54:59Z")

</div>

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