diff options
author | iurii <[email protected]> | 2024-09-05 23:42:07 +0200 |
---|---|---|
committer | iurii <[email protected]> | 2024-09-05 23:42:07 +0200 |
commit | c78784795449732a4d7edb72af28506ab16d0117 (patch) | |
tree | ff4a9a1b9f31f8c507151c44a847da6ac4b8bb2e | |
parent | 6add0f74e9c8a0a1b1252a8bab01a2d677555e63 (diff) | |
download | funhalla-c78784795449732a4d7edb72af28506ab16d0117.tar.gz |
colored cubes``
-rw-r--r-- | res/shaders/colors.fs | 15 | ||||
-rw-r--r-- | src/main.odin | 14 |
2 files changed, 23 insertions, 6 deletions
diff --git a/res/shaders/colors.fs b/res/shaders/colors.fs index df02754..053e1c4 100644 --- a/res/shaders/colors.fs +++ b/res/shaders/colors.fs @@ -6,32 +6,39 @@ struct Material { float shininess; }; +struct Light { + vec3 position; + vec3 ambient; + vec3 diffuse; + vec3 specular; +}; + out vec4 FragColor; in vec3 Normal; in vec3 FragPos; -uniform vec3 light_color; uniform vec3 light_position; uniform vec3 view_position; uniform Material material; +uniform Light light; void main() { // ambient - vec3 ambient = light_color * material.ambient; + vec3 ambient = light.ambient * material.ambient; // diffuse vec3 norm = normalize(Normal); vec3 light_dir = normalize(light_position - FragPos); float diff = max(dot(norm, light_dir), 0.0); - vec3 diffuse = light_color * (diff * material.diffuse); + vec3 diffuse = light.diffuse * (diff * material.diffuse); // specular vec3 view_dir = normalize(view_position - FragPos); vec3 reflect_dir = reflect(-light_dir, norm); float spec = pow(max(dot(view_dir, reflect_dir), 0.0), material.shininess); - vec3 specular = light_color * (spec * material.specular); + vec3 specular = light.specular * (spec * material.specular); vec3 result = ambient + diffuse + specular; FragColor = vec4(result, 1.0); diff --git a/src/main.odin b/src/main.odin index ea37cc0..67f4c4c 100644 --- a/src/main.odin +++ b/src/main.odin @@ -398,17 +398,27 @@ main :: proc() { shader.use(lighting_shader) - light_color := Vec3{1.0, 1.0, 1.0} + light_color := Vec3 { + cast(f32)math.sin(glfw.GetTime() * 2.0), + cast(f32)math.sin(glfw.GetTime() * 0.7), + cast(f32)math.sin(glfw.GetTime() * 1.3), + } material_ambient := Vec3{1.0, 0.5, 0.31} material_diffuse := Vec3{1.0, 0.5, 0.31} material_specular := Vec3{0.5, 0.5, 0.5} - shader.set_vec3(lighting_shader, cstring("light_color"), &light_color) shader.set_vec3(lighting_shader, cstring("material.ambient"), &material_ambient) shader.set_vec3(lighting_shader, cstring("material.diffuse"), &material_diffuse) shader.set_vec3(lighting_shader, cstring("material.specular"), &material_specular) shader.set_f32(lighting_shader, cstring("material.shininess"), 32.0) + light_diffuse := light_color * Vec3{0.5, 0.5, 0.05} + light_ambient := light_diffuse * Vec3{0.2, 0.2, 0.2} + light_specular := Vec3{1.0, 1.0, 1.0} + shader.set_vec3(lighting_shader, cstring("light.ambient"), &light_ambient) + shader.set_vec3(lighting_shader, cstring("light.diffuse"), &light_diffuse) + shader.set_vec3(lighting_shader, cstring("light.specular"), &light_specular) + shader.set_vec3(lighting_shader, cstring("light_position"), &light_pos) shader.set_vec3(lighting_shader, cstring("view_position"), &camera.position) |