Add initial prototype.

This commit is contained in:
Rod Kay
2022-07-31 17:34:54 +10:00
commit 54a53b2ac0
1421 changed files with 358874 additions and 0 deletions

Binary file not shown.

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,12 @@
#version 140
in vec4 frag_Color;
out vec4 final_Color;
void
main()
{
final_Color = frag_Color;
}

View File

@@ -0,0 +1,23 @@
#version 140
uniform mat4 mvp_Transform;
uniform vec3 Scale;
in vec3 Site;
in vec4 Color;
out vec3 frag_Site;
out vec4 frag_Color;
void main()
{
// Pass some variables to the fragment shader.
//
frag_Site = Site;
frag_Color = Color;
// Apply all matrix transformations to 'Site'.
//
gl_Position = mvp_Transform * vec4 (Site * Scale, 1);
}

View File

@@ -0,0 +1,15 @@
#version 140
uniform sampler2D sTexture;
varying vec4 vColor;
varying vec2 vCoords;
void main()
{
gl_FragColor = mix (texture2D (sTexture, vCoords),
vColor,
0.5);
}

View File

@@ -0,0 +1,19 @@
#version 140
uniform mat4 mvp_Transform;
uniform vec3 Scale;
attribute vec3 Site;
attribute vec4 Color;
attribute vec2 Coords;
varying vec4 vColor;
varying vec2 vCoords;
void main()
{
gl_Position = mvp_Transform * vec4 (Site * Scale, 1.0);
vColor = Color;
vCoords = Coords;
}

View File

@@ -0,0 +1,123 @@
#version 140
struct light
{
vec4 Site;
vec3 Color;
float Attenuation;
float ambient_Coefficient;
float cone_Angle;
vec3 cone_Direction;
};
uniform mat4 model_Transform;
uniform mat3 inverse_model_Rotation;
uniform vec3 camera_Site;
uniform vec3 specular_Color; // The materials specular color.
uniform int light_Count;
uniform light Lights [10];
in vec3 frag_Site;
in vec3 frag_Normal;
in vec4 frag_Color;
in float frag_Shine;
out vec4 final_Color;
vec3
apply_Light (light Light,
vec3 surface_Color,
vec3 Normal,
vec3 surface_Site,
vec3 Surface_to_Camera)
{
vec3 Surface_to_Light;
float Attenuation = 1.0;
if (Light.Site.w == 0.0)
{
// Directional light.
//
Surface_to_Light = normalize (-Light.Site.xyz);
Attenuation = 1.0; // No attenuation for directional lights.
}
else
{
// Point light.
//
vec3 Surface_to_Light_vector = Light.Site.xyz - surface_Site;
float Distance_to_Light = length (Surface_to_Light_vector);
Surface_to_Light = normalize (Surface_to_Light_vector);
Attenuation = 1.0
/ ( 1.0
+ Light.Attenuation
* pow (Distance_to_Light, 2));
// Cone restrictions which affects attenuation.
//
float Light_to_Surface_Angle = degrees (acos (dot (-Surface_to_Light,
normalize (Light.cone_Direction))));
if (Light_to_Surface_Angle > Light.cone_Angle)
{
Attenuation = 0.0;
}
}
vec3 lit_surface_Color = surface_Color * Light.Color;
vec3 Ambient = Light.ambient_Coefficient * lit_surface_Color;
float diffuse_Coefficient = max (0.0,
dot (Normal,
Surface_to_Light));
vec3 Diffuse = diffuse_Coefficient * lit_surface_Color;
float specular_Coefficient = 0.0;
if (diffuse_Coefficient > 0.0)
specular_Coefficient = pow (max (0.0,
dot (Surface_to_Camera,
reflect (-Surface_to_Light,
Normal))),
frag_Shine);
vec3 Specular = specular_Coefficient * specular_Color * Light.Color;
return Ambient + Attenuation * (Diffuse + Specular); // Linear color (before gamma correction).
}
void
main()
{
vec3 surface_Site = vec3 ( model_Transform
* vec4 (frag_Site, 1));
vec4 surface_Color = frag_Color;
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);
for (int i = 0; i < light_Count; ++i)
{
linear_Color += apply_Light (Lights [i],
surface_Color.rgb,
Normal,
surface_Site,
Surface_to_Camera);
}
vec3 Gamma = vec3 (1.0 / 2.2);
final_Color = vec4 (pow (linear_Color, // Final color (after gamma correction).
Gamma),
surface_Color.a);
}

View File

