Przeglądaj źródła

Merge branch 'master' of github.com:bkaradzic/bgfx

Бранимир Караџић 7 lat temu
rodzic
commit
bc65303576

+ 3 - 4
examples/13-stencil/stencil.cpp

@@ -1123,13 +1123,12 @@ public:
 					mtxReflected(reflectMtx, { 0.0f, 0.01f, 0.0f }, { 0.0f, 1.0f, 0.0f });
 
 					// Reflect lights.
-					float reflectedLights[MAX_NUM_LIGHTS][4];
 					for (uint8_t ii = 0; ii < numLights; ++ii)
 					{
-						bx::vec3MulMtx(reflectedLights[ii], lightPosRadius[ii], reflectMtx);
-						reflectedLights[ii][3] = lightPosRadius[ii][3];
+						bx::Vec3 reflected = bx::mul(bx::load<bx::Vec3>(lightPosRadius[ii]), reflectMtx);
+						bx::store(&s_uniforms.m_lightPosRadius[ii], reflected);
+						s_uniforms.m_lightPosRadius[ii][3] = lightPosRadius[ii][3];
 					}
-					bx::memCopy(s_uniforms.m_lightPosRadius, reflectedLights, numLights * 4*sizeof(float) );
 
 					// Reflect and submit bunny.
 					float mtxReflectedBunny[16];

+ 29 - 34
examples/14-shadowvolumes/shadowvolumes.cpp

@@ -1275,12 +1275,13 @@ struct ShadowVolume
 	bool m_cap;
 };
 
