# Occlusion geometry questions

**URL:** <https://qa.fmod.com/t/occlusion-geometry-questions/19714>\
**Category:** FMOD Engine\
**Tags:** cpp\
**Created:** [January 8, 2023, 3:51pm UTC](https://qa.fmod.com/t/occlusion-geometry-questions/19714 "2023-01-08T15:51:33Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![juhrell](https://avatars.discourse-cdn.com/v4/letter/j/c6cbf5/32.png) [@juhrell](https://qa.fmod.com/u/juhrell)\
**Post date:** [January 8, 2023, 3:51pm UTC](https://qa.fmod.com/t/occlusion-geometry-questions/19714/1 "2023-01-08T15:51:33Z")

</div>

Hi there, I’m having trouble adding occlusion into my game engine and was wondering what’s the issue.

```auto
void InitOcclusion(vector3 vertices[8])
{
	FMOD_VECTOR m_Vertices[8];
	for (int i = 0; i < 8; i++)
		{
			m_Vertices[i].x = vertices[i].x;
			m_Vertices[i].y = vertices[i].y;
			m_Vertices[i].z = vertices[i].z;
		}	
	/* FMOD_VECTOR rectangle[8] = {
		{ 0.5, 10, 5}, { 0.5, 10, -5}, { 0.5, 0, 5}, { 0.5, 0, -5},
		{-0.5, 10, 5}, {-0.5, 10, -5}, {-0.5, 0, 5}, {-0.5, 0, -5}
		}; */ //Hardcoding the vertices doesn't work either

	FMOD::Geometry* geometry;
	m_CoreSystem->createGeometry(1, 8, &geometry);

	int index = 0;
	geometry->addPolygon(1, 1, true, 8, m_Vertices, &index);
}

```

Instead of hardcoding the vertices that needs to be occluded, I am passing the values in from another function that I’ve set up. Currently, there’s only 1 wall inside my testing case and my sounds are all in 3D.

I can’t seem to get the occlusion to work, or rather can’t tell if it’s working based of hearing the audio. Any suggestions to improve on the code? Thank you 🙂

edit: my listener position is {-2.5, 5, 0} while audio source is {2.5, 5, 0}

---

<div class="post-metadata">

**Author:** ![Leah\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/leah_fmod/32/3685_2.png) [@Leah\_FMOD](https://qa.fmod.com/u/Leah_FMOD)\
**Post date:** [January 9, 2023, 5:10am UTC](https://qa.fmod.com/t/occlusion-geometry-questions/19714/2 "2023-01-09T05:10:52Z")

</div>

Hi,

The issues stems from how exactly you’re providing your vertices to FMOD in order to construct polygons. FMOD’s geometry system is a little fragile - while technically it will support polygons comprised of an arbitrarily large amount of vertices (up to a point), the order you provide the verts will determine exactly how the polygon is constructed. Additionally, concave polygons or verts not lying on the same plane will cause unpredictable behvaiour - see the documentation on [`Geometry::addPolygon`](https://www.fmod.com/docs/2.02/api/core-api-geometry.html#geometry_addpolygon).

In your case, `geometry->addPolygon(1, 1, true, 8, m_Vertices, &index)` isn’t creating a rectangular prism, but instead a polygon with eight verts based the order they’re laid out in `m_Vertices`. Since they’re the verts of a prism, providing all verts will result in half of them not sharing the same plane, thus causing your issue.

I would highly recommend splitting your geometry into more manageable polygons with less verts, like quads or tris, and using those to make up your prism i.e. one quad/two tris for each “face” of the prism. Winding order shouldn’t be a problem since you can just set your polygons to be double-sided. Hardcoding your verts will work fine as well, just be aware that you’re trying to provide the “outside” of the polygon with your vertices - making a quad with the first four verts in `rectangle` will result in an “hourglass” instead of a rectangle, as going from `rectangle[1]` to `rectangle[2]` will cut across the middle of the quad.

Hope that helps.

---

<div class="post-metadata">

**Author:** ![juhrell](https://avatars.discourse-cdn.com/v4/letter/j/c6cbf5/32.png) [@juhrell](https://qa.fmod.com/u/juhrell)\
**Post date:** [January 9, 2023, 9:06am UTC](https://qa.fmod.com/t/occlusion-geometry-questions/19714/3 "2023-01-09T09:06:02Z")

</div>

hello, thanks for the detailed reply! I have some questions regarding this though, I am currently making a 3D game and say i change my vertices to quads, eg i pass in 4 vertices at a time. How do I determine the “thickness” of the wall? I’d assume the thicker the wall, the lesser the sound will be heard from the listener. Do i have to then split into 2 quads, passing both front and face of the wall?

I also just realised the way im passing in the vertices are not done properly, causing a hourglass shape so i’ll go and tweak that.

Once again, thank you for your help!

---

<div class="post-metadata">

**Author:** ![Leah\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/leah_fmod/32/3685_2.png) [@Leah\_FMOD](https://qa.fmod.com/u/Leah_FMOD)\
**Post date:** [January 9, 2023, 10:43pm UTC](https://qa.fmod.com/t/occlusion-geometry-questions/19714/4 "2023-01-09T22:43:49Z")

</div>

The geometry occlusion system doesn’t calculate how thick a wall is based on the distance between a front and back face, so you don’t need to provide both both the front and back faces of a wall if you don’t want to. If you do want to create just the front and back face of the prism, with none of the polygons on the side connecting the two, then two quads will be fine. If you want to create a fully enclosed rectangular prism with no “holes”, you’ll need to provide six quads, one for each face of the prism.

To determine the “thickness” of a polygon, you can use `Geometry::addPolygon` or [`Geometry::setPolygonAttributes`](https://www.fmod.com/docs/2.02/api/core-api-geometry.html#geometry_setpolygonattributes) to set occlusion factors for each polygon, which will determine how much an audio source is occluded when that polygon comes between the listener and the audio source.

---

<div class="post-metadata">

**Author:** ![juhrell](https://avatars.discourse-cdn.com/v4/letter/j/c6cbf5/32.png) [@juhrell](https://qa.fmod.com/u/juhrell)\
**Post date:** [January 10, 2023, 8:39am UTC](https://qa.fmod.com/t/occlusion-geometry-questions/19714/5 "2023-01-10T08:39:21Z")

</div>

Yep, I got it to finally work, however the issue now is that during runtime, the audio behind the wall will play for ~0.1sec before realizing that the wall is in the way before fading out to 0 as I set 1 for direct and reverb occlusion. However coding wise, I checked for all occluded walls with my player before I play the necessary audio. May I know what’s the issue?

---

<div class="post-metadata">

**Author:** ![juhrell](https://avatars.discourse-cdn.com/v4/letter/j/c6cbf5/32.png) [@juhrell](https://qa.fmod.com/u/juhrell)\
**Post date:** [January 10, 2023, 9:20am UTC](https://qa.fmod.com/t/occlusion-geometry-questions/19714/6 "2023-01-10T09:20:18Z")

</div>

Sorry another question, I saw in the other FMOD forum post that the distance of the wall to the player should be calculated every frame?

---

<div class="post-metadata">

**Author:** ![Leah\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/leah_fmod/32/3685_2.png) [@Leah\_FMOD](https://qa.fmod.com/u/Leah_FMOD)\
**Post date:** [January 11, 2023, 4:23am UTC](https://qa.fmod.com/t/occlusion-geometry-questions/19714/7 "2023-01-11T04:23:16Z")

</div>

> [@juhrell](#):
>
> Yep, I got it to finally work, however the issue now is that during runtime, the audio behind the wall will play for ~0.1sec before realizing that the wall is in the way before fading out to 0 as I set 1 for direct and reverb occlusion. However coding wise, I checked for all occluded walls with my player before I play the necessary audio. May I know what’s the issue?

Since you’ve said that you’ve “checked for all occluded walls with my player before I play the necessary audio”, I assume you’re not initializing your audio source before initializing the occluding geometry. Is there anything else you’re doing that may be delaying the occlusion kicking in, such as a delay in setting your listener position?

> [@juhrell](#):
>
> Sorry another question, I saw in the other FMOD forum post that the distance of the wall to the player should be calculated every frame?

The Core API geometry occlusion system will handle the distance calculation itself based on the listener and audio source positions every time [System::update](https://www.fmod.com/docs/2.02/api/core-api-system.html#system_update) is called from your tick function, but in FMOD Studio there’s also an occlusion setting in the Resonance Audio Source plugin that does need to be manually calculated and updated by you every tick. To be sure what we’re talking about, could you link the thread in question?
