Occlusion geometry questions

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

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 :slight_smile:

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

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.

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.

1 Like

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!

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 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.

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?

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?

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?

The Core API geometry occlusion system will handle the distance calculation itself based on the listener and audio source positions every time 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?