@@ -0,0 +1,29 @@
#version 140
uniform mat4 mvp_Transform;
uniform vec3 Scale;
in vec3 Site;
in vec3 Normal;
in vec4 Color;
in float Shine;
out vec3 frag_Site;
out vec3 frag_Normal;
out vec4 frag_Color;
out float frag_Shine;
void main()
{
// Pass some variables to the fragment shader.
//
frag_Site = Site;
frag_Normal = Normal;
frag_Color = Color;
frag_Shine = Shine;
// Apply all matrix transformations to 'Site'.
//
gl_Position = mvp_Transform * vec4 (Site * Scale, 1);
}

View File

@@ -0,0 +1,127 @@
#version 140
struct light
{
vec4 Site;
vec3 Color;
float Attenuation;
float ambient_Coefficient;
float cone_Angle;
vec3 cone_Direction;
};
uniform mat4 model_Transform;
uniform mat3 inverse_model_Rotation;
uniform vec3 camera_Site;
uniform vec3 specular_Color; // The materials specular color.
uniform sampler2D Texture;
uniform int light_Count;
uniform light Lights [10];
in vec3 frag_Site;
in vec3 frag_Normal;
in vec4 frag_Color;
in vec2 frag_Coords;
in float frag_Shine;
out vec4 final_Color;
vec3
apply_Light (light Light,
vec3 surface_Color,
vec3 Normal,
vec3 surface_Site,
vec3 Surface_to_Camera)
{
vec3 Surface_to_Light;
float Attenuation = 1.0;
if (Light.Site.w == 0.0)
{
// Directional light.
//
Surface_to_Light = normalize (-Light.Site.xyz);
Attenuation = 1.0; // No attenuation for directional lights.
}
else
{
// Point light.
//
vec3 Surface_to_Light_vector = Light.Site.xyz - surface_Site;
float Distance_to_Light = length (Surface_to_Light_vector);
Surface_to_Light = normalize (Surface_to_Light_vector);
Attenuation = 1.0
/ ( 1.0
+ Light.Attenuation
* pow (Distance_to_Light, 2));
// Cone restrictions which affects attenuation.
//
float Light_to_Surface_Angle = degrees (acos (dot (-Surface_to_Light,
normalize (Light.cone_Direction))));
if (Light_to_Surface_Angle > Light.cone_Angle)
{
Attenuation = 0.0;
}
}
vec3 lit_surface_Color = surface_Color * Light.Color;
vec3 Ambient = Light.ambient_Coefficient * lit_surface_Color;
float diffuse_Coefficient = max (0.0,
dot (Normal,
Surface_to_Light));
vec3 Diffuse = diffuse_Coefficient * lit_surface_Color;
float specular_Coefficient = 0.0;
if (diffuse_Coefficient > 0.0)
specular_Coefficient = pow (max (0.0,
dot (Surface_to_Camera,
reflect (-Surface_to_Light,
Normal))),
frag_Shine);
vec3 Specular = specular_Coefficient * specular_Color * Light.Color;
return Ambient + Attenuation * (Diffuse + Specular); // Linear color (before gamma correction).
}
void
main()
{
vec3 surface_Site = vec3 ( model_Transform
* vec4 (frag_Site, 1));
vec4 surface_Color = ( texture (Texture, frag_Coords)
+ frag_Color)
/ 2.0;
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);
for (int i = 0; i < light_Count; ++i)
{
linear_Color += apply_Light (Lights [i],
surface_Color.rgb,
Normal,
surface_Site,
Surface_to_Camera);
}
vec3 Gamma = vec3 (1.0 / 2.2);
final_Color = vec4 (pow (linear_Color, // Final color (after gamma correction).
Gamma),
surface_Color.a);
}

View File

