diff options
Diffstat (limited to 'src/llr')
| -rw-r--r-- | src/llr/llr.c | 42 | ||||
| -rw-r--r-- | src/llr/llr_impl.h | 3 |
2 files changed, 28 insertions, 17 deletions
diff --git a/src/llr/llr.c b/src/llr/llr.c index 746f4b3..74cfaed 100644 --- a/src/llr/llr.c +++ b/src/llr/llr.c | |||
| @@ -171,6 +171,9 @@ static void configure_state(LLR* renderer) { | |||
| 171 | gfx_set_mat4_uniform(shader, "ViewProjection", &view_proj); | 171 | gfx_set_mat4_uniform(shader, "ViewProjection", &view_proj); |
| 172 | gfx_set_mat4_uniform(shader, "MVP", &mvp); | 172 | gfx_set_mat4_uniform(shader, "MVP", &mvp); |
| 173 | gfx_set_vec3_uniform(shader, "CameraPosition", renderer->camera_position); | 173 | gfx_set_vec3_uniform(shader, "CameraPosition", renderer->camera_position); |
| 174 | gfx_set_mat4_uniform(shader, "CameraRotation", &renderer->camera_rotation); | ||
| 175 | gfx_set_float_uniform(shader, "Fovy", renderer->fovy); | ||
| 176 | gfx_set_float_uniform(shader, "Aspect", renderer->aspect); | ||
| 174 | } | 177 | } |
| 175 | 178 | ||
| 176 | if (renderer->lights_changed || renderer->shader_changed) { | 179 | if (renderer->lights_changed || renderer->shader_changed) { |
| @@ -188,9 +191,11 @@ static void configure_state(LLR* renderer) { | |||
| 188 | if (renderer->skeleton_changed || renderer->shader_changed) { | 191 | if (renderer->skeleton_changed || renderer->shader_changed) { |
| 189 | renderer->skeleton_changed = false; | 192 | renderer->skeleton_changed = false; |
| 190 | 193 | ||
| 191 | gfx_set_mat4_array_uniform( | 194 | if (renderer->num_joints > 0) { |
| 192 | shader, "JointMatrices", renderer->joint_matrices, | 195 | gfx_set_mat4_array_uniform( |
| 193 | renderer->num_joints); | 196 | shader, "JointMatrices", renderer->joint_matrices, |
| 197 | renderer->num_joints); | ||
| 198 | } | ||
| 194 | } | 199 | } |
| 195 | 200 | ||
| 196 | if (renderer->shader_changed) { | 201 | if (renderer->shader_changed) { |
| @@ -211,6 +216,9 @@ bool gfx_llr_make(LLR* renderer, GfxCore* gfxcore) { | |||
| 211 | goto cleanup; | 216 | goto cleanup; |
| 212 | } | 217 | } |
| 213 | gfx_llr_load_identity(renderer); | 218 | gfx_llr_load_identity(renderer); |
| 219 | renderer->view = mat4_id(); | ||
| 220 | renderer->projection = mat4_id(); | ||
| 221 | renderer->camera_rotation = mat4_id(); | ||
| 214 | return true; | 222 | return true; |
| 215 | 223 | ||
| 216 | cleanup: | 224 | cleanup: |
| @@ -278,7 +286,7 @@ void gfx_llr_set_skeleton( | |||
| 278 | renderer->skeleton_changed = true; | 286 | renderer->skeleton_changed = true; |
| 279 | } | 287 | } |
| 280 | 288 | ||
| 281 | void gfx_llr_unset_skeleton(LLR* renderer) { | 289 | void gfx_llr_clear_skeleton(LLR* renderer) { |
| 282 | assert(renderer); | 290 | assert(renderer); |
| 283 | 291 | ||
| 284 | renderer->num_joints = 0; | 292 | renderer->num_joints = 0; |
| @@ -288,22 +296,22 @@ void gfx_llr_unset_skeleton(LLR* renderer) { | |||
| 288 | void gfx_llr_set_camera(LLR* renderer, const Camera* camera) { | 296 | void gfx_llr_set_camera(LLR* renderer, const Camera* camera) { |
| 289 | assert(renderer); | 297 | assert(renderer); |
| 290 | 298 | ||
| 291 | const mat4 view = spatial3_inverse_transform(&camera->spatial); | 299 | renderer->camera_position = camera->spatial.p; |
| 292 | // const mat4 view_proj = mat4_mul(camera->projection, view); | 300 | renderer->camera_rotation = |
| 293 | // gfx_llr_set_view_projection_matrix(renderer, &view_proj); | 301 | mat4_rotation(spatial3_transform(&camera->spatial)); |
| 294 | renderer->view = view; | 302 | renderer->view = spatial3_inverse_transform(&camera->spatial); |
| 295 | renderer->projection = camera->projection; | 303 | renderer->projection = camera->projection; |
| 304 | // Assuming a perspective matrix. | ||
| 305 | renderer->fovy = (R)atan(1.0 / (mat4_at(camera->projection, 1, 1))) * 2; | ||
| 296 | renderer->camera_changed = true; | 306 | renderer->camera_changed = true; |
| 297 | } | 307 | } |
| 298 | 308 | ||
| 299 | // void gfx_llr_set_view_projection_matrix( | 309 | void gfx_llr_set_aspect(LLR* renderer, float aspect) { |
| 300 | // LLR* renderer, const mat4* view_proj) { | 310 | assert(renderer); |
| 301 | // assert(renderer); | 311 | |
| 302 | // assert(renderer->shader); | 312 | renderer->aspect = aspect; |
| 303 | // | 313 | renderer->camera_changed = true; |
| 304 | // gfx_llr_flush(renderer); | 314 | } |
| 305 | // gfx_set_mat4_uniform(renderer->shader, "ViewProjection", view_proj); | ||
| 306 | // } | ||
| 307 | 315 | ||
| 308 | void gfx_llr_render_geometry(LLR* renderer, const Geometry* geometry) { | 316 | void gfx_llr_render_geometry(LLR* renderer, const Geometry* geometry) { |
| 309 | assert(renderer); | 317 | assert(renderer); |
diff --git a/src/llr/llr_impl.h b/src/llr/llr_impl.h index e9dc0ac..ada2d79 100644 --- a/src/llr/llr_impl.h +++ b/src/llr/llr_impl.h | |||
| @@ -54,8 +54,11 @@ typedef struct LLR { | |||
| 54 | ShaderProgram* shader; // Active shader. Not owned. | 54 | ShaderProgram* shader; // Active shader. Not owned. |
| 55 | 55 | ||
| 56 | vec3 camera_position; | 56 | vec3 camera_position; |
| 57 | mat4 camera_rotation; | ||
| 57 | mat4 view; // Camera view matrix. | 58 | mat4 view; // Camera view matrix. |
| 58 | mat4 projection; // Camera projection matrix. | 59 | mat4 projection; // Camera projection matrix. |
| 60 | R fovy; // Camera vertical field of view. | ||
| 61 | R aspect; // Aspect ratio. | ||
| 59 | 62 | ||
| 60 | // Lights are not const because environment lights store lazily-computed | 63 | // Lights are not const because environment lights store lazily-computed |
| 61 | // irradiance maps. | 64 | // irradiance maps. |
