Adding resources and tweaks
This commit is contained in:
48
main.c
48
main.c
@@ -107,6 +107,7 @@ static void DrawLevel(Model mdlTile);
|
||||
static void CenterMouseAndFlush(void);
|
||||
int Random(int x);
|
||||
static void RenderTrees(Master* g, Texture2D tree, Vector3 treepos, float treeSize);
|
||||
static void ApplyFogShaderToModel(Model *m, Shader fog);
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Program main entry point
|
||||
@@ -162,14 +163,15 @@ int main(void)
|
||||
|
||||
|
||||
// Load GLTF model (no animations)
|
||||
//Model model = LoadModel("resources/3d_models/bad_sphere.glb");
|
||||
//Vector3 position = { 0.0f, 0.0f, 0.0f };
|
||||
Model wall = LoadModel("resources/3d_models/Tiny_Treats_Homely_House_1.0_FREE/Assets/gltf/fence_straight.gltf");
|
||||
Vector3 wall_position = { 0.0f, 0.0f, 120.0f };
|
||||
|
||||
// Load a 2D image as texture for the billboard
|
||||
//Billboards always point toward the active camera.
|
||||
Texture2D sign = LoadTexture("resources/sprites/husk/ZOMBC1.png");
|
||||
//Texture2D sign = LoadTexture("resources/sprites/diard-charles.jpg");
|
||||
GenTextureMipmaps(&sign);
|
||||
SetTextureFilter(sign, TEXTURE_FILTER_BILINEAR); // optional but looks nicer
|
||||
SetTextureFilter(sign, TEXTURE_FILTER_POINT); // optional but looks nicer
|
||||
Vector3 bbPos = (Vector3){ -1.0f, 2.0f, -1.0f }; // where in 3D world to place it
|
||||
float bbSize = 4.0f; // billboard height in world units
|
||||
|
||||
@@ -222,7 +224,7 @@ int main(void)
|
||||
SetShaderValue(skyboxShader, GetShaderLocation(skyboxShader, "vflipped"), &vflipped, SHADER_UNIFORM_INT);
|
||||
SetShaderValue(skyboxShader, GetShaderLocation(skyboxShader, "doGamma"), &doGamma, SHADER_UNIFORM_INT);
|
||||
|
||||
// Load the fog-of-war shader
|
||||
// Load the fog shader
|
||||
Shader fog = LoadShader("shaders/fog.vs", "shaders/fog.fs");
|
||||
|
||||
// Grab uniform locations (cache them)
|
||||
@@ -255,6 +257,9 @@ int main(void)
|
||||
// --- Apply shader to your ground tile model ---
|
||||
mdlTile.materials[0].shader = fog; // same shader also works for opaque
|
||||
|
||||
//Apply shader to wall
|
||||
ApplyFogShaderToModel(&wall, fog);
|
||||
|
||||
// Defaults for opaque geometry (no alpha cut)
|
||||
float cutoffOpaque = 0.0f;
|
||||
SetShaderValue(fog, locCutoff_fog, &cutoffOpaque, SHADER_UNIFORM_FLOAT);
|
||||
@@ -423,7 +428,7 @@ int main(void)
|
||||
DrawModel(skybox, (Vector3){0}, 1.0f, WHITE);
|
||||
|
||||
rlEnableDepthMask();
|
||||
rlEnableBackfaceCulling();
|
||||
rlEnableBackfaceCulling();
|
||||
|
||||
DrawLevel(mdlTile);
|
||||
|
||||
@@ -433,6 +438,7 @@ int main(void)
|
||||
|
||||
BeginShaderMode(fog);
|
||||
|
||||
DrawModel(wall, wall_position, 5.0, WHITE);
|
||||
RenderTrees(&g, tree, treepos, treeSize);
|
||||
DrawBillboard(g.player.camera, sign, bbPos, bbSize, WHITE);
|
||||
|
||||
@@ -470,6 +476,7 @@ int main(void)
|
||||
UnloadTexture(texGrass); // frees the grass texture you loaded
|
||||
UnloadTexture(tree); // frees tree texture
|
||||
UnloadTexture(sign);
|
||||
UnloadModel(wall);
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
@@ -761,4 +768,33 @@ static void RenderTrees(Master* g, Texture2D tree, Vector3 baseTreePos, float tr
|
||||
DrawTreeBillboardStable(g->player.camera, tree, pos, /*height*/ treeSize, WHITE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void ApplyFogShaderToModel(Model *m, Shader fog)
|
||||
{
|
||||
// 1) Tell raylib which uniform in your shader is the ALBEDO map
|
||||
fog.locs[SHADER_LOC_MATRIX_MODEL] = GetShaderLocation(fog, "matModel");
|
||||
fog.locs[SHADER_LOC_MATRIX_VIEW] = GetShaderLocation(fog, "matView");
|
||||
fog.locs[SHADER_LOC_MATRIX_PROJECTION] = GetShaderLocation(fog, "matProjection");
|
||||
fog.locs[SHADER_LOC_MAP_ALBEDO] = GetShaderLocation(fog, "texture0"); // your FS: uniform sampler2D texture0;
|
||||
|
||||
// (optional but nice)
|
||||
fog.locs[SHADER_LOC_COLOR_DIFFUSE] = GetShaderLocation(fog, "colDiffuse");
|
||||
|
||||
// 2) For each material, make sure the base color texture ends up in the ALBEDO slot
|
||||
for (int i = 0; i < m->materialCount; ++i) {
|
||||
Material *mat = &m->materials[i];
|
||||
|
||||
// Some importers put the base map in DIFFUSE, copy to ALBEDO if ALBEDO is empty.
|
||||
if (mat->maps[MATERIAL_MAP_ALBEDO].texture.id == 0 &&
|
||||
mat->maps[MATERIAL_MAP_DIFFUSE].texture.id != 0) {
|
||||
mat->maps[MATERIAL_MAP_ALBEDO].texture = mat->maps[MATERIAL_MAP_DIFFUSE].texture;
|
||||
}
|
||||
|
||||
// Ensure non-zero tint
|
||||
if (mat->maps[MATERIAL_MAP_ALBEDO].color.a == 0) mat->maps[MATERIAL_MAP_ALBEDO].color = WHITE;
|
||||
|
||||
// 3) Attach your fog shader to this material
|
||||
mat->shader = fog;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user