@@ -0,0 +1,114 @@
#version 140
uniform mat4 mvp_Transform;
uniform vec3 Scale;
uniform mat4 bone_Matrices[120];
in vec3 Site;
in vec3 Normal;
in vec4 Color;
in vec2 Coords;
in float Shine;
in vec4 bone_Ids;
in vec4 bone_Weights;
out vec3 frag_Site;
out vec3 frag_Normal;
out vec4 frag_Color;
out vec2 frag_Coords;
out float frag_Shine;
const float c_zero = 0.0;
const float c_one = 1.0;
void main()
{
vec4 transformedPosition = vec4 (0.0);
vec3 transformedNormal = vec3 (0.0);
if (int (bone_Ids.x) == 0) // No bones affect this vertex.
{
transformedPosition = vec4 (Site, c_one);
transformedNormal = Normal;
}
else
{
// Bone 1.
//
mat4 m44 = bone_Matrices [int (bone_Ids.x) - 1];
// Transform the offset by bone 1.
transformedPosition += m44 * vec4 (Site, c_one) * bone_Weights.x;
mat3 m33 = mat3 (m44[0].xyz,
m44[1].xyz,
m44[2].xyz);
// Transform the normal by bone 1.
transformedNormal += m33 * Normal * bone_Weights.x;
if (int (bone_Ids.y) != 0)
{
// Bone 2.
//
m44 = bone_Matrices [int (bone_Ids.y) - 1];
// Transform the offset by bone 2.
transformedPosition += m44 * vec4 (Site, c_one) * bone_Weights.y;
m33 = mat3 (m44[0].xyz,
m44[1].xyz,
m44[2].xyz);
// Transform the normal by bone 2.
transformedNormal += m33 * Normal * bone_Weights.y;
if (int (bone_Ids.z) != 0)
{
// Bone 3.
//
m44 = bone_Matrices [int (bone_Ids.z) - 1];
// Transform the offset by bone 3.
transformedPosition += m44 * vec4 (Site, c_one) * bone_Weights.z;
m33 = mat3(m44[0].xyz,
m44[1].xyz,
m44[2].xyz);
// Transform the normal by bone 3.
transformedNormal += m33 * Normal * bone_Weights.z;
if (int (bone_Ids.w) != 0)
{
// Bone 4.
//
m44 = bone_Matrices [int (bone_Ids.w) - 1];
// Transform the offset by bone 4.
transformedPosition += m44 * vec4 (Site, c_one) * bone_Weights.w;
m33 = mat3 (m44[0].xyz,
m44[1].xyz,
m44[2].xyz);
// Transform the normal by bone 4.
transformedNormal += m33 * Normal * bone_Weights.w;
}
}
}
}
// Pass some variables to the fragment shader.
//
frag_Site = Site;
frag_Normal = normalize (transformedNormal);
frag_Color = Color;
frag_Coords = Coords;
frag_Shine = Shine;
// Apply all matrix transformations to 'Site'.
//
gl_Position = mvp_Transform * (transformedPosition * vec4 (Scale, 1));
}

View File

@@ -0,0 +1,132 @@
#version 140
struct light
{
vec4 Site;
vec3 Color;
float Attenuation;
float ambient_Coefficient;
float cone_Angle;
vec3 cone_Direction;
};
uniform mat4 model_Transform;
uniform mat3 inverse_model_Rotation;
uniform vec3 camera_Site;
uniform vec3 specular_Color; // The materials specular color.
uniform sampler2D Texture;
uniform int light_Count;
uniform light Lights [10];
in vec3 frag_Site;
in vec3 frag_Normal;
in vec4 frag_Color;
in vec2 frag_Coords;
in float frag_Shine;
out vec4 final_Color;
vec3
apply_Light (light Light,
vec3 surface_Color,
vec3 Normal,
vec3 surface_Site,
vec3 Surface_to_Camera)
{
vec3 Surface_to_Light;
float Attenuation = 1.0;
if (Light.Site.w == 0.0)
{
// Directional light.
//
Surface_to_Light = normalize (-Light.Site.xyz);
Attenuation = 1.0; // No attenuation for directional lights.
}
else
{
// Difuse light.
//
vec3 Surface_to_Light_vector = Light.Site.xyz - surface_Site;
float Distance_to_Light = length (Surface_to_Light_vector);
Surface_to_Light = normalize (Surface_to_Light_vector);
Attenuation = 1.0
/ ( 1.0
+ Light.Attenuation
* pow (Distance_to_Light, 2));
// Cone restrictions which affects attenuation.
//
float Light_to_Surface_Angle = degrees (acos (dot (-Surface_to_Light,
normalize (Light.cone_Direction))));
if (Light_to_Surface_Angle > Light.cone_Angle)
{
Attenuation = 0.0;
}
}
vec3 lit_surface_Color = surface_Color * Light.Color;
vec3 Ambient = Light.ambient_Coefficient * lit_surface_Color;
float diffuse_Coefficient = max (0.0,
dot (Normal,
Surface_to_Light));
vec3 Diffuse = diffuse_Coefficient * lit_surface_Color;
float specular_Coefficient = 0.0;
if (diffuse_Coefficient > 0.0)
specular_Coefficient = pow (max (0.0,
dot (Surface_to_Camera,
reflect (-Surface_to_Light,
Normal))),
frag_Shine);
vec3 Specular = specular_Coefficient * specular_Color * Light.Color;
return Ambient + Attenuation * (Diffuse + Specular); // Linear color (before gamma correction).
}
void
main()
{
vec4 texture_Color = texture (Texture, frag_Coords);
vec4 surface_Color = vec4 (mix (texture_Color.rgb,
frag_Color .rgb,
0.5),
texture_Color.a
* frag_Color .a);
vec3 surface_Site = vec3 ( model_Transform
* vec4 (frag_Site, 1));
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);
for (int i = 0; i < light_Count; ++i)
{
linear_Color += apply_Light (Lights [i],
surface_Color.rgb,
Normal,
surface_Site,
Surface_to_Camera);
}
vec3 Gamma = vec3 (1.0 / 2.2);
final_Color = vec4 (pow (linear_Color, // Final color (after gamma correction).
Gamma),
surface_Color.a);
}