-void shadowVolumeLightTransform(float* __restrict _outLightPos
-							  , const float* __restrict _scale
-							  , const float* __restrict _rotate
-							  , const float* __restrict _translate
-							  , const float* __restrict _lightPos // world pos
-							  )
+void shadowVolumeLightTransform(
+	  float* __restrict _outLightPos
+	, const float* __restrict _scale
+	, const float* __restrict _rotate
+	, const float* __restrict _translate
+	, const float* __restrict _lightPos // world pos
+	)
 {
 	/**
 	 * Instead of transforming all the vertices, transform light instead:
@@ -1315,19 +1316,19 @@ void shadowVolumeLightTransform(float* __restrict _outLightPos
 	float mtx[16];
 	bx::mtxMul(mtx, tmp0, invScale);
 
-	float origin[3] = { 0.0f, 0.0f, 0.0f };
-	bx::vec3MulMtx(_outLightPos, origin, mtx);
+	bx::store(_outLightPos, bx::mul({ 0.0f, 0.0f, 0.0f }, mtx) );
 }
 
-void shadowVolumeCreate(ShadowVolume& _shadowVolume
-					  , Group& _group
-					  , uint16_t _stride
-					  , const float* _mtx
-					  , const float* _light // in model space
-					  , ShadowVolumeImpl::Enum _impl = ShadowVolumeImpl::DepthPass
-					  , ShadowVolumeAlgorithm::Enum _algo = ShadowVolumeAlgorithm::FaceBased
-					  , bool _textureAsStencil = false
-					  )
+void shadowVolumeCreate(
+	  ShadowVolume& _shadowVolume
+	, Group& _group
+	, uint16_t _stride
+	, const float* _mtx
+	, const float* _light // in model space
+	, ShadowVolumeImpl::Enum _impl = ShadowVolumeImpl::DepthPass
+	, ShadowVolumeAlgorithm::Enum _algo = ShadowVolumeAlgorithm::FaceBased
+	, bool _textureAsStencil = false
+	)
 {
 	const uint8_t*    vertices   = _group.m_vertices;
 	const FaceArray&  faces      = _group.m_faces;
@@ -1708,33 +1709,27 @@ void createNearClipVolume(float* __restrict _outPlanes24f
 	// -1.0f - behind near plane
 	const float lightSide = float( (d > delta) - (d < -delta) );
 
-	float t = bx::tan(bx::toRad(_fovy)*0.5f) * _near;
-	float b = -t;
-	float r = t * _aspect;
-	float l = -r;
+	const float t = bx::tan(bx::toRad(_fovy)*0.5f) * _near;
+	const float b = -t;
+	const float r = t * _aspect;
+	const float l = -r;
 
-	float cornersV[4][3] =
+	const bx::Vec3 corners[4] =
 	{
-		{ r, t, _near },
-		{ l, t, _near },
-		{ l, b, _near },
-		{ r, b, _near },
+		bx::mul({ r, t, _near }, mtxViewInv),
+		bx::mul({ l, t, _near }, mtxViewInv),
+		bx::mul({ l, b, _near }, mtxViewInv),
+		bx::mul({ r, b, _near }, mtxViewInv),
 	};
 
-	float corners[4][3];
-	bx::vec3MulMtx(corners[0], cornersV[0], mtxViewInv);
-	bx::vec3MulMtx(corners[1], cornersV[1], mtxViewInv);
-	bx::vec3MulMtx(corners[2], cornersV[2], mtxViewInv);
-	bx::vec3MulMtx(corners[3], cornersV[3], mtxViewInv);
-
 	float planeNormals[4][3];
 	for (uint8_t ii = 0; ii < 4; ++ii)
 	{
 		float* outNormal = planeNormals[ii];
 		float* outPlane  = volumePlanes[ii];
 
-		const bx::Vec3 c0       = bx::load<bx::Vec3>(corners[ii]);
-		const bx::Vec3 planeVec = bx::sub(c0, bx::load<bx::Vec3>(corners[(ii-1)&3]) );
+		const bx::Vec3 c0       = corners[ii];
+		const bx::Vec3 planeVec = bx::sub(c0, corners[(ii-1)&3]);
 		const bx::Vec3 light    = bx::sub(bx::load<bx::Vec3>(_lightPos), bx::mul(c0, _lightPos[3]) );
 		const bx::Vec3 normal   = bx::mul(bx::cross(planeVec, light), lightSide);
 

+ 23 - 33
examples/16-shadowmaps/shadowmaps.cpp

@@ -1076,7 +1076,7 @@ void worldSpaceFrustumCorners(float* _corners24f
 	const float fh = _far  * _projHeight;
 
 	const uint8_t numCorners = 8;
-	const float corners[numCorners][3] =
+	const bx::Vec3 corners[numCorners] =
 	{
 		{ -nw,  nh, _near },
 		{  nw,  nh, _near },
@@ -1092,7 +1092,7 @@ void worldSpaceFrustumCorners(float* _corners24f
 	float (*out)[3] = (float(*)[3])_corners24f;
 	for (uint8_t ii = 0; ii < numCorners; ++ii)
 	{
-		bx::vec3MulMtx( (float*)&out[ii], (float*)&corners[ii], _invViewMtx);
+		bx::store(&out[ii], bx::mul(corners[ii], _invViewMtx) );
 	}
 }
 
@@ -2453,16 +2453,16 @@ public:
 
 				float mtxProj[16];
 				bx::mtxOrtho(
-							 mtxProj
-							 , 1.0f
-							 , -1.0f
-							 , 1.0f
-							 , -1.0f
-							 , -currentSmSettings->m_far
-							 , currentSmSettings->m_far
-							 , 0.0f
-							 , caps->homogeneousDepth
-							 );
+					  mtxProj
+					, 1.0f
+					, -1.0f
+					, 1.0f
+					, -1.0f
+					, -currentSmSettings->m_far
+					, currentSmSettings->m_far
+					, 0.0f
+					, caps->homogeneousDepth
+					);
 
 				const uint8_t numCorners = 8;
 				float frustumCorners[maxNumSplits][numCorners][3];
@@ -2471,34 +2471,24 @@ public:
 					// Compute frustum corners for one split in world space.
 					worldSpaceFrustumCorners( (float*)frustumCorners[ii], splitSlices[nn], splitSlices[ff], projWidth, projHeight, mtxViewInv);
 
-					float min[3] = {  9000.0f,  9000.0f,  9000.0f };
-					float max[3] = { -9000.0f, -9000.0f, -9000.0f };
+					bx::Vec3 min = {  9000.0f,  9000.0f,  9000.0f };
+					bx::Vec3 max = { -9000.0f, -9000.0f, -9000.0f };
 
 					for (uint8_t jj = 0; jj < numCorners; ++jj)
 					{
 						// Transform to light space.
-						float lightSpaceFrustumCorner[3];
-						bx::vec3MulMtx(lightSpaceFrustumCorner, frustumCorners[ii][jj], lightView[0]);
+						const bx::Vec3 xyz = bx::mul(bx::load<bx::Vec3>(frustumCorners[ii][jj]), lightView[0]);
 
 						// Update bounding box.
-						min[0] = bx::min(min[0], lightSpaceFrustumCorner[0]);
-						max[0] = bx::max(max[0], lightSpaceFrustumCorner[0]);
-						min[1] = bx::min(min[1], lightSpaceFrustumCorner[1]);
-						max[1] = bx::max(max[1], lightSpaceFrustumCorner[1]);
-						min[2] = bx::min(min[2], lightSpaceFrustumCorner[2]);
-						max[2] = bx::max(max[2], lightSpaceFrustumCorner[2]);
+						min = bx::min(min, xyz);
+						max = bx::max(max, xyz);
 					}
 
-					float minproj[3];
-					float maxproj[3];
-					bx::vec3MulMtxH(minproj, min, mtxProj);
-					bx::vec3MulMtxH(maxproj, max, mtxProj);
-
-					float offsetx, offsety;
-					float scalex, scaley;
+					const bx::Vec3 minproj = bx::mulH(min, mtxProj);
+					const bx::Vec3 maxproj = bx::mulH(max, mtxProj);
 
-					scalex = 2.0f / (maxproj[0] - minproj[0]);
-					scaley = 2.0f / (maxproj[1] - minproj[1]);
+					float scalex = 2.0f / (maxproj.x - minproj.x);
+					float scaley = 2.0f / (maxproj.y - minproj.y);
 
 					if (m_settings.m_stabilize)
 					{
@@ -2507,8 +2497,8 @@ public:
 						scaley = quantizer / bx::ceil(quantizer / scaley);
 					}
 
-					offsetx = 0.5f * (maxproj[0] + minproj[0]) * scalex;
-					offsety = 0.5f * (maxproj[1] + minproj[1]) * scaley;
+					float offsetx = 0.5f * (maxproj.x + minproj.x) * scalex;
+					float offsety = 0.5f * (maxproj.y + minproj.y) * scaley;
 
 					if (m_settings.m_stabilize)
 					{

+ 12 - 19
examples/21-deferred/deferred.cpp

@@ -561,7 +561,7 @@ public:
 					Aabb aabb;
 					toAabb(aabb, lightPosRadius);
 
-					float box[8][3] =
+					const bx::Vec3 box[8] =
 					{
 						{ aabb.m_min.x, aabb.m_min.y, aabb.m_min.z },
 						{ aabb.m_min.x, aabb.m_min.y, aabb.m_max.z },
@@ -573,31 +573,24 @@ public:
 						{ aabb.m_max.x, aabb.m_max.y, aabb.m_max.z },
 					};
 
-					float xyz[3];
-					bx::vec3MulMtxH(xyz, box[0], vp);
-					float minx = xyz[0];
-					float miny = xyz[1];
-					float maxx = xyz[0];
-					float maxy = xyz[1];
-					float maxz = xyz[2];
+					bx::Vec3 xyz = bx::mulH(box[0], vp);
+					bx::Vec3 min = xyz;
+					bx::Vec3 max = xyz;
 
 					for (uint32_t ii = 1; ii < 8; ++ii)
 					{
-						bx::vec3MulMtxH(xyz, box[ii], vp);
-						minx = bx::min(minx, xyz[0]);
-						miny = bx::min(miny, xyz[1]);
-						maxx = bx::max(maxx, xyz[0]);
-						maxy = bx::max(maxy, xyz[1]);
-						maxz = bx::max(maxz, xyz[2]);
+						xyz = bx::mulH(box[ii], vp);
+						min = bx::min(min, xyz);
+						max = bx::max(max, xyz);
 					}
 
 					// Cull light if it's fully behind camera.
-					if (maxz >= 0.0f)
+					if (max.z >= 0.0f)
 					{
-						float x0 = bx::clamp( (minx * 0.5f + 0.5f) * m_width,  0.0f, (float)m_width);
-						float y0 = bx::clamp( (miny * 0.5f + 0.5f) * m_height, 0.0f, (float)m_height);
-						float x1 = bx::clamp( (maxx * 0.5f + 0.5f) * m_width,  0.0f, (float)m_width);
-						float y1 = bx::clamp( (maxy * 0.5f + 0.5f) * m_height, 0.0f, (float)m_height);
+						const float x0 = bx::clamp( (min.x * 0.5f + 0.5f) * m_width,  0.0f, (float)m_width);
+						const float y0 = bx::clamp( (min.y * 0.5f + 0.5f) * m_height, 0.0f, (float)m_height);
+						const float x1 = bx::clamp( (max.x * 0.5f + 0.5f) * m_width,  0.0f, (float)m_width);
+						const float y1 = bx::clamp( (max.y * 0.5f + 0.5f) * m_height, 0.0f, (float)m_height);
 
 						if (m_showScissorRects)
 						{

+ 1 - 2
examples/29-debugdraw/debugdraw.cpp

@@ -818,8 +818,7 @@ public:
 					1.0f
 				};
 
-				float up[3] = { 0.0f, 4.0f, 0.0f };
-				bx::vec3MulMtx(&cylinder.m_end.x, up, mtx);
+				cylinder.m_end = bx::mul({ 0.0f, 4.0f, 0.0f }, mtx);
 				dde.setColor(intersect(&dde, ray, cylinder) ? selected : 0xffffffff);
 				dde.draw(cylinder);
 

+ 3 - 8
examples/30-picking/picking.cpp

@@ -268,17 +268,12 @@ public:
 				float mouseXNDC = ( m_mouseState.m_mx             / (float)m_width ) * 2.0f - 1.0f;
 				float mouseYNDC = ((m_height - m_mouseState.m_my) / (float)m_height) * 2.0f - 1.0f;
 
-				float pickEye[3];
-				float mousePosNDC[3] = { mouseXNDC, mouseYNDC, 0.0f };
-				bx::vec3MulMtxH(pickEye, mousePosNDC, invViewProj);
-
-				float pickAt[3];
-				float mousePosNDCEnd[3] = { mouseXNDC, mouseYNDC, 1.0f };
-				bx::vec3MulMtxH(pickAt, mousePosNDCEnd, invViewProj);
+				const bx::Vec3 pickEye = bx::mulH({ mouseXNDC, mouseYNDC, 0.0f }, invViewProj);
+				const bx::Vec3 pickAt  = bx::mulH({ mouseXNDC, mouseYNDC, 1.0f }, invViewProj);
 
 				// Look at our unprojected point
 				float pickView[16];
-				bx::mtxLookAt(pickView, bx::load<bx::Vec3>(pickEye), bx::load<bx::Vec3>(pickAt) );
+				bx::mtxLookAt(pickView, pickEye, pickAt);
 
 				// Tight FOV is best for picking
 				float pickProj[16];

+ 1 - 1
examples/35-dynamic/dynamic.cpp

@@ -220,7 +220,7 @@ public:
 				const uint32_t abgr = m_mwc.gen();
 				for (uint32_t ii = 0; ii < BX_COUNTOF(s_cubeVertices); ++ii)
 				{
-					bx::vec3MulMtx(&vertex[ii].m_x, &s_cubeVertices[ii].m_x, mtx);
+					bx::store(&vertex[ii].m_x, bx::mul(bx::load<bx::Vec3>(&s_cubeVertices[ii].m_x), mtx) );
 					vertex[ii].m_abgr = abgr;
 				}
 

+ 2 - 12
examples/common/bounds.cpp

@@ -137,25 +137,15 @@ void toAabb(Aabb& _aabb, const float* _mtx, const void* _vertices, uint32_t _num
 {
 	bx::Vec3 min, max;
 	uint8_t* vertex = (uint8_t*)_vertices;
+	min = max = bx::mul(bx::load<bx::Vec3>(vertex), _mtx);
 
-	float position[3];
-	bx::vec3MulMtx(position, (float*)vertex, _mtx);
-	min.x = max.x = position[0];
-	min.y = max.y = position[1];
-	min.z = max.z = position[2];
 	vertex += _stride;
 
 	for (uint32_t ii = 1; ii < _numVertices; ++ii)
 	{
-		bx::vec3MulMtx(position, (float*)vertex, _mtx);
+		bx::Vec3 pos = bx::mul(bx::load<bx::Vec3>(vertex), _mtx);
 		vertex += _stride;
 
-		bx::Vec3 pos =
-		{
-			position[0],
-			position[1],
-			position[2],
-		};
 		min = bx::min(pos, min);
 		max = bx::max(pos, max);
 	}

+ 5 - 8
tools/texturev/texturev.cpp

@@ -2054,14 +2054,11 @@ int _main_(int _argc, char** _argv)
 
 			if (view.m_fit)
 			{
-				float wh[3] = { float(view.m_textureInfo.width), float(view.m_textureInfo.height), 0.0f };
-				float result[3];
-				bx::vec3MulMtx(result, wh, orientation);
-				result[0] = bx::round(bx::abs(result[0]) );
-				result[1] = bx::round(bx::abs(result[1]) );
-
-				scale.set(bx::min(float(view.m_width)  / result[0]
-					,             float(view.m_height) / result[1])
+				const bx::Vec3 wh = { float(view.m_textureInfo.width), float(view.m_textureInfo.height), 0.0f };
+				const bx::Vec3 result = bx::round(bx::abs(bx::mul(wh, orientation) ) );
+
+				scale.set(bx::min(float(view.m_width)  / result.x
+					,             float(view.m_height) / result.y)
 					, 0.1f*view.m_transitionTime
 					);
 			}