Skip to content

Commit 7fef65a

Browse files
authored
Make fogColor in the fog tutorial a parameter (#5672)
* uniform fogColor fogColor is now a parameter * use new fog color parameter * convert ambient to Vector4
1 parent da9e881 commit 7fef65a

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

examples/shaders/resources/shaders/glsl330/fog.fs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ struct Light {
3737
uniform Light lights[MAX_LIGHTS];
3838
uniform vec4 ambient;
3939
uniform vec3 viewPos;
40+
uniform vec4 fogColor;
4041
uniform float fogDensity;
4142

4243
void main()
@@ -77,10 +78,6 @@ void main()
7778
// Fog calculation
7879
float dist = length(viewPos - fragPosition);
7980

80-
// these could be parameters...
81-
const vec4 fogColor = vec4(0.5, 0.5, 0.5, 1.0);
82-
//const float fogDensity = 0.16;
83-
8481
// Exponential fog
8582
float fogFactor = 1.0/exp((dist*fogDensity)*(dist*fogDensity));
8683

examples/shaders/shaders_fog_rendering.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,13 @@ int main(void)
7272
shader.locs[SHADER_LOC_VECTOR_VIEW] = GetShaderLocation(shader, "viewPos");
7373

7474
// Ambient light level
75+
Vector4 ambient = (Vector4){ 0.2f, 0.2f, 0.2f, 1.0f };
7576
int ambientLoc = GetShaderLocation(shader, "ambient");
76-
SetShaderValue(shader, ambientLoc, (float[4]){ 0.2f, 0.2f, 0.2f, 1.0f }, SHADER_UNIFORM_VEC4);
77+
SetShaderValue(shader, ambientLoc, &ambient, SHADER_UNIFORM_VEC4);
78+
79+
Vector4 fogColor = ColorNormalize(GRAY);
80+
int fogColorLoc = GetShaderLocation(shader, "fogColor");
81+
SetShaderValue(shader, fogColorLoc, &fogColor, SHADER_UNIFORM_VEC4);
7782

7883
float fogDensity = 0.15f;
7984
int fogDensityLoc = GetShaderLocation(shader, "fogDensity");

0 commit comments

Comments
 (0)