View File

@@ -0,0 +1,126 @@
#version 140
struct light
{
vec4 Site;
vec3 Color;
float Attenuation;
float ambient_Coefficient;
float cone_Angle;
vec3 cone_Direction;
};
uniform mat4 model_Transform;
uniform mat3 inverse_model_Rotation;
uniform vec3 camera_Site;
uniform vec3 specular_Color; // The materials specular color.
uniform sampler2D Texture;
uniform int light_Count;
uniform light Lights [10];
in vec3 frag_Site;
in vec3 frag_Normal;
in vec4 frag_Color;
in vec2 frag_Coords;
in float frag_Shine;
out vec4 final_Color;
vec3
apply_Light (light Light,
vec3 surface_Color,
vec3 Normal,
vec3 surface_Site,
vec3 Surface_to_Camera)
{
vec3 Surface_to_Light;
float Attenuation = 1.0;
if (Light.Site.w == 0.0)
{
// Directional light.
//
Surface_to_Light = normalize (-Light.Site.xyz);
Attenuation = 1.0; // No attenuation for directional lights.
}
else
{
// Point light.
//
vec3 Surface_to_Light_vector = Light.Site.xyz - surface_Site;
float Distance_to_Light = length (Surface_to_Light_vector);
Surface_to_Light = normalize (Surface_to_Light_vector);
Attenuation = 1.0
/ ( 1.0
+ Light.Attenuation
* pow (Distance_to_Light, 2));
// Cone restrictions which affects attenuation.
//
float Light_to_Surface_Angle = degrees (acos (dot (-Surface_to_Light,
normalize (Light.cone_Direction))));
if (Light_to_Surface_Angle > Light.cone_Angle)
{
Attenuation = 0.0;
}
}
vec3 lit_surface_Color = surface_Color * Light.Color;
vec3 Ambient = Light.ambient_Coefficient * lit_surface_Color;
float diffuse_Coefficient = max (0.0,
dot (Normal,
Surface_to_Light));
vec3 Diffuse = diffuse_Coefficient * lit_surface_Color;
float specular_Coefficient = 0.0;
if (diffuse_Coefficient > 0.0)
specular_Coefficient = pow (max (0.0,
dot (Surface_to_Camera,
reflect (-Surface_to_Light,
Normal))),
frag_Shine);
vec3 Specular = specular_Coefficient * specular_Color * Light.Color;
return Ambient + Attenuation * (Diffuse + Specular); // Linear color (before gamma correction).
}
void
main()
{
vec3 surface_Site = vec3 ( model_Transform
* vec4 (frag_Site, 1));
vec4 surface_Color = mix (texture (Texture, frag_Coords),
frag_Color,
0.5);
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);
for (int i = 0; i < light_Count; ++i)
{
linear_Color += apply_Light (Lights [i],
surface_Color.rgb,
Normal,
surface_Site,
Surface_to_Camera);
}
vec3 Gamma = vec3 (1.0 / 2.2);
final_Color = vec4 (pow (linear_Color, // Final color (after gamma correction).
Gamma),
surface_Color.a);
}

View File

@@ -0,0 +1,32 @@
#version 140
uniform mat4 mvp_Transform;
uniform vec3 Scale;
in vec3 Site;
in vec3 Normal;
in vec4 Color;
in vec2 Coords;
in float Shine;
out vec3 frag_Site;
out vec3 frag_Normal;
out vec4 frag_Color;
out vec2 frag_Coords;
out float frag_Shine;
void main()
{
// Pass some variables to the fragment shader.
//
frag_Site = Site;
frag_Normal = Normal;
frag_Color = Color;
frag_Coords = Coords;
frag_Shine = Shine;
// Apply all matrix transformations to 'Site'.
//
gl_Position = mvp_Transform * vec4 (Site * Scale, 1);
}

