Skip to content

Commit d390160

Browse files
committed
add new fragCoordTransformVect and perspectiveTransformVect utils to matrix4SIMD
1 parent c6c3f42 commit d390160

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

include/matrix4SIMD.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,28 @@ class matrix4SIMD// : public AlignedBase<_NBL_SIMD_ALIGNMENT> don't inherit from
169169

170170
bool isBoxInFrustum(const aabbox3d<float>& bbox);
171171

172+
bool perspectiveTransformVect(core::vectorSIMDf& inOutVec)
173+
{
174+
transformVect(inOutVec);
175+
const bool inFront = inOutVec[3] > 0.f;
176+
inOutVec /= inOutVec.wwww();
177+
return inFront;
178+
}
179+
180+
core::vector2di fragCoordTransformVect(const core::vectorSIMDf& _in, const core::dimension2du& viewportDimensions)
181+
{
182+
core::vectorSIMDf pos(_in);
183+
pos.w = 1.f;
184+
if (perspectiveTransformVect(pos))
185+
core::vector2di(-0x80000000, -0x80000000);
186+
187+
pos[0] *= 0.5f;
188+
pos[1] *= 0.5f;
189+
pos[0] += 0.5f;
190+
pos[1] += 0.5f;
191+
192+
return core::vector2di(pos[0] * float(viewportDimensions.Width), pos[1] * float(viewportDimensions.Height));
193+
}
172194

173195
static inline matrix4SIMD buildProjectionMatrixPerspectiveFovRH(float fieldOfViewRadians, float aspectRatio, float zNear, float zFar);
174196
static inline matrix4SIMD buildProjectionMatrixPerspectiveFovLH(float fieldOfViewRadians, float aspectRatio, float zNear, float zFar);

0 commit comments

Comments
 (0)