nxdk_pgraph_tests
A collection of tests for the Xbox nv2a graphics processor
 
Loading...
Searching...
No Matches
projection_vertex_shader.h
1#ifndef NXDK_PGRAPH_TESTS_SHADERS_PROJECTION_VERTEX_SHADER_H_
2#define NXDK_PGRAPH_TESTS_SHADERS_PROJECTION_VERTEX_SHADER_H_
3
4#include <cstdint>
5
6#include "vertex_shader_program.h"
7#include "xbox_math_types.h"
8
9using namespace XboxMath;
10
12 public:
13 ProjectionVertexShader(uint32_t framebuffer_width, uint32_t framebuffer_height, float z_min = 0, float z_max = 0x7FFF,
14 bool enable_lighting = true);
15
16 void SetLightingEnabled(bool enabled = true) { enable_lighting_ = enabled; }
17
18 inline void SetUseD3DStyleViewport(bool enable = true) {
19 use_d3d_style_viewport_ = enable;
20 UpdateMatrices();
21 }
22
23 inline void SetZMin(float val) { z_min_ = val; }
24 inline void SetZMax(float val) { z_max_ = val; }
25
26 inline float GetZMin() const { return z_min_; }
27 inline float GetZMax() const { return z_max_; }
28
29 inline void LookAt(const vector_t &camera_position, const vector_t &look_at_point) {
30 vector_t y_axis{0, 1, 0, 1};
31 LookAt(camera_position, look_at_point, y_axis);
32 }
33
34 void LookAt(const vector_t &camera_position, const vector_t &look_at_point, const vector_t &up);
35 void LookTo(const vector_t &camera_position, const vector_t &camera_direction, const vector_t &up);
36 void SetCamera(const vector_t &position, const vector_t &rotation);
37
39 void SetDirectionalLightDirection(const vector_t &direction);
40
42 void SetDirectionalLightCastDirection(const vector_t &direction);
43
44 matrix4_t &GetModelMatrix() { return model_matrix_; }
45 matrix4_t &GetViewMatrix() { return view_matrix_; }
46 matrix4_t &GetProjectionMatrix() { return projection_matrix_; }
47 matrix4_t &GetViewportMatrix() { return viewport_matrix_; }
48 matrix4_t &GetProjectionViewportMatrix() { return projection_viewport_matrix_; }
49
50 // Projects the given point (on the CPU), placing the resulting screen coordinates into `result`.
51 void ProjectPoint(vector_t &result, const vector_t &world_point) const;
52
54 void UnprojectPoint(vector_t &result, const vector_t &screen_point) const;
55
57 void UnprojectPoint(vector_t &result, const vector_t &screen_point, float world_z) const;
58
60 void SetTransposeOnUpload(bool transpose = true) { transpose_on_upload_ = transpose; }
61
62 protected:
63 void OnActivate() override;
64 void OnLoadShader() override;
65 void OnLoadConstants() override;
66 virtual void CalculateProjectionMatrix() = 0;
67
68 private:
69 void UpdateMatrices();
70 void CalculateViewportMatrix();
71
72 protected:
73 float framebuffer_width_{0.0};
74 float framebuffer_height_{0.0};
75 float z_min_;
76 float z_max_;
77
78 bool enable_lighting_{true};
79 // Generate a viewport matrix that matches XDK/D3D behavior.
80 bool use_d3d_style_viewport_{false};
81
82 matrix4_t model_matrix_{};
83 matrix4_t view_matrix_{};
84 matrix4_t projection_matrix_{};
85 matrix4_t viewport_matrix_{};
86 matrix4_t projection_viewport_matrix_{};
87
88 matrix4_t composite_matrix_{};
89 matrix4_t inverse_composite_matrix_{};
90
91 vector_t camera_position_ = {0, 0, -2.25, 1};
92 vector_t light_direction_ = {0, 0, 1, 1};
93
94 bool transpose_on_upload_{false};
95};
96
97#endif // NXDK_PGRAPH_TESTS_SHADERS_PROJECTION_VERTEX_SHADER_H_
Definition projection_vertex_shader.h:11
void SetTransposeOnUpload(bool transpose=true)
Causes matrices to be transposed before being uploaded to the shader.
Definition projection_vertex_shader.h:60
void UnprojectPoint(vector_t &result, const vector_t &screen_point) const
Unprojects the given screen point, producing world coordinates that will project there.
Definition projection_vertex_shader.cpp:205
void SetDirectionalLightDirection(const vector_t &direction)
Sets the direction from the origin towards the directional light.
Definition projection_vertex_shader.cpp:101
void SetDirectionalLightCastDirection(const vector_t &direction)
Sets the direction in which the directional light is casting light.
Definition projection_vertex_shader.cpp:105
Definition vertex_shader_program.h:13