View File

@@ -0,0 +1,127 @@
#version 140
struct light
{
vec4 Site;
vec3 Color;
float Attenuation;
float ambient_Coefficient;
float cone_Angle;
vec3 cone_Direction;
};
uniform mat4 model_Transform;
uniform mat3 inverse_model_Rotation;
uniform vec3 camera_Site;
uniform vec3 specular_Color; // The materials specular color.
uniform sampler2D Texture;
uniform int light_Count;
uniform light Lights [10];
in vec3 frag_Site;
in vec3 frag_Normal;
in vec4 frag_Color;
in vec2 frag_Coords;
in float frag_Shine;
out vec4 final_Color;
vec3
apply_Light (light Light,
vec3 surface_Color,
vec3 Normal,
vec3 surface_Site,
vec3 Surface_to_Camera)
{
vec3 Surface_to_Light;
float Attenuation = 1.0;
if (Light.Site.w == 0.0)
{
// Directional light.
//
Surface_to_Light = normalize (-Light.Site.xyz);
Attenuation = 1.0; // No attenuation for directional lights.
}
else
{
// Point light.
//
vec3 Surface_to_Light_vector = Light.Site.xyz - surface_Site;
float Distance_to_Light = length (Surface_to_Light_vector);
Surface_to_Light = normalize (Surface_to_Light_vector);
Attenuation = 1.0
/ ( 1.0
+ Light.Attenuation
* pow (Distance_to_Light, 2));
// Cone restrictions which affects attenuation.
//
float Light_to_Surface_Angle = degrees (acos (dot (-Surface_to_Light,
normalize (Light.cone_Direction))));
if (Light_to_Surface_Angle > Light.cone_Angle)
{
Attenuation = 0.0;
}
}
vec3 lit_surface_Color = surface_Color * Light.Color;
vec3 Ambient = Light.ambient_Coefficient * lit_surface_Color;
float diffuse_Coefficient = max (0.0,
dot (Normal,
Surface_to_Light));
vec3 Diffuse = diffuse_Coefficient * lit_surface_Color;
float specular_Coefficient = 0.0;
if (diffuse_Coefficient > 0.0)
specular_Coefficient = pow (max (0.0,
dot (Surface_to_Camera,
reflect (-Surface_to_Light,
Normal))),
frag_Shine);
vec3 Specular = specular_Coefficient * specular_Color * Light.Color;
return Ambient + Attenuation * (Diffuse + Specular); // Linear color (before gamma correction).
}
void
main()
{
vec3 surface_Site = vec3 ( model_Transform
* vec4 (frag_Site, 1));
vec4 surface_Color = mix (texture (Texture, frag_Coords),
frag_Color,
0.5);
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);
for (int i = 0; i < light_Count; ++i)
{
linear_Color += apply_Light (Lights [i],
surface_Color.rgb,
Normal,
surface_Site,
Surface_to_Camera);
}
vec3 Gamma = vec3 (1.0 / 2.2);
final_Color = vec4 (pow (linear_Color, // Final color (after gamma correction).
Gamma),
surface_Color.a);
}

View File

