2 Commits

Author SHA1 Message Date
YourWishes 8cfa8ddfeb Weaather baseline 2026-07-08 12:57:13 -05:00
YourWishes ef284a15a1 pre-cache shader matrices 2026-07-08 12:36:40 -05:00
3 changed files with 65 additions and 40 deletions
+35 -21
View File
@@ -24,6 +24,8 @@
#include "asset/loader/assetloader.h" #include "asset/loader/assetloader.h"
#include "asset/loader/assetentry.h" #include "asset/loader/assetentry.h"
#include "util/memory.h"
errorret_t sceneOverworldInit(scenedata_t *sceneData) { errorret_t sceneOverworldInit(scenedata_t *sceneData) {
assertNotNull(sceneData, "Scene data cannot be null"); assertNotNull(sceneData, "Scene data cannot be null");
errorOk(); errorOk();
@@ -40,55 +42,67 @@ errorret_t sceneOverworldRender(scenedata_t *sceneData) {
sceneoverworld_t *overworld = &sceneData->overworld; sceneoverworld_t *overworld = &sceneData->overworld;
sceneOverworldCullUpdate(overworld); sceneOverworldCullUpdate(overworld);
errorChain(displaySetState((displaystate_t){
.flags = DISPLAY_STATE_FLAG_DEPTH_TEST | DISPLAY_STATE_FLAG_CULL // Overworld camera
}));
mat4 model;
errorChain(shaderBind(&SHADER_UNLIT)); errorChain(shaderBind(&SHADER_UNLIT));
errorChain(shaderSetMatrix(
&SHADER_UNLIT, SHADER_UNLIT_MODEL, SCENE.screenIdentity
));
// Model
glm_mat4_identity(model);
errorChain(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_MODEL, model));
// Camera projection
rpgCameraUpdateProjection(); rpgCameraUpdateProjection();
errorChain(shaderSetMatrix( errorChain(shaderSetMatrix(
&SHADER_UNLIT, SHADER_UNLIT_PROJECTION, RPG_CAMERA.projection &SHADER_UNLIT, SHADER_UNLIT_PROJECTION, RPG_CAMERA.projection
)); ));
// Camera Eye
rpgCameraUpdateEye(); rpgCameraUpdateEye();
errorChain(shaderSetMatrix( errorChain(shaderSetMatrix(
&SHADER_UNLIT, SHADER_UNLIT_VIEW, RPG_CAMERA.eye &SHADER_UNLIT, SHADER_UNLIT_VIEW, RPG_CAMERA.eye
)); ));
// Base terrain meshes, drawn with normal depth testing. // Chunk tiles
errorChain(displaySetState((displaystate_t){
.flags = DISPLAY_STATE_FLAG_DEPTH_TEST | DISPLAY_STATE_FLAG_CULL
}));
errorChain(sceneOverworldDrawChunksBase(overworld)); errorChain(sceneOverworldDrawChunksBase(overworld));
// Entities are drawn with depth testing fully disabled so sloped tiles // Entities
// (ramps) never clip them; entity-vs-entity overlap falls back to
// array draw order instead of true depth.
errorChain(displaySetState((displaystate_t){ errorChain(displaySetState((displaystate_t){
.flags = DISPLAY_STATE_FLAG_CULL .flags = DISPLAY_STATE_FLAG_CULL
})); }));
// Entities
for(uint8_t i = 0; i < ENTITY_COUNT; i++) { for(uint8_t i = 0; i < ENTITY_COUNT; i++) {
entity_t *ent = &ENTITIES[i]; entity_t *ent = &ENTITIES[i];
if(ent->type == ENTITY_TYPE_NULL) continue; if(ent->type == ENTITY_TYPE_NULL) continue;
errorChain(sceneOverworldDrawEntity(overworld, ent)); errorChain(sceneOverworldDrawEntity(overworld, ent));
} }
// Other chunk meshes (trees, buildings, etc), drawn last with normal // Chunk props
// depth testing so they correctly occlude entities standing beneath
// them.
errorChain(displaySetState((displaystate_t){ errorChain(displaySetState((displaystate_t){
.flags = DISPLAY_STATE_FLAG_DEPTH_TEST | DISPLAY_STATE_FLAG_CULL .flags = DISPLAY_STATE_FLAG_DEPTH_TEST | DISPLAY_STATE_FLAG_CULL
})); }));
errorChain(sceneOverworldDrawChunksProps(overworld)); errorChain(sceneOverworldDrawChunksProps(overworld));
// Weather effects
// errorChain(shaderSetMatrix(
// &SHADER_UNLIT, SHADER_UNLIT_PROJECTION, SCENE.screenProj
// ));
// errorChain(shaderSetMatrix(
// &SHADER_UNLIT, SHADER_UNLIT_VIEW, SCENE.screenView
// ));
// errorChain(displaySetState((displaystate_t){
// .flags = DISPLAY_STATE_FLAG_BLEND
// }));
// spritebatchsprite_t skyboxSprite;
// memoryZero(&skyboxSprite, sizeof(spritebatchsprite_t));
// skyboxSprite.max[0] = (float_t)(SCREEN.width / SCREEN.scaleUi);
// skyboxSprite.max[1] = (float_t)(SCREEN.height / SCREEN.scaleUi);
// shadermaterial_t skyboxMaterial = {
// .unlit = { .color = color(0xFF, 0x00, 0x00, 0xFF/2), .texture = NULL }
// };
// errorChain(spriteBatchBuffer(&skyboxSprite, 1, &SHADER_UNLIT, skyboxMaterial));
// errorChain(spriteBatchFlush());
errorOk(); errorOk();
} }
+26 -19
View File
@@ -58,6 +58,23 @@ errorret_t sceneUpdate(void) {
} }
errorret_t sceneRender(void) { errorret_t sceneRender(void) {
// Setup screen matrices for 3D rendering.
glm_mat4_identity(SCENE.screenIdentity);
glm_ortho(
0.0f, (float_t)(SCREEN.width / SCREEN.scaleUi),
(float_t)(SCREEN.height / SCREEN.scaleUi), 0.0f,
0.1f, 100.0f,
SCENE.screenProj
);
glm_lookat(
(vec3){ 0.0f, 0.0f, 1.0f },
(vec3){ 0.0f, 0.0f, 0.0f },
(vec3){ 0.0f, 1.0f, 0.0f },
SCENE.screenView
);
// Scene rendering // Scene rendering
if( if(
SCENE.current != SCENE_TYPE_NULL && SCENE.current != SCENE_TYPE_NULL &&
@@ -67,26 +84,16 @@ errorret_t sceneRender(void) {
} }
// UI Rendering // UI Rendering
mat4 proj, view, ident;
glm_mat4_identity(ident);
errorChain(shaderBind(&SHADER_UNLIT)); errorChain(shaderBind(&SHADER_UNLIT));
errorChain(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_MODEL, ident)); errorChain(shaderSetMatrix(
&SHADER_UNLIT, SHADER_UNLIT_MODEL, SCENE.screenIdentity
glm_ortho( ));
0.0f, (float_t)(SCREEN.width / SCREEN.scaleUi), errorChain(shaderSetMatrix(
(float_t)(SCREEN.height / SCREEN.scaleUi), 0.0f, &SHADER_UNLIT, SHADER_UNLIT_PROJECTION, SCENE.screenProj
0.1f, 100.0f, ));
proj errorChain(shaderSetMatrix(
); &SHADER_UNLIT, SHADER_UNLIT_VIEW, SCENE.screenView
errorChain(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_PROJECTION, proj)); ));
glm_lookat(
(vec3){ 0.0f, 0.0f, 1.0f },
(vec3){ 0.0f, 0.0f, 0.0f },
(vec3){ 0.0f, 1.0f, 0.0f },
view
);
errorChain(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_VIEW, view));
errorChain(displaySetState((displaystate_t){ errorChain(displaySetState((displaystate_t){
.flags = DISPLAY_STATE_FLAG_BLEND .flags = DISPLAY_STATE_FLAG_BLEND
+4
View File
@@ -6,12 +6,16 @@
*/ */
#pragma once #pragma once
#include "dusk.h"
#include "scenetype.h" #include "scenetype.h"
typedef struct { typedef struct {
scenetype_t current; scenetype_t current;
scenetype_t next; scenetype_t next;
scenedata_t data; scenedata_t data;
mat4 screenProj;
mat4 screenView;
mat4 screenIdentity;
} scene_t; } scene_t;
extern scene_t SCENE; extern scene_t SCENE;