Basic flashlight
This commit is contained in:
47
main.c
47
main.c
@@ -200,8 +200,8 @@ int main(void)
|
||||
|
||||
// Load skybox shader
|
||||
Shader skyboxShader = LoadShader(
|
||||
"resources/shaders/skybox.vs",
|
||||
"resources/shaders/skybox.fs"
|
||||
"shaders/skybox.vs",
|
||||
"shaders/skybox.fs"
|
||||
);
|
||||
|
||||
// Attach shader to skybox
|
||||
@@ -221,7 +221,7 @@ int main(void)
|
||||
SetShaderValue(skyboxShader, GetShaderLocation(skyboxShader, "doGamma"), &doGamma, SHADER_UNIFORM_INT);
|
||||
|
||||
// Load the fog-of-war shader
|
||||
Shader fog = LoadShader("resources/shaders/fog.vs", "resources/shaders/fog.fs");
|
||||
Shader fog = LoadShader("shaders/fog.vs", "shaders/fog.fs");
|
||||
|
||||
// Grab uniform locations (cache them)
|
||||
int locPlayer = GetShaderLocation(fog, "u_playerPos");
|
||||
@@ -236,6 +236,16 @@ int main(void)
|
||||
// Optional if you added the sharpness curve in the shader
|
||||
int locSharpness = GetShaderLocation(fog, "u_sharpness");
|
||||
|
||||
//Flashlight
|
||||
int locSpotDir = GetShaderLocation(fog, "u_spotDir");
|
||||
int locSpotCos = GetShaderLocation(fog, "u_spotCos");
|
||||
int locSpotSoft = GetShaderLocation(fog, "u_spotSoft");
|
||||
int locLightRange = GetShaderLocation(fog, "u_lightRange");
|
||||
int locLightFade = GetShaderLocation(fog, "u_lightFade");
|
||||
int locIntensity = GetShaderLocation(fog, "u_intensity");
|
||||
int locBeamSpread = GetShaderLocation(fog, "u_beamSpread");
|
||||
|
||||
|
||||
// Let raylib know which matrices the shader expects
|
||||
fog.locs[SHADER_LOC_MATRIX_MODEL] = GetShaderLocation(fog, "matModel");
|
||||
fog.locs[SHADER_LOC_MATRIX_VIEW] = GetShaderLocation(fog, "matView");
|
||||
@@ -250,17 +260,33 @@ int main(void)
|
||||
|
||||
// Fog/vignette tuning
|
||||
float inner = 0.0f; // start radius (center under player)
|
||||
float outer = 45.0f; // how far until full fog
|
||||
float minShadow = 0.45f; // baseline darkness at the center (0 = none, 1 = pitch black)
|
||||
float outer = 20.0f; // how far until full fog
|
||||
float minShadow = 0.9f; // baseline darkness at the center (0 = none, 1 = pitch black)
|
||||
float sharpness = 2.0f; // steeper edge (optional if shader uses it)
|
||||
Vector4 fogColor = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
|
||||
|
||||
// Flashligh tuning
|
||||
float spotAngleDeg = 35.0f; //cone angle
|
||||
float spotCos = cosf(DEG2RAD * (spotAngleDeg * 0.5f));
|
||||
float spotSoft = 0.05f;
|
||||
float lightRange = 150.0f;
|
||||
float lightFade = 10.0f;
|
||||
float intensity = 0.25f; // try 0.7–1.5 to taste
|
||||
float beamSpread = 0.00f; // try 0.15–0.35; higher = less “laser” at distance
|
||||
|
||||
SetShaderValue(fog, locIntensity, &intensity, SHADER_UNIFORM_FLOAT);
|
||||
SetShaderValue(fog, locBeamSpread, &beamSpread, SHADER_UNIFORM_FLOAT);
|
||||
SetShaderValue(fog, locSpotCos, &spotCos, SHADER_UNIFORM_FLOAT);
|
||||
SetShaderValue(fog, locSpotSoft, &spotSoft, SHADER_UNIFORM_FLOAT);
|
||||
SetShaderValue(fog, locLightRange, &lightRange, SHADER_UNIFORM_FLOAT);
|
||||
SetShaderValue(fog, locLightFade, &lightFade, SHADER_UNIFORM_FLOAT);
|
||||
|
||||
SetShaderValue(fog, locInner, &inner, SHADER_UNIFORM_FLOAT);
|
||||
SetShaderValue(fog, locOuter, &outer, SHADER_UNIFORM_FLOAT);
|
||||
SetShaderValue(fog, locMinShadow, &minShadow, SHADER_UNIFORM_FLOAT);
|
||||
SetShaderValue(fog, locFogColor, &fogColor, SHADER_UNIFORM_VEC4);
|
||||
SetShaderValue(fog, locSharpness, &sharpness, SHADER_UNIFORM_FLOAT);
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
@@ -367,8 +393,15 @@ int main(void)
|
||||
case STATE_GAME:
|
||||
{
|
||||
ClearBackground(BLACK);
|
||||
|
||||
Vector3 camPos = g.player.camera.position;
|
||||
Vector3 camFwd = Vector3Normalize(Vector3Subtract(g.player.camera.target, camPos));
|
||||
|
||||
SetShaderValue(fog, locPlayer, &g.player.position, SHADER_UNIFORM_VEC3);
|
||||
// Camera forward (normalize target - position)
|
||||
Vector3 forward = Vector3Normalize(Vector3Subtract(g.player.camera.target, g.player.camera.position));
|
||||
|
||||
SetShaderValue(fog, locPlayer, &camPos, SHADER_UNIFORM_VEC3);
|
||||
SetShaderValue(fog, locSpotDir, &camFwd, SHADER_UNIFORM_VEC3);
|
||||
|
||||
BeginMode3D(g.player.camera);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user