@@ -0,0 +1,114 @@
#version 140
uniform mat4 mvp_Transform;
uniform vec3 Scale;
uniform mat4 bone_Matrices[120];
in vec3 Site;
in vec3 Normal;
in vec4 Color;
in vec2 Coords;
in float Shine;
in vec4 bone_Ids;
in vec4 bone_Weights;
out vec3 frag_Site;
out vec3 frag_Normal;
out vec4 frag_Color;
out vec2 frag_Coords;
out float frag_Shine;
const float c_zero = 0.0;
const float c_one = 1.0;
void main()
{
vec4 transformedPosition = vec4 (0.0);
vec3 transformedNormal = vec3 (0.0);
if (int (bone_Ids.x) == 0) // No bones affect this vertex.
{
transformedPosition = vec4 (Site, c_one);
transformedNormal = Normal;
}
else
{
// Bone 1.
//
mat4 m44 = bone_Matrices [int (bone_Ids.x) - 1];
// Transform the offset by bone 1.
transformedPosition += m44 * vec4 (Site, c_one) * bone_Weights.x;
mat3 m33 = mat3 (m44[0].xyz,
m44[1].xyz,
m44[2].xyz);
// Transform the normal by bone 1.
transformedNormal += m33 * Normal * bone_Weights.x;
if (int (bone_Ids.y) != 0)
{
// Bone 2.
//
m44 = bone_Matrices [int (bone_Ids.y) - 1];
// Transform the offset by bone 2.
transformedPosition += m44 * vec4 (Site, c_one) * bone_Weights.y;
m33 = mat3 (m44[0].xyz,
m44[1].xyz,
m44[2].xyz);
// Transform the normal by bone 2.
transformedNormal += m33 * Normal * bone_Weights.y;
if (int (bone_Ids.z) != 0)
{
// Bone 3.
//
m44 = bone_Matrices [int (bone_Ids.z) - 1];
// Transform the offset by bone 3.
transformedPosition += m44 * vec4 (Site, c_one) * bone_Weights.z;
m33 = mat3(m44[0].xyz,
m44[1].xyz,
m44[2].xyz);
// Transform the normal by bone 3.
transformedNormal += m33 * Normal * bone_Weights.z;
if (int (bone_Ids.w) != 0)
{
// Bone 4.
//
m44 = bone_Matrices [int (bone_Ids.w) - 1];
// Transform the offset by bone 4.
transformedPosition += m44 * vec4 (Site, c_one) * bone_Weights.w;
m33 = mat3 (m44[0].xyz,
m44[1].xyz,
m44[2].xyz);
// Transform the normal by bone 4.
transformedNormal += m33 * Normal * bone_Weights.w;
}
}
}
}
// Pass some variables to the fragment shader.
//
frag_Site = Site;
frag_Normal = normalize (transformedNormal);
frag_Color = Color;
frag_Coords = Coords;
frag_Shine = Shine;
// Apply all matrix transformations to 'Site'.
//
gl_Position = mvp_Transform * (transformedPosition * vec4 (Scale, 1));
}

View File

@@ -0,0 +1,124 @@
#version 140
struct light
{
vec4 Site;
vec3 Color;
float Attenuation;
float ambient_Coefficient;
float cone_Angle;
vec3 cone_Direction;
};
uniform mat4 model_Transform;
uniform mat3 inverse_model_Rotation;
uniform vec3 camera_Site;
uniform vec3 specular_Color; // The materials specular color.
uniform sampler2D Texture;
uniform int light_Count;
uniform light Lights [10];
in vec3 frag_Site;
in vec3 frag_Normal;
in vec2 frag_Coords;
in float frag_Shine;
out vec4 final_Color;
vec3
apply_Light (light Light,
vec3 surface_Color,
vec3 Normal,
vec3 surface_Site,
vec3 Surface_to_Camera)
{
vec3 Surface_to_Light;
float Attenuation = 1.0;
if (Light.Site.w == 0.0)
{
// Directional light.
//
Surface_to_Light = normalize (-Light.Site.xyz);
Attenuation = 1.0; // No attenuation for directional lights.
}
else
{
// Point light.
//
vec3 Surface_to_Light_vector = Light.Site.xyz - surface_Site;
float Distance_to_Light = length (Surface_to_Light_vector);
Surface_to_Light = normalize (Surface_to_Light_vector);
Attenuation = 1.0
/ ( 1.0
+ Light.Attenuation
* pow (Distance_to_Light, 2));
// Cone restrictions which affects attenuation.
//
float Light_to_Surface_Angle = degrees (acos (dot (-Surface_to_Light,
normalize (Light.cone_Direction))));
if (Light_to_Surface_Angle > Light.cone_Angle)
{
Attenuation = 0.0;
}
}
vec3 lit_surface_Color = surface_Color * Light.Color;
vec3 Ambient = Light.ambient_Coefficient * lit_surface_Color;
float diffuse_Coefficient = max (0.0,
dot (Normal,
Surface_to_Light));
vec3 Diffuse = diffuse_Coefficient * lit_surface_Color;
float specular_Coefficient = 0.0;
if (diffuse_Coefficient > 0.0)
specular_Coefficient = pow (max (0.0,
dot (Surface_to_Camera,
reflect (-Surface_to_Light,
Normal))),
frag_Shine);
vec3 Specular = specular_Coefficient * specular_Color * Light.Color;
return Ambient + Attenuation * (Diffuse + Specular); // Linear color (before gamma correction).
}
void
main()
{
vec3 surface_Site = vec3 ( model_Transform
* vec4 (frag_Site, 1));
vec4 surface_Color = texture (Texture, 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);
for (int i = 0; i < light_Count; ++i)
{
linear_Color += apply_Light (Lights [i],
surface_Color.rgb,
Normal,
surface_Site,
Surface_to_Camera);
}
vec3 Gamma = vec3 (1.0 / 2.2);
final_Color = vec4 (pow (linear_Color, // Final color (after gamma correction).
Gamma),
surface_Color.a);
}

View File

