opengl.shader: Allow shaders to be built from snippets.

This commit is contained in:
Rod Kay
2023-05-07 06:46:45 +10:00
parent 8570d1709e
commit 5daf101be3
4 changed files with 128 additions and 57 deletions

View File

@@ -1,5 +1,3 @@
#version 140
struct light
{
vec4 Site;
@@ -16,10 +14,6 @@ uniform mat3 inverse_model_Rotation;
uniform vec3 camera_Site;
uniform vec3 specular_Color; // The materials specular color.
uniform int texture_Count;
uniform sampler2D Textures [32];
uniform float Fade [32];
uniform int light_Count;
uniform light Lights [10];
@@ -32,6 +26,8 @@ in float frag_Shine;
out vec4 final_Color;
vec3
apply_Light (light Light,
vec3 surface_Color,
@@ -95,33 +91,16 @@ apply_Light (light Light,
void
main()
{
vec3 surface_Site = vec3 ( model_Transform
* vec4 (frag_Site, 1));
vec4 surface_Color = vec4 (0);
for (int i = 0; i < texture_Count; ++i)
{
// surface_Color += texture (Textures [i],
// frag_Coords);
surface_Color.rgb += texture (Textures [i],frag_Coords).rgb
* texture (Textures [i],frag_Coords).a
* (1.0 - Fade [i]);
surface_Color.a = max (surface_Color.a, texture (Textures [i],
frag_Coords).a);
}
surface_Color = surface_Color; // / texture_Count;
vec4 surface_Color = apply_Texturing (frag_Coords);
vec3 Surface_to_Camera = normalize (camera_Site - surface_Site);
vec3 Normal = normalize ( frag_Normal
* inverse_model_Rotation);
// Combine color from all the lights.
//
vec3 linear_Color = vec3 (0);
@@ -135,8 +114,7 @@ main()
Surface_to_Camera);
}
vec3 Gamma = vec3 (1.0 / 2.2);
vec3 Gamma = vec3 (1.0 / 2.2);
final_Color = vec4 (pow (linear_Color, // Final color (after gamma correction).
Gamma),
surface_Color.a);