[vlc-devel] [PATCH v3 8/8] d3d11: use View matrix instead of individual rotation
Alexandre Janniaux
ajanni at videolabs.io
Fri Mar 8 10:35:45 CET 2019
---
modules/video_output/win32/d3d11_shaders.c | 7 +--
modules/video_output/win32/d3d11_shaders.h | 3 -
modules/video_output/win32/direct3d11.c | 65 +---------------------
3 files changed, 3 insertions(+), 72 deletions(-)
diff --git a/modules/video_output/win32/d3d11_shaders.c b/modules/video_output/win32/d3d11_shaders.c
index a591e43854..bec0756229 100644
--- a/modules/video_output/win32/d3d11_shaders.c
+++ b/modules/video_output/win32/d3d11_shaders.c
@@ -166,9 +166,6 @@ VS_OUTPUT main( VS_INPUT In )\n\
const char* globVertexShaderProjection = "\n\
cbuffer VS_PROJECTION_CONST : register(b0)\n\
{\n\
- float4x4 RotX;\n\
- float4x4 RotY;\n\
- float4x4 RotZ;\n\
float4x4 View;\n\
float4x4 Zoom;\n\
float4x4 Projection;\n\
@@ -189,9 +186,7 @@ VS_OUTPUT main( VS_INPUT In )\n\
{\n\
VS_OUTPUT Output;\n\
float4 pos = In.Position;\n\
- pos = mul(RotY, pos);\n\
- pos = mul(RotX, pos);\n\
- pos = mul(RotZ, pos);\n\
+ pos = mul(View, pos);\n\
pos = mul(Zoom, pos);\n\
pos = mul(Projection, pos);\n\
Output.Position = pos;\n\
diff --git a/modules/video_output/win32/d3d11_shaders.h b/modules/video_output/win32/d3d11_shaders.h
index c7582972ce..fea6dbdd22 100644
--- a/modules/video_output/win32/d3d11_shaders.h
+++ b/modules/video_output/win32/d3d11_shaders.h
@@ -66,9 +66,6 @@ typedef struct {
} PS_COLOR_TRANSFORM;
typedef struct {
- FLOAT RotX[4*4];
- FLOAT RotY[4*4];
- FLOAT RotZ[4*4];
FLOAT View[4*4];
FLOAT Zoom[4*4];
FLOAT Projection[4*4];
diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index 53f10a74dc..f2e28dd8d1 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -659,60 +659,6 @@ static void DestroyDisplayPoolPicture(picture_t *picture)
free(p_sys);
}
-/* rotation around the Z axis */
-static void getZRotMatrix(float theta, FLOAT matrix[static 16])
-{
- float st, ct;
-
- sincosf(theta, &st, &ct);
-
- const FLOAT m[] = {
- /* x y z w */
- ct, -st, 0.f, 0.f,
- st, ct, 0.f, 0.f,
- 0.f, 0.f, 1.f, 0.f,
- 0.f, 0.f, 0.f, 1.f
- };
-
- memcpy(matrix, m, sizeof(m));
-}
-
-/* rotation around the Y axis */
-static void getYRotMatrix(float theta, FLOAT matrix[static 16])
-{
- float st, ct;
-
- sincosf(theta, &st, &ct);
-
- const FLOAT m[] = {
- /* x y z w */
- ct, 0.f, -st, 0.f,
- 0.f, 1.f, 0.f, 0.f,
- st, 0.f, ct, 0.f,
- 0.f, 0.f, 0.f, 1.f
- };
-
- memcpy(matrix, m, sizeof(m));
-}
-
-/* rotation around the X axis */
-static void getXRotMatrix(float phi, FLOAT matrix[static 16])
-{
- float sp, cp;
-
- sincosf(phi, &sp, &cp);
-
- const FLOAT m[] = {
- /* x y z w */
- 1.f, 0.f, 0.f, 0.f,
- 0.f, cp, sp, 0.f,
- 0.f, -sp, cp, 0.f,
- 0.f, 0.f, 0.f, 1.f
- };
-
- memcpy(matrix, m, sizeof(m));
-}
-
static void getZoomMatrix(float zoom, FLOAT matrix[static 16]) {
const FLOAT m[] = {
@@ -780,16 +726,13 @@ static void SetQuadVSProjection(vout_display_t *vd, d3d_quad_t *quad, const vlc_
if (!quad->pVertexShaderConstants)
return;
-#define RAD(d) ((float) ((d) * M_PI / 180.f))
- float f_fovx = RAD(p_vp->fov);
+ // Convert degree into radian
+ float f_fovx = p_vp->fov * (float)M_PI / 180.f;
if ( f_fovx > FIELD_OF_VIEW_DEGREES_MAX * M_PI / 180 + 0.001f ||
f_fovx < -0.001f )
return;
float f_sar = (float) sys->sys.vdcfg.display.width / sys->sys.vdcfg.display.height;
- float f_teta = RAD(p_vp->yaw) - (float) M_PI_2;
- float f_phi = RAD(p_vp->pitch);
- float f_roll = RAD(p_vp->roll);
float f_fovy = UpdateFOVy(f_fovx, f_sar);
float f_z = UpdateZ(f_fovx, f_fovy);
@@ -798,9 +741,6 @@ static void SetQuadVSProjection(vout_display_t *vd, d3d_quad_t *quad, const vlc_
hr = ID3D11DeviceContext_Map(sys->d3d_dev.d3dcontext, (ID3D11Resource *)quad->pVertexShaderConstants, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
if (SUCCEEDED(hr)) {
VS_PROJECTION_CONST *dst_data = mapped.pData;
- getXRotMatrix(f_phi, dst_data->RotX);
- getYRotMatrix(f_teta, dst_data->RotY);
- getZRotMatrix(f_roll, dst_data->RotZ);
getZoomMatrix(SPHERE_RADIUS * f_z, dst_data->Zoom);
getProjectionMatrix(f_sar, f_fovy, dst_data->Projection);
@@ -809,7 +749,6 @@ static void SetQuadVSProjection(vout_display_t *vd, d3d_quad_t *quad, const vlc_
vlc_viewpoint_to_4x4(&vp, dst_data->View);
}
ID3D11DeviceContext_Unmap(sys->d3d_dev.d3dcontext, (ID3D11Resource *)quad->pVertexShaderConstants, 0);
-#undef RAD
}
static int Control(vout_display_t *vd, int query, va_list args)
--
2.21.0
More information about the vlc-devel
mailing list