@@ -0,0 +1,29 @@
#version 140
uniform mat4 mvp_Transform;
uniform vec3 Scale;
in vec3 Site;
in vec3 Normal;
in vec2 Coords;
in float Shine;
out vec3 frag_Site;
out vec3 frag_Normal;
out vec2 frag_Coords;
out float frag_Shine;
void main()
{
// Pass some variables to the fragment shader.
//
frag_Site = Site;
frag_Normal = Normal;
frag_Coords = Coords;
frag_Shine = Shine;
// Apply all matrix transformations to 'Site'.
//
gl_Position = mvp_Transform * vec4 (Site * Scale, 1);
}

View File

@@ -0,0 +1,124 @@
#version 140
struct light
{
vec4 Site;
vec3 Color;
float Attenuation;
float ambient_Coefficient;
float cone_Angle;
vec3 cone_Direction;
};
uniform mat4 model_Transform;
uniform mat3 inverse_model_Rotation;
uniform vec3 camera_Site;
uniform vec3 specular_Color; // The materials specular color.
uniform sampler2D Texture;
uniform int light_Count;
uniform light Lights [10];
in vec3 frag_Site;
in vec3 frag_Normal;
in vec2 frag_Coords;
in float frag_Shine;
out vec4 final_Color;
vec3
apply_Light (light Light,
vec3 surface_Color,
vec3 Normal,
vec3 surface_Site,
vec3 Surface_to_Camera)
{
vec3 Surface_to_Light;
float Attenuation = 1.0;
if (Light.Site.w == 0.0)
{
// Directional light.
//
Surface_to_Light = normalize (-Light.Site.xyz);
Attenuation = 1.0; // No attenuation for directional lights.
}
else
{
// Point light.
//
vec3 Surface_to_Light_vector = Light.Site.xyz - surface_Site;
float Distance_to_Light = length (Surface_to_Light_vector);
Surface_to_Light = normalize (Surface_to_Light_vector);
Attenuation = 1.0
/ ( 1.0
+ Light.Attenuation
* pow (Distance_to_Light, 2));
// Cone restrictions which affects attenuation.
//
float Light_to_Surface_Angle = degrees (acos (dot (-Surface_to_Light,
normalize (Light.cone_Direction))));
if (Light_to_Surface_Angle > Light.cone_Angle)
{
Attenuation = 0.0;
}
}
vec3 lit_surface_Color = surface_Color * Light.Color;
vec3 Ambient = Light.ambient_Coefficient * lit_surface_Color;
float diffuse_Coefficient = max (0.0,
dot (Normal,
Surface_to_Light));
vec3 Diffuse = diffuse_Coefficient * lit_surface_Color;
float specular_Coefficient = 0.0;
if (diffuse_Coefficient > 0.0)
specular_Coefficient = pow (max (0.0,
dot (Surface_to_Camera,
reflect (-Surface_to_Light,
Normal))),
frag_Shine);
vec3 Specular = specular_Coefficient * specular_Color * Light.Color;
return Ambient + Attenuation * (Diffuse + Specular); // Linear color (before gamma correction).
}
void
main()
{
vec3 surface_Site = vec3 ( model_Transform
* vec4 (frag_Site, 1));
vec4 surface_Color = texture (Texture, 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);
for (int i = 0; i < light_Count; ++i)
{
linear_Color += apply_Light (Lights [i],
surface_Color.rgb,
Normal,
surface_Site,
Surface_to_Camera);
}
vec3 Gamma = vec3 (1.0 / 2.2);
final_Color = vec4 (pow (linear_Color, // Final color (after gamma correction).
Gamma),
surface_Color.a);
}

View File

@@ -0,0 +1,116 @@
#version 140
uniform mat4 mvp_Transform;
uniform vec3 Scale;
uniform mat4 bone_Matrices[120];
in vec3 Site;
in vec3 Normal;
in vec2 Coords;
in float Shine;
in vec4 bone_Ids;
in vec4 bone_Weights;
out vec3 frag_Site;
out vec3 frag_Normal;
out vec2 frag_Coords;
out float frag_Shine;
const float c_zero = 0.0;
const float c_one = 1.0;
void main()
{
vec4 transformedPosition = vec4 (0.0);
vec3 transformedNormal = vec3 (0.0);
if (int (bone_Ids.x) == 0) // No bones affect this vertex.
{
transformedPosition = vec4 (Site, c_one);
transformedNormal = Normal;
}
else
{
// Bone 1.
//
mat4 m44 = bone_Matrices [int (bone_Ids.x) - 1];
// Transform the offset by bone 1.
transformedPosition += m44 * vec4 (Site, c_one) * bone_Weights.x;
mat3 m33 = mat3 (m44[0].xyz,
m44[1].xyz,
m44[2].xyz);
// Transform the normal by bone 1.
transformedNormal += m33 * Normal * bone_Weights.x;
if (int(bone_Ids.y) != 0)
{
// Bone 2.
//
m44 = bone_Matrices [int (bone_Ids.y) - 1];
// Transform the offset by bone 2.
transformedPosition += m44 * vec4 (Site, c_one) * bone_Weights.y;
m33 = mat3 (m44[0].xyz,
m44[1].xyz,
m44[2].xyz);
// Transform the normal by bone 2.
transformedNormal += m33 * Normal * bone_Weights.y;
if (int (bone_Ids.z) != 0)
{
// Bone 3.
//
m44 = bone_Matrices [int (bone_Ids.z) - 1];
// Transform the offset by bone 3.
transformedPosition += m44 * vec4 (Site, c_one) * bone_Weights.z;
m33 = mat3 (m44[0].xyz,
m44[1].xyz,
m44[2].xyz);
// Transform the normal by bone 3.
transformedNormal += m33 * Normal * bone_Weights.z;
if (int (bone_Ids.w) != 0)
{
// Bone 4.
//
m44 = bone_Matrices [int (bone_Ids.w) - 1];
// Transform the offset by bone 4.
transformedPosition += m44 * vec4 (Site, c_one) * bone_Weights.w;
m33 = mat3 (m44[0].xyz,
m44[1].xyz,
m44[2].xyz);
// Transform the normal by bone 4.
transformedNormal += m33 * Normal * bone_Weights.w;
}
}
}
}
// Pass some variables to the fragment shader.
//
frag_Site = transformedPosition.xyz * Scale;
frag_Normal = normalize (transformedNormal);
frag_Coords = Coords;
frag_Shine = Shine;
// Apply all matrix transformations to 'Site'.
//
gl_Position = mvp_Transform * transformedPosition;
gl_Position = mvp_Transform * (transformedPosition * vec4 (Scale, 1));
}

View File

@@ -0,0 +1,69 @@
#version 120
struct directional_light
{
vec3 direction; // Normalized light direction in eye space.
vec3 halfplane; // Normalized half-plane vector.
vec4 ambient_color;
vec4 diffuse_color;
vec4 specular_color;
bool is_on;
};
uniform mat3 inv_modelview_Matrix;
uniform directional_light uLights [8];
uniform float uShine;
attribute vec3 aNormal;
attribute vec4 aColor;
varying vec4 vColor;
const float c_zero = 0.0;
const float c_one = 1.0;
vec4 // Returns the computed color.
directional_light_color (in vec3 normal, // 'normal' has been transformed into eye space and normalized.
in directional_light light)
{
if (!light.is_on)
return vec4 (0.0, 0.0, 0.0, 0.0);
vec4 computed_color = vec4 (c_zero, c_zero, c_zero, c_zero);
float NdotL; // Dot product of normal and light direction.
float NdotH; // Dot product of normal and half-plane vector.
NdotL = max (c_zero, dot (normal, light.direction));
NdotH = max (c_zero, dot (normal, light.halfplane));
computed_color += ( light.ambient_color * aColor);
computed_color += (NdotL * light.diffuse_color * aColor);
if (NdotH > c_zero)
computed_color += (pow (NdotH, uShine) * aColor * light.specular_color);
return computed_color;
}
void main()
{
vec3 light_Normal = normalize (aNormal) * inv_modelview_Matrix;
vColor = vec4 (0.0, 0.0, 0.0, 0.0);
for (int i = 0; i < 8; i++)
{
vColor += directional_light_color (light_Normal, uLights [i]);
}
}

View File

@@ -0,0 +1,12 @@
#version 140
uniform sampler2D sTexture;
varying vec4 vColor;
varying vec2 vCoords;
void main()
{
gl_FragColor = texture2D (sTexture, vCoords) * vColor; // Modulate light color with texture.
}

View File

@@ -0,0 +1,25 @@
#version 140
uniform mat4 mvp_Transform;
uniform vec3 Scale;
attribute vec3 Site;
attribute vec2 Coords;
varying vec4 vColor;
varying vec2 vCoords;
const float c_zero = 0.0;
const float c_one = 1.0;
void main()
{
gl_Position = mvp_Transform * vec4 (Site * Scale, 1.0);
vColor = vec4 (1.0, 1.0, 1.0, 1.0);
vCoords = Coords;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB