Changed light model
Former-commit-id: bdf192bd83dbb5ae3ce8c46d6414e5b4fbc0047a
This commit is contained in:
parent
83dc00dc60
commit
f69d2f13e5
|
|
@ -163,17 +163,9 @@ int main()
|
||||||
// Nous choisissons une lumière directionnelle représentant la nébuleuse de notre skybox
|
// Nous choisissons une lumière directionnelle représentant la nébuleuse de notre skybox
|
||||||
NzLight nebulaLight(nzLightType_Directional);
|
NzLight nebulaLight(nzLightType_Directional);
|
||||||
|
|
||||||
// Il nous faut ensuite configurer la lumière, pour commencer, les couleurs.
|
// Il nous faut ensuite configurer la lumière
|
||||||
|
// Pour commencer, sa couleur, la nébuleuse étant d'une couleur jaune, j'ai choisi ces valeurs
|
||||||
// La couleur ambiante est celle qui sera appliquée à toutes les faces, éclairées ou non, dans le rayon de la lumière
|
nebulaLight.SetColor(NzColor(255, 182, 90));
|
||||||
// Comme nous avons une lumière infinie, ceci est la couleur appliquée de base à toutes les faces de la scène
|
|
||||||
nebulaLight.SetAmbientColor(NzColor(30, 30, 30));
|
|
||||||
|
|
||||||
// Ensuite vient la couleur diffuse, celle-ci étant la couleur appliquée lorsque la lumière éclaire une face
|
|
||||||
nebulaLight.SetDiffuseColor(NzColor(255, 182, 90));
|
|
||||||
|
|
||||||
// Ensuite, la lumière spéculaire, appliquée aux faces éclairées faisant face à la lumière
|
|
||||||
nebulaLight.SetSpecularColor(NzColor::Orange);
|
|
||||||
|
|
||||||
// Nous appliquons ensuite une rotation de sorte que la lumière dans la même direction que la nébuleuse
|
// Nous appliquons ensuite une rotation de sorte que la lumière dans la même direction que la nébuleuse
|
||||||
nebulaLight.SetRotation(NzEulerAnglesf(0.f, 102.f, 0.f));
|
nebulaLight.SetRotation(NzEulerAnglesf(0.f, 102.f, 0.f));
|
||||||
|
|
|
||||||
|
|
@ -25,26 +25,26 @@ class NAZARA_API NzLight : public NzSceneNode
|
||||||
|
|
||||||
void Enable(const NzShaderProgram* program, unsigned int lightUnit) const;
|
void Enable(const NzShaderProgram* program, unsigned int lightUnit) const;
|
||||||
|
|
||||||
NzColor GetAmbientColor() const;
|
float GetAmbientFactor() const;
|
||||||
float GetAttenuation() const;
|
float GetAttenuation() const;
|
||||||
const NzBoundingVolumef& GetBoundingVolume() const;
|
const NzBoundingVolumef& GetBoundingVolume() const;
|
||||||
NzColor GetDiffuseColor() const;
|
NzColor GetColor() const;
|
||||||
|
float GetDiffuseFactor() const;
|
||||||
float GetInnerAngle() const;
|
float GetInnerAngle() const;
|
||||||
nzLightType GetLightType() const;
|
nzLightType GetLightType() const;
|
||||||
float GetOuterAngle() const;
|
float GetOuterAngle() const;
|
||||||
float GetRadius() const;
|
float GetRadius() const;
|
||||||
nzSceneNodeType GetSceneNodeType() const;
|
nzSceneNodeType GetSceneNodeType() const;
|
||||||
NzColor GetSpecularColor() const;
|
|
||||||
|
|
||||||
bool IsDrawable() const;
|
bool IsDrawable() const;
|
||||||
|
|
||||||
void SetAmbientColor(const NzColor& ambient);
|
void SetAmbientFactor(float factor);
|
||||||
void SetAttenuation(float attenuation);
|
void SetAttenuation(float attenuation);
|
||||||
void SetDiffuseColor(const NzColor& diffuse);
|
void SetColor(const NzColor& color);
|
||||||
|
void SetDiffuseFactor(float factor);
|
||||||
void SetInnerAngle(float innerAngle);
|
void SetInnerAngle(float innerAngle);
|
||||||
void SetOuterAngle(float outerAngle);
|
void SetOuterAngle(float outerAngle);
|
||||||
void SetRadius(float radius);
|
void SetRadius(float radius);
|
||||||
void SetSpecularColor(const NzColor& specular);
|
|
||||||
|
|
||||||
NzLight& operator=(const NzLight& light);
|
NzLight& operator=(const NzLight& light);
|
||||||
|
|
||||||
|
|
@ -59,11 +59,11 @@ class NAZARA_API NzLight : public NzSceneNode
|
||||||
|
|
||||||
nzLightType m_type;
|
nzLightType m_type;
|
||||||
mutable NzBoundingVolumef m_boundingVolume;
|
mutable NzBoundingVolumef m_boundingVolume;
|
||||||
NzColor m_ambientColor;
|
NzColor m_color;
|
||||||
NzColor m_diffuseColor;
|
|
||||||
NzColor m_specularColor;
|
|
||||||
mutable bool m_boundingVolumeUpdated;
|
mutable bool m_boundingVolumeUpdated;
|
||||||
|
float m_ambientFactor;
|
||||||
float m_attenuation;
|
float m_attenuation;
|
||||||
|
float m_diffuseFactor;
|
||||||
float m_innerAngle;
|
float m_innerAngle;
|
||||||
float m_outerAngle;
|
float m_outerAngle;
|
||||||
float m_radius;
|
float m_radius;
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,11 @@
|
||||||
|
|
||||||
NzLight::NzLight(nzLightType type) :
|
NzLight::NzLight(nzLightType type) :
|
||||||
m_type(type),
|
m_type(type),
|
||||||
m_ambientColor((type == nzLightType_Directional) ? NzColor(50, 50, 50) : NzColor::Black),
|
m_color(NzColor::White),
|
||||||
m_diffuseColor(NzColor::White),
|
|
||||||
m_specularColor(NzColor::White),
|
|
||||||
m_boundingVolumeUpdated(false),
|
m_boundingVolumeUpdated(false),
|
||||||
|
m_ambientFactor((type == nzLightType_Directional) ? 0.2f : 0.f),
|
||||||
m_attenuation(0.9f),
|
m_attenuation(0.9f),
|
||||||
|
m_diffuseFactor(1.f),
|
||||||
m_innerAngle(15.f),
|
m_innerAngle(15.f),
|
||||||
m_outerAngle(45.f),
|
m_outerAngle(45.f),
|
||||||
m_radius(5.f)
|
m_radius(5.f)
|
||||||
|
|
@ -45,9 +45,8 @@ void NzLight::Enable(const NzShaderProgram* program, unsigned int lightUnit) con
|
||||||
struct Light
|
struct Light
|
||||||
{
|
{
|
||||||
int type;
|
int type;
|
||||||
vec4 ambient;
|
vec4 color;
|
||||||
vec4 diffuse;
|
vec2 factors;
|
||||||
vec4 specular;
|
|
||||||
|
|
||||||
vec4 parameters1;
|
vec4 parameters1;
|
||||||
vec4 parameters2;
|
vec4 parameters2;
|
||||||
|
|
@ -69,9 +68,8 @@ void NzLight::Enable(const NzShaderProgram* program, unsigned int lightUnit) con
|
||||||
|
|
||||||
///TODO: Optimiser
|
///TODO: Optimiser
|
||||||
int typeLocation = program->GetUniformLocation("Lights[0].type");
|
int typeLocation = program->GetUniformLocation("Lights[0].type");
|
||||||
int ambientLocation = program->GetUniformLocation("Lights[0].ambient");
|
int colorLocation = program->GetUniformLocation("Lights[0].color");
|
||||||
int diffuseLocation = program->GetUniformLocation("Lights[0].diffuse");
|
int factorsLocation = program->GetUniformLocation("Lights[0].factors");
|
||||||
int specularLocation = program->GetUniformLocation("Lights[0].specular");
|
|
||||||
int parameters1Location = program->GetUniformLocation("Lights[0].parameters1");
|
int parameters1Location = program->GetUniformLocation("Lights[0].parameters1");
|
||||||
int parameters2Location = program->GetUniformLocation("Lights[0].parameters2");
|
int parameters2Location = program->GetUniformLocation("Lights[0].parameters2");
|
||||||
int parameters3Location = program->GetUniformLocation("Lights[0].parameters3");
|
int parameters3Location = program->GetUniformLocation("Lights[0].parameters3");
|
||||||
|
|
@ -83,18 +81,16 @@ void NzLight::Enable(const NzShaderProgram* program, unsigned int lightUnit) con
|
||||||
|
|
||||||
// On applique cet offset
|
// On applique cet offset
|
||||||
typeLocation += offset;
|
typeLocation += offset;
|
||||||
ambientLocation += offset;
|
colorLocation += offset;
|
||||||
diffuseLocation += offset;
|
factorsLocation += offset;
|
||||||
specularLocation += offset;
|
|
||||||
parameters1Location += offset;
|
parameters1Location += offset;
|
||||||
parameters2Location += offset;
|
parameters2Location += offset;
|
||||||
parameters3Location += offset;
|
parameters3Location += offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
program->SendInteger(typeLocation, m_type);
|
program->SendInteger(typeLocation, m_type);
|
||||||
program->SendColor(ambientLocation, m_ambientColor);
|
program->SendColor(colorLocation, m_color);
|
||||||
program->SendColor(diffuseLocation, m_diffuseColor);
|
program->SendVector(factorsLocation, NzVector2f(m_ambientFactor, m_diffuseFactor));
|
||||||
program->SendColor(specularLocation, m_specularColor);
|
|
||||||
|
|
||||||
if (!m_derivedUpdated)
|
if (!m_derivedUpdated)
|
||||||
UpdateDerived();
|
UpdateDerived();
|
||||||
|
|
@ -118,6 +114,16 @@ void NzLight::Enable(const NzShaderProgram* program, unsigned int lightUnit) con
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float NzLight::GetAmbientFactor() const
|
||||||
|
{
|
||||||
|
return m_ambientFactor;
|
||||||
|
}
|
||||||
|
|
||||||
|
float NzLight::GetAttenuation() const
|
||||||
|
{
|
||||||
|
return m_attenuation;
|
||||||
|
}
|
||||||
|
|
||||||
const NzBoundingVolumef& NzLight::GetBoundingVolume() const
|
const NzBoundingVolumef& NzLight::GetBoundingVolume() const
|
||||||
{
|
{
|
||||||
if (!m_boundingVolumeUpdated)
|
if (!m_boundingVolumeUpdated)
|
||||||
|
|
@ -126,19 +132,14 @@ const NzBoundingVolumef& NzLight::GetBoundingVolume() const
|
||||||
return m_boundingVolume;
|
return m_boundingVolume;
|
||||||
}
|
}
|
||||||
|
|
||||||
NzColor NzLight::GetAmbientColor() const
|
NzColor NzLight::GetColor() const
|
||||||
{
|
{
|
||||||
return m_ambientColor;
|
return m_color;
|
||||||
}
|
}
|
||||||
|
|
||||||
float NzLight::GetAttenuation() const
|
float NzLight::GetDiffuseFactor() const
|
||||||
{
|
{
|
||||||
return m_attenuation;
|
return m_diffuseFactor;
|
||||||
}
|
|
||||||
|
|
||||||
NzColor NzLight::GetDiffuseColor() const
|
|
||||||
{
|
|
||||||
return m_diffuseColor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float NzLight::GetInnerAngle() const
|
float NzLight::GetInnerAngle() const
|
||||||
|
|
@ -166,19 +167,14 @@ nzSceneNodeType NzLight::GetSceneNodeType() const
|
||||||
return nzSceneNodeType_Light;
|
return nzSceneNodeType_Light;
|
||||||
}
|
}
|
||||||
|
|
||||||
NzColor NzLight::GetSpecularColor() const
|
|
||||||
{
|
|
||||||
return m_specularColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool NzLight::IsDrawable() const
|
bool NzLight::IsDrawable() const
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzLight::SetAmbientColor(const NzColor& ambient)
|
void NzLight::SetAmbientFactor(float factor)
|
||||||
{
|
{
|
||||||
m_ambientColor = ambient;
|
m_ambientFactor = factor;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzLight::SetAttenuation(float attenuation)
|
void NzLight::SetAttenuation(float attenuation)
|
||||||
|
|
@ -186,9 +182,14 @@ void NzLight::SetAttenuation(float attenuation)
|
||||||
m_attenuation = attenuation;
|
m_attenuation = attenuation;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzLight::SetDiffuseColor(const NzColor& diffuse)
|
void NzLight::SetColor(const NzColor& color)
|
||||||
{
|
{
|
||||||
m_diffuseColor = diffuse;
|
m_color = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NzLight::SetDiffuseFactor(float factor)
|
||||||
|
{
|
||||||
|
m_diffuseFactor = factor;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzLight::SetInnerAngle(float innerAngle)
|
void NzLight::SetInnerAngle(float innerAngle)
|
||||||
|
|
@ -212,11 +213,6 @@ void NzLight::SetRadius(float radius)
|
||||||
m_boundingVolumeUpdated = false;
|
m_boundingVolumeUpdated = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzLight::SetSpecularColor(const NzColor& specular)
|
|
||||||
{
|
|
||||||
m_specularColor = specular;
|
|
||||||
}
|
|
||||||
|
|
||||||
NzLight& NzLight::operator=(const NzLight& light)
|
NzLight& NzLight::operator=(const NzLight& light)
|
||||||
{
|
{
|
||||||
std::memcpy(this, &light, sizeof(NzLight));
|
std::memcpy(this, &light, sizeof(NzLight));
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,8 @@ varying vec3 vWorldPos;
|
||||||
struct Light
|
struct Light
|
||||||
{
|
{
|
||||||
int type;
|
int type;
|
||||||
vec4 ambient;
|
vec4 color;
|
||||||
vec4 diffuse;
|
vec2 factors;
|
||||||
vec4 specular;
|
|
||||||
|
|
||||||
vec4 parameters1;
|
vec4 parameters1;
|
||||||
vec4 parameters2;
|
vec4 parameters2;
|
||||||
|
|
@ -44,29 +43,27 @@ uniform vec4 SceneAmbient;
|
||||||
/********************Fonctions********************/
|
/********************Fonctions********************/
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 fragmentColor = MaterialDiffuse;
|
vec4 diffuseColor = MaterialDiffuse;
|
||||||
#if DIFFUSE_MAPPING
|
#if DIFFUSE_MAPPING
|
||||||
fragmentColor *= texture2D(MaterialDiffuseMap, vTexCoord);
|
diffuseColor *= texture(MaterialDiffuseMap, vTexCoord);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ALPHA_MAPPING
|
#if ALPHA_MAPPING
|
||||||
fragmentColor.a *= texture2D(MaterialAlphaMap, vTexCoord).r;
|
diffuseColor.a *= texture(MaterialAlphaMap, vTexCoord).r;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ALPHA_TEST
|
#if ALPHA_TEST
|
||||||
if (fragmentColor.a < MaterialAlphaThreshold)
|
if (diffuseColor.a < MaterialAlphaThreshold)
|
||||||
discard;
|
discard;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if LIGHTING
|
#if LIGHTING
|
||||||
vec3 lightColor = vec3(0.0);
|
vec3 lightAmbient = vec3(0.0);
|
||||||
|
vec3 lightDiffuse = vec3(0.0);
|
||||||
#if SPECULAR_MAPPING
|
vec3 lightSpecular = vec3(0.0);
|
||||||
vec3 specularColor = vec3(0.0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if NORMAL_MAPPING
|
#if NORMAL_MAPPING
|
||||||
vec3 normal = normalize(vLightToWorld * (2.0 * vec3(texture2D(MaterialNormalMap, vTexCoord)) - 1.0));
|
vec3 normal = normalize(vLightToWorld * (2.0 * vec3(texture(MaterialNormalMap, vTexCoord)) - 1.0));
|
||||||
#else
|
#else
|
||||||
vec3 normal = normalize(vNormal);
|
vec3 normal = normalize(vNormal);
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -79,76 +76,74 @@ void main()
|
||||||
{
|
{
|
||||||
if (Lights[i].type == LIGHT_DIRECTIONAL)
|
if (Lights[i].type == LIGHT_DIRECTIONAL)
|
||||||
{
|
{
|
||||||
vec3 lightDir = normalize(-Lights[i].parameters1.xyz);
|
vec3 lightDir = -Lights[i].parameters1.xyz;
|
||||||
|
|
||||||
// Ambient
|
// Ambient
|
||||||
lightColor += Lights[i].ambient.rgb * (MaterialAmbient.rgb + SceneAmbient.rgb);
|
lightAmbient += Lights[i].color.rgb * Lights[i].factors.x;
|
||||||
|
|
||||||
// Diffuse
|
// Diffuse
|
||||||
float lambert = max(dot(normal, lightDir), 0.0);
|
float lambert = max(dot(normal, lightDir), 0.0);
|
||||||
lightColor += lambert * Lights[i].diffuse.rgb * MaterialDiffuse.rgb;
|
|
||||||
|
lightDiffuse += lambert * Lights[i].color.rgb * Lights[i].factors.y;
|
||||||
|
|
||||||
// Specular
|
// Specular
|
||||||
vec3 reflection = reflect(-lightDir, normal);
|
vec3 reflection = reflect(-lightDir, normal);
|
||||||
float specular = pow(max(dot(reflection, eyeVec), 0.0), MaterialShininess);
|
float specularFactor = max(dot(reflection, eyeVec), 0.0);
|
||||||
|
specularFactor = pow(specularFactor, MaterialShininess);
|
||||||
|
|
||||||
#if SPECULAR_MAPPING
|
lightSpecular += specularFactor * Lights[i].color.rgb;
|
||||||
specularColor += specular * Lights[i].specular.rgb * MaterialSpecular.rgb;
|
|
||||||
#else
|
|
||||||
lightColor += specular * Lights[i].specular.rgb * MaterialSpecular.rgb;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else if (Lights[i].type == LIGHT_POINT)
|
else if (Lights[i].type == LIGHT_POINT)
|
||||||
{
|
{
|
||||||
vec3 lightDir = Lights[i].parameters1.xyz - vWorldPos;
|
vec3 lightDir = Lights[i].parameters1.xyz - vWorldPos;
|
||||||
float att = max(Lights[i].parameters1.w - Lights[i].parameters2.x*length(lightDir), 0.0);
|
float lightDirLength = length(lightDir);
|
||||||
lightDir = normalize(lightDir);
|
lightDir /= lightDirLength; // Normalisation
|
||||||
|
|
||||||
|
float att = max(Lights[i].parameters1.w - Lights[i].parameters2.x*lightDirLength, 0.0);
|
||||||
|
|
||||||
// Ambient
|
// Ambient
|
||||||
lightColor += att * Lights[i].ambient.rgb * (MaterialAmbient.rgb + SceneAmbient.rgb);
|
lightAmbient += att * Lights[i].color.rgb * Lights[i].factors.x;
|
||||||
|
|
||||||
// Diffuse
|
// Diffuse
|
||||||
float lambert = max(dot(normal, lightDir), 0.0);
|
float lambert = max(dot(normal, lightDir), 0.0);
|
||||||
lightColor += att * lambert * Lights[i].diffuse.rgb * MaterialDiffuse.rgb;
|
|
||||||
|
lightDiffuse += att * lambert * Lights[i].color.rgb * Lights[i].factors.y;
|
||||||
|
|
||||||
// Specular
|
// Specular
|
||||||
vec3 reflection = reflect(-lightDir, normal);
|
vec3 reflection = reflect(-lightDir, normal);
|
||||||
float specular = pow(max(dot(reflection, eyeVec), 0.0), MaterialShininess);
|
float specularFactor = max(dot(reflection, eyeVec), 0.0);
|
||||||
|
specularFactor = pow(specularFactor, MaterialShininess);
|
||||||
|
|
||||||
#if SPECULAR_MAPPING
|
lightSpecular += att * specularFactor * Lights[i].color.rgb;
|
||||||
specularColor += att * specular * Lights[i].specular.rgb * MaterialSpecular.rgb;
|
|
||||||
#else
|
|
||||||
lightColor += att * specular * Lights[i].specular.rgb * MaterialSpecular.rgb;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else if (Lights[i].type == LIGHT_SPOT)
|
else if (Lights[i].type == LIGHT_SPOT)
|
||||||
{
|
{
|
||||||
vec3 lightDir = Lights[i].parameters1.xyz - vWorldPos;
|
vec3 lightDir = Lights[i].parameters1.xyz - vWorldPos;
|
||||||
float att = max(Lights[i].parameters1.w - Lights[i].parameters2.x*length(lightDir), 0.0);
|
float lightDirLength = length(lightDir);
|
||||||
lightDir = normalize(lightDir);
|
lightDir /= lightDirLength; // Normalisation
|
||||||
|
|
||||||
|
float att = max(Lights[i].parameters1.w - Lights[i].parameters2.x*lightDirLength, 0.0);
|
||||||
|
|
||||||
// Ambient
|
// Ambient
|
||||||
lightColor += att * Lights[i].ambient.rgb * (MaterialAmbient.rgb + SceneAmbient.rgb);
|
lightAmbient += att * Lights[i].color.rgb * Lights[i].factors.x;
|
||||||
|
|
||||||
// Modification de l'atténuation
|
// Diffuse
|
||||||
|
float lambert = max(dot(normal, lightDir), 0.0);
|
||||||
|
|
||||||
|
// Modification de l'atténuation pour gérer le spot
|
||||||
float curAngle = dot(Lights[i].parameters2.xyz, -lightDir);
|
float curAngle = dot(Lights[i].parameters2.xyz, -lightDir);
|
||||||
float outerAngle = Lights[i].parameters3.y;
|
float outerAngle = Lights[i].parameters3.y;
|
||||||
float innerMinusOuterAngle = Lights[i].parameters3.x - outerAngle;
|
float innerMinusOuterAngle = Lights[i].parameters3.x - outerAngle;
|
||||||
float lambert = max(dot(normal, lightDir), 0.0);
|
|
||||||
att *= max((curAngle - outerAngle) / innerMinusOuterAngle, 0.0);
|
att *= max((curAngle - outerAngle) / innerMinusOuterAngle, 0.0);
|
||||||
|
|
||||||
// Diffuse
|
lightDiffuse += att * lambert * Lights[i].color.rgb * Lights[i].factors.y;
|
||||||
lightColor += att * lambert * Lights[i].diffuse.rgb * MaterialDiffuse.rgb;
|
|
||||||
|
|
||||||
// Specular
|
// Specular
|
||||||
vec3 reflection = reflect(-lightDir, normal);
|
vec3 reflection = reflect(-lightDir, normal);
|
||||||
float specular = pow(max(dot(reflection, eyeVec), 0.0), MaterialShininess);
|
float specularFactor = max(dot(reflection, eyeVec), 0.0);
|
||||||
|
specularFactor = pow(specularFactor, MaterialShininess);
|
||||||
|
|
||||||
#if SPECULAR_MAPPING
|
lightSpecular += att * specularFactor * Lights[i].color.rgb;
|
||||||
specularColor += att * specular * Lights[i].specular.rgb * MaterialSpecular.rgb;
|
|
||||||
#else
|
|
||||||
lightColor += att * specular * Lights[i].specular.rgb * MaterialSpecular.rgb;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -158,68 +153,75 @@ void main()
|
||||||
{
|
{
|
||||||
if (Lights[i].type == LIGHT_DIRECTIONAL)
|
if (Lights[i].type == LIGHT_DIRECTIONAL)
|
||||||
{
|
{
|
||||||
vec3 lightDir = normalize(-Lights[i].parameters1.xyz);
|
vec3 lightDir = -Lights[i].parameters1.xyz;
|
||||||
|
|
||||||
// Ambient
|
// Ambient
|
||||||
lightColor += Lights[i].ambient.rgb * (MaterialAmbient.rgb + SceneAmbient.rgb);
|
lightAmbient += Lights[i].color.rgb * Lights[i].factors.x;
|
||||||
|
|
||||||
// Diffuse
|
// Diffuse
|
||||||
float lambert = max(dot(normal, lightDir), 0.0);
|
float lambert = max(dot(normal, lightDir), 0.0);
|
||||||
lightColor += lambert * Lights[i].diffuse.rgb * MaterialDiffuse.rgb;
|
|
||||||
|
lightDiffuse += lambert * Lights[i].color.rgb * Lights[i].factors.y;
|
||||||
}
|
}
|
||||||
else if (Lights[i].type == LIGHT_POINT)
|
else if (Lights[i].type == LIGHT_POINT)
|
||||||
{
|
{
|
||||||
vec3 lightDir = Lights[i].parameters1.xyz - vWorldPos;
|
vec3 lightDir = Lights[i].parameters1.xyz - vWorldPos;
|
||||||
float att = max(Lights[i].parameters1.w - Lights[i].parameters2.x*length(lightDir), 0.0);
|
float lightDirLength = length(lightDir);
|
||||||
lightDir = normalize(lightDir);
|
lightDir /= lightDirLength; // Normalisation
|
||||||
|
|
||||||
|
float att = max(Lights[i].parameters1.w - Lights[i].parameters2.x*lightDirLength, 0.0);
|
||||||
|
|
||||||
// Ambient
|
// Ambient
|
||||||
lightColor += att * Lights[i].ambient.rgb * (MaterialAmbient.rgb + SceneAmbient.rgb);
|
lightAmbient += att * Lights[i].color.rgb * Lights[i].factors.x;
|
||||||
|
|
||||||
// Diffuse
|
// Diffuse
|
||||||
float lambert = max(dot(normal, lightDir), 0.0);
|
float lambert = max(dot(normal, lightDir), 0.0);
|
||||||
lightColor += att * lambert * Lights[i].diffuse.rgb * MaterialDiffuse.rgb;
|
|
||||||
|
lightDiffuse += att * lambert * Lights[i].color.rgb * Lights[i].factors.y;
|
||||||
}
|
}
|
||||||
else if (Lights[i].type == LIGHT_SPOT)
|
else if (Lights[i].type == LIGHT_SPOT)
|
||||||
{
|
{
|
||||||
vec3 lightDir = Lights[i].parameters1.xyz - vWorldPos;
|
vec3 lightDir = Lights[i].parameters1.xyz - vWorldPos;
|
||||||
float att = max(Lights[i].parameters1.w - Lights[i].parameters2.x*length(lightDir), 0.0);
|
float lightDirLength = length(lightDir);
|
||||||
lightDir = normalize(lightDir);
|
lightDir /= lightDirLength; // Normalisation
|
||||||
|
|
||||||
|
float att = max(Lights[i].parameters1.w - Lights[i].parameters2.x*lightDirLength, 0.0);
|
||||||
|
|
||||||
// Ambient
|
// Ambient
|
||||||
lightColor += att * Lights[i].ambient.rgb * (MaterialAmbient.rgb + SceneAmbient.rgb);
|
lightAmbient += att * Lights[i].color.rgb * Lights[i].factors.x;
|
||||||
|
|
||||||
// Modification de l'atténuation
|
// Diffuse
|
||||||
|
float lambert = max(dot(normal, lightDir), 0.0);
|
||||||
|
|
||||||
|
// Modification de l'atténuation pour gérer le spot
|
||||||
float curAngle = dot(Lights[i].parameters2.xyz, -lightDir);
|
float curAngle = dot(Lights[i].parameters2.xyz, -lightDir);
|
||||||
float outerAngle = Lights[i].parameters3.y;
|
float outerAngle = Lights[i].parameters3.y;
|
||||||
float innerMinusOuterAngle = Lights[i].parameters3.x - outerAngle;
|
float innerMinusOuterAngle = Lights[i].parameters3.x - outerAngle;
|
||||||
float lambert = max(dot(normal, lightDir), 0.0);
|
|
||||||
att *= max((curAngle - outerAngle) / innerMinusOuterAngle, 0.0);
|
att *= max((curAngle - outerAngle) / innerMinusOuterAngle, 0.0);
|
||||||
|
|
||||||
// Diffuse
|
lightDiffuse += att * lambert * Lights[i].color.rgb * Lights[i].factors.y;
|
||||||
lightColor += att * lambert * Lights[i].diffuse.rgb * MaterialDiffuse.rgb;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fragmentColor *= vec4(lightColor, 1.0);
|
lightAmbient = (lightAmbient + SceneAmbient.rgb)*MaterialAmbient.rgb;
|
||||||
|
lightSpecular *= MaterialSpecular.rgb;
|
||||||
#if SPECULAR_MAPPING
|
#if SPECULAR_MAPPING
|
||||||
fragmentColor *= vec4(specularColor * texture2D(MaterialSpecularMap, vTexCoord).rgb, 1.0); // Utiliser l'alpha de MaterialSpecular n'aurait aucun sens
|
lightSpecular *= texture(MaterialSpecularMap, vTexCoord).rgb; // Utiliser l'alpha de MaterialSpecular n'aurait aucun sens
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
vec3 lightColor = (lightAmbient + lightDiffuse + lightSpecular);
|
||||||
|
vec4 fragmentColor = vec4(lightColor, 1.0) * diffuseColor;
|
||||||
|
|
||||||
#if EMISSIVE_MAPPING
|
#if EMISSIVE_MAPPING
|
||||||
#if SPECULAR_MAPPING
|
|
||||||
float lightIntensity = dot(lightColor + specularColor, vec3(0.3, 0.59, 0.11));
|
|
||||||
#else
|
|
||||||
float lightIntensity = dot(lightColor, vec3(0.3, 0.59, 0.11));
|
float lightIntensity = dot(lightColor, vec3(0.3, 0.59, 0.11));
|
||||||
#endif // SPECULAR_MAPPING
|
|
||||||
|
|
||||||
vec3 emissionColor = MaterialDiffuse.rgb * texture2D(MaterialEmissiveMap, vTexCoord).rgb;
|
vec3 emissionColor = MaterialDiffuse.rgb * texture(MaterialEmissiveMap, vTexCoord).rgb;
|
||||||
gl_FragColor = vec4(mix(fragmentColor.rgb, emissionColor, clamp(1.0 - 3.0*lightIntensity, 0.0, 1.0)), fragmentColor.a);
|
RenderTarget0 = vec4(mix(fragmentColor.rgb, emissionColor, clamp(1.0 - 3.0*lightIntensity, 0.0, 1.0)), fragmentColor.a);
|
||||||
#else
|
#else
|
||||||
gl_FragColor = fragmentColor;
|
RenderTarget0 = fragmentColor;
|
||||||
#endif // EMISSIVE_MAPPING
|
#endif // EMISSIVE_MAPPING
|
||||||
#else
|
#else
|
||||||
gl_FragColor = fragmentColor;
|
RenderTarget0 = diffuseColor;
|
||||||
#endif // LIGHTING
|
#endif // LIGHTING
|
||||||
}
|
}
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -17,9 +17,8 @@ out vec4 RenderTarget2;
|
||||||
struct Light
|
struct Light
|
||||||
{
|
{
|
||||||
int type;
|
int type;
|
||||||
vec4 ambient;
|
vec4 color;
|
||||||
vec4 diffuse;
|
vec2 factors;
|
||||||
vec4 specular;
|
|
||||||
|
|
||||||
vec4 parameters1;
|
vec4 parameters1;
|
||||||
vec4 parameters2;
|
vec4 parameters2;
|
||||||
|
|
@ -45,18 +44,18 @@ uniform vec4 SceneAmbient;
|
||||||
/********************Fonctions********************/
|
/********************Fonctions********************/
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 fragmentColor = MaterialDiffuse;
|
vec4 diffuseColor = MaterialDiffuse;
|
||||||
#if DIFFUSE_MAPPING
|
#if DIFFUSE_MAPPING
|
||||||
fragmentColor *= texture(MaterialDiffuseMap, vTexCoord);
|
diffuseColor *= texture(MaterialDiffuseMap, vTexCoord);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if FLAG_DEFERRED
|
#if FLAG_DEFERRED
|
||||||
#if ALPHA_TEST
|
#if ALPHA_TEST
|
||||||
#if ALPHA_MAPPING // Inutile de faire de l'alpha-mapping sans alpha-test en Deferred (l'alpha n'est pas sauvegardé)
|
#if ALPHA_MAPPING // Inutile de faire de l'alpha-mapping sans alpha-test en Deferred (l'alpha n'est pas sauvegardé)
|
||||||
fragmentColor.a *= texture(MaterialAlphaMap, vTexCoord).r;
|
diffuseColor.a *= texture(MaterialAlphaMap, vTexCoord).r;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (fragmentColor.a < MaterialAlphaThreshold)
|
if (diffuseColor.a < MaterialAlphaThreshold)
|
||||||
discard;
|
discard;
|
||||||
#endif // ALPHA_TEST
|
#endif // ALPHA_TEST
|
||||||
|
|
||||||
|
|
@ -67,39 +66,37 @@ void main()
|
||||||
vec3 normal = normalize(vNormal);
|
vec3 normal = normalize(vNormal);
|
||||||
#endif // NORMAL_MAPPING
|
#endif // NORMAL_MAPPING
|
||||||
|
|
||||||
vec3 specular = MaterialSpecular.rgb;
|
vec3 specularColor = MaterialSpecular.rgb;
|
||||||
#if SPECULAR_MAPPING
|
#if SPECULAR_MAPPING
|
||||||
specular *= texture(MaterialSpecularMap, vTexCoord).rgb;
|
specularColor *= texture(MaterialSpecularMap, vTexCoord).rgb;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Texture0: Diffuse Color + Flags
|
Texture0: Diffuse Color + Flags
|
||||||
Texture1: Normal map + Empty
|
Texture1: Normal map + Empty
|
||||||
Texture2: Specular value + Shininess
|
Texture2: Specular color + Shininess
|
||||||
Texture3: Depth texture
|
Texture3: Depth texture
|
||||||
*/
|
*/
|
||||||
RenderTarget0 = vec4(fragmentColor.rgb, 1.0);
|
RenderTarget0 = vec4(diffuseColor.rgb, 1.0);
|
||||||
RenderTarget1 = vec4(normal, 0.0);
|
RenderTarget1 = vec4(normal*0.5 + 0.5, 0.0);
|
||||||
RenderTarget2 = vec4(specular, MaterialShininess);
|
RenderTarget2 = vec4(specularColor, MaterialShininess);
|
||||||
#else // LIGHTING
|
#else // LIGHTING
|
||||||
RenderTarget0 = vec4(fragmentColor.rgb, 0.0);
|
RenderTarget0 = vec4(diffuseColor.rgb, 0.0);
|
||||||
#endif
|
#endif
|
||||||
#else // FLAG_DEFERRED
|
#else // FLAG_DEFERRED
|
||||||
#if ALPHA_MAPPING
|
#if ALPHA_MAPPING
|
||||||
fragmentColor.a *= texture(MaterialAlphaMap, vTexCoord).r;
|
diffuseColor.a *= texture(MaterialAlphaMap, vTexCoord).r;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ALPHA_TEST
|
#if ALPHA_TEST
|
||||||
if (fragmentColor.a < MaterialAlphaThreshold)
|
if (diffuseColor.a < MaterialAlphaThreshold)
|
||||||
discard;
|
discard;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if LIGHTING
|
#if LIGHTING
|
||||||
vec3 lightColor = vec3(0.0);
|
vec3 lightAmbient = vec3(0.0);
|
||||||
|
vec3 lightDiffuse = vec3(0.0);
|
||||||
#if SPECULAR_MAPPING
|
vec3 lightSpecular = vec3(0.0);
|
||||||
vec3 specularColor = vec3(0.0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if NORMAL_MAPPING
|
#if NORMAL_MAPPING
|
||||||
vec3 normal = normalize(vLightToWorld * (2.0 * vec3(texture(MaterialNormalMap, vTexCoord)) - 1.0));
|
vec3 normal = normalize(vLightToWorld * (2.0 * vec3(texture(MaterialNormalMap, vTexCoord)) - 1.0));
|
||||||
|
|
@ -117,80 +114,78 @@ void main()
|
||||||
{
|
{
|
||||||
case LIGHT_DIRECTIONAL:
|
case LIGHT_DIRECTIONAL:
|
||||||
{
|
{
|
||||||
vec3 lightDir = normalize(-Lights[i].parameters1.xyz);
|
vec3 lightDir = -Lights[i].parameters1.xyz;
|
||||||
|
|
||||||
// Ambient
|
// Ambient
|
||||||
lightColor += Lights[i].ambient.rgb * (MaterialAmbient.rgb + SceneAmbient.rgb);
|
lightAmbient += Lights[i].color.rgb * Lights[i].factors.x;
|
||||||
|
|
||||||
// Diffuse
|
// Diffuse
|
||||||
float lambert = max(dot(normal, lightDir), 0.0);
|
float lambert = max(dot(normal, lightDir), 0.0);
|
||||||
lightColor += lambert * Lights[i].diffuse.rgb * MaterialDiffuse.rgb;
|
|
||||||
|
lightDiffuse += lambert * Lights[i].color.rgb * Lights[i].factors.y;
|
||||||
|
|
||||||
// Specular
|
// Specular
|
||||||
vec3 reflection = reflect(-lightDir, normal);
|
vec3 reflection = reflect(-lightDir, normal);
|
||||||
float specular = pow(max(dot(reflection, eyeVec), 0.0), MaterialShininess);
|
float specularFactor = max(dot(reflection, eyeVec), 0.0);
|
||||||
|
specularFactor = pow(specularFactor, MaterialShininess);
|
||||||
|
|
||||||
#if SPECULAR_MAPPING
|
lightSpecular += specularFactor * Lights[i].color.rgb;
|
||||||
specularColor += specular * Lights[i].specular.rgb * MaterialSpecular.rgb;
|
|
||||||
#else
|
|
||||||
lightColor += specular * Lights[i].specular.rgb * MaterialSpecular.rgb;
|
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case LIGHT_POINT:
|
case LIGHT_POINT:
|
||||||
{
|
{
|
||||||
vec3 lightDir = Lights[i].parameters1.xyz - vWorldPos;
|
vec3 lightDir = Lights[i].parameters1.xyz - vWorldPos;
|
||||||
float att = max(Lights[i].parameters1.w - Lights[i].parameters2.x*length(lightDir), 0.0);
|
float lightDirLength = length(lightDir);
|
||||||
lightDir = normalize(lightDir);
|
lightDir /= lightDirLength; // Normalisation
|
||||||
|
|
||||||
|
float att = max(Lights[i].parameters1.w - Lights[i].parameters2.x*lightDirLength, 0.0);
|
||||||
|
|
||||||
// Ambient
|
// Ambient
|
||||||
lightColor += att * Lights[i].ambient.rgb * (MaterialAmbient.rgb + SceneAmbient.rgb);
|
lightAmbient += att * Lights[i].color.rgb * Lights[i].factors.x;
|
||||||
|
|
||||||
// Diffuse
|
// Diffuse
|
||||||
float lambert = max(dot(normal, lightDir), 0.0);
|
float lambert = max(dot(normal, lightDir), 0.0);
|
||||||
lightColor += att * lambert * Lights[i].diffuse.rgb * MaterialDiffuse.rgb;
|
|
||||||
|
lightDiffuse += att * lambert * Lights[i].color.rgb * Lights[i].factors.y;
|
||||||
|
|
||||||
// Specular
|
// Specular
|
||||||
vec3 reflection = reflect(-lightDir, normal);
|
vec3 reflection = reflect(-lightDir, normal);
|
||||||
float specular = pow(max(dot(reflection, eyeVec), 0.0), MaterialShininess);
|
float specularFactor = max(dot(reflection, eyeVec), 0.0);
|
||||||
|
specularFactor = pow(specularFactor, MaterialShininess);
|
||||||
|
|
||||||
#if SPECULAR_MAPPING
|
lightSpecular += att * specularFactor * Lights[i].color.rgb;
|
||||||
specularColor += att * specular * Lights[i].specular.rgb * MaterialSpecular.rgb;
|
|
||||||
#else
|
|
||||||
lightColor += att * specular * Lights[i].specular.rgb * MaterialSpecular.rgb;
|
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case LIGHT_SPOT:
|
case LIGHT_SPOT:
|
||||||
{
|
{
|
||||||
vec3 lightDir = Lights[i].parameters1.xyz - vWorldPos;
|
vec3 lightDir = Lights[i].parameters1.xyz - vWorldPos;
|
||||||
float att = max(Lights[i].parameters1.w - Lights[i].parameters2.x*length(lightDir), 0.0);
|
float lightDirLength = length(lightDir);
|
||||||
lightDir = normalize(lightDir);
|
lightDir /= lightDirLength; // Normalisation
|
||||||
|
|
||||||
|
float att = max(Lights[i].parameters1.w - Lights[i].parameters2.x*lightDirLength, 0.0);
|
||||||
|
|
||||||
// Ambient
|
// Ambient
|
||||||
lightColor += att * Lights[i].ambient.rgb * (MaterialAmbient.rgb + SceneAmbient.rgb);
|
lightAmbient += att * Lights[i].color.rgb * Lights[i].factors.x;
|
||||||
|
|
||||||
// Modification de l'atténuation
|
// Diffuse
|
||||||
|
float lambert = max(dot(normal, lightDir), 0.0);
|
||||||
|
|
||||||
|
// Modification de l'atténuation pour gérer le spot
|
||||||
float curAngle = dot(Lights[i].parameters2.xyz, -lightDir);
|
float curAngle = dot(Lights[i].parameters2.xyz, -lightDir);
|
||||||
float outerAngle = Lights[i].parameters3.y;
|
float outerAngle = Lights[i].parameters3.y;
|
||||||
float innerMinusOuterAngle = Lights[i].parameters3.x - outerAngle;
|
float innerMinusOuterAngle = Lights[i].parameters3.x - outerAngle;
|
||||||
float lambert = max(dot(normal, lightDir), 0.0);
|
|
||||||
att *= max((curAngle - outerAngle) / innerMinusOuterAngle, 0.0);
|
att *= max((curAngle - outerAngle) / innerMinusOuterAngle, 0.0);
|
||||||
|
|
||||||
// Diffuse
|
lightDiffuse += att * lambert * Lights[i].color.rgb * Lights[i].factors.y;
|
||||||
lightColor += att * lambert * Lights[i].diffuse.rgb * MaterialDiffuse.rgb;
|
|
||||||
|
|
||||||
// Specular
|
// Specular
|
||||||
vec3 reflection = reflect(-lightDir, normal);
|
vec3 reflection = reflect(-lightDir, normal);
|
||||||
float specular = pow(max(dot(reflection, eyeVec), 0.0), MaterialShininess);
|
float specularFactor = max(dot(reflection, eyeVec), 0.0);
|
||||||
|
specularFactor = pow(specularFactor, MaterialShininess);
|
||||||
|
|
||||||
#if SPECULAR_MAPPING
|
lightSpecular += att * specularFactor * Lights[i].color.rgb;
|
||||||
specularColor += att * specular * Lights[i].specular.rgb * MaterialSpecular.rgb;
|
|
||||||
#else
|
|
||||||
lightColor += att * specular * Lights[i].specular.rgb * MaterialSpecular.rgb;
|
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -208,50 +203,56 @@ void main()
|
||||||
case LIGHT_DIRECTIONAL:
|
case LIGHT_DIRECTIONAL:
|
||||||
{
|
{
|
||||||
vec3 lightDir = normalize(-Lights[i].parameters1.xyz);
|
vec3 lightDir = normalize(-Lights[i].parameters1.xyz);
|
||||||
|
|
||||||
// Ambient
|
// Ambient
|
||||||
lightColor += Lights[i].ambient.rgb * (MaterialAmbient.rgb + SceneAmbient.rgb);
|
lightAmbient += Lights[i].color.rgb * Lights[i].factors.x;
|
||||||
|
|
||||||
// Diffuse
|
// Diffuse
|
||||||
float lambert = max(dot(normal, lightDir), 0.0);
|
float lambert = max(dot(normal, lightDir), 0.0);
|
||||||
lightColor += lambert * Lights[i].diffuse.rgb * MaterialDiffuse.rgb;
|
|
||||||
|
lightDiffuse += lambert * Lights[i].color.rgb * Lights[i].factors.y;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case LIGHT_POINT:
|
case LIGHT_POINT:
|
||||||
{
|
{
|
||||||
vec3 lightDir = Lights[i].parameters1.xyz - vWorldPos;
|
vec3 lightDir = Lights[i].parameters1.xyz - vWorldPos;
|
||||||
float att = max(Lights[i].parameters1.w - Lights[i].parameters2.x*length(lightDir), 0.0);
|
float lightDirLength = length(lightDir);
|
||||||
lightDir = normalize(lightDir);
|
lightDir /= lightDirLength; // Normalisation
|
||||||
|
|
||||||
|
float att = max(Lights[i].parameters1.w - Lights[i].parameters2.x*lightDirLength, 0.0);
|
||||||
|
|
||||||
// Ambient
|
// Ambient
|
||||||
lightColor += att * Lights[i].ambient.rgb * (MaterialAmbient.rgb + SceneAmbient.rgb);
|
lightAmbient += att * Lights[i].color.rgb * Lights[i].factors.x;
|
||||||
|
|
||||||
// Diffuse
|
// Diffuse
|
||||||
float lambert = max(dot(normal, lightDir), 0.0);
|
float lambert = max(dot(normal, lightDir), 0.0);
|
||||||
lightColor += att * lambert * Lights[i].diffuse.rgb * MaterialDiffuse.rgb;
|
|
||||||
|
lightDiffuse += att * lambert * Lights[i].color.rgb * Lights[i].factors.y;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case LIGHT_SPOT:
|
case LIGHT_SPOT:
|
||||||
{
|
{
|
||||||
vec3 lightDir = Lights[i].parameters1.xyz - vWorldPos;
|
vec3 lightDir = Lights[i].parameters1.xyz - vWorldPos;
|
||||||
float att = max(Lights[i].parameters1.w - Lights[i].parameters2.x*length(lightDir), 0.0);
|
float lightDirLength = length(lightDir);
|
||||||
lightDir = normalize(lightDir);
|
lightDir /= lightDirLength; // Normalisation
|
||||||
|
|
||||||
|
float att = max(Lights[i].parameters1.w - Lights[i].parameters2.x*lightDirLength, 0.0);
|
||||||
|
|
||||||
// Ambient
|
// Ambient
|
||||||
lightColor += att * Lights[i].ambient.rgb * (MaterialAmbient.rgb + SceneAmbient.rgb);
|
lightAmbient += att * Lights[i].color.rgb * Lights[i].factors.x;
|
||||||
|
|
||||||
// Modification de l'atténuation
|
// Diffuse
|
||||||
|
float lambert = max(dot(normal, lightDir), 0.0);
|
||||||
|
|
||||||
|
// Modification de l'atténuation pour gérer le spot
|
||||||
float curAngle = dot(Lights[i].parameters2.xyz, -lightDir);
|
float curAngle = dot(Lights[i].parameters2.xyz, -lightDir);
|
||||||
float outerAngle = Lights[i].parameters3.y;
|
float outerAngle = Lights[i].parameters3.y;
|
||||||
float innerMinusOuterAngle = Lights[i].parameters3.x - outerAngle;
|
float innerMinusOuterAngle = Lights[i].parameters3.x - outerAngle;
|
||||||
float lambert = max(dot(normal, lightDir), 0.0);
|
|
||||||
att *= max((curAngle - outerAngle) / innerMinusOuterAngle, 0.0);
|
att *= max((curAngle - outerAngle) / innerMinusOuterAngle, 0.0);
|
||||||
|
|
||||||
// Diffuse
|
lightDiffuse += att * lambert * Lights[i].color.rgb * Lights[i].factors.y;
|
||||||
lightColor += att * lambert * Lights[i].diffuse.rgb * MaterialDiffuse.rgb;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
@ -260,17 +261,17 @@ void main()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fragmentColor *= vec4(lightColor, 1.0);
|
lightAmbient = (lightAmbient + SceneAmbient.rgb)*MaterialAmbient.rgb;
|
||||||
|
lightSpecular *= MaterialSpecular.rgb;
|
||||||
#if SPECULAR_MAPPING
|
#if SPECULAR_MAPPING
|
||||||
fragmentColor *= vec4(specularColor * texture(MaterialSpecularMap, vTexCoord).rgb, 1.0); // Utiliser l'alpha de MaterialSpecular n'aurait aucun sens
|
lightSpecular *= texture(MaterialSpecularMap, vTexCoord).rgb; // Utiliser l'alpha de MaterialSpecular n'aurait aucun sens
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
vec3 lightColor = (lightAmbient + lightDiffuse + lightSpecular);
|
||||||
|
vec4 fragmentColor = vec4(lightColor, 1.0) * diffuseColor;
|
||||||
|
|
||||||
#if EMISSIVE_MAPPING
|
#if EMISSIVE_MAPPING
|
||||||
#if SPECULAR_MAPPING
|
|
||||||
float lightIntensity = dot(lightColor + specularColor, vec3(0.3, 0.59, 0.11));
|
|
||||||
#else
|
|
||||||
float lightIntensity = dot(lightColor, vec3(0.3, 0.59, 0.11));
|
float lightIntensity = dot(lightColor, vec3(0.3, 0.59, 0.11));
|
||||||
#endif // SPECULAR_MAPPING
|
|
||||||
|
|
||||||
vec3 emissionColor = MaterialDiffuse.rgb * texture(MaterialEmissiveMap, vTexCoord).rgb;
|
vec3 emissionColor = MaterialDiffuse.rgb * texture(MaterialEmissiveMap, vTexCoord).rgb;
|
||||||
RenderTarget0 = vec4(mix(fragmentColor.rgb, emissionColor, clamp(1.0 - 3.0*lightIntensity, 0.0, 1.0)), fragmentColor.a);
|
RenderTarget0 = vec4(mix(fragmentColor.rgb, emissionColor, clamp(1.0 - 3.0*lightIntensity, 0.0, 1.0)), fragmentColor.a);
|
||||||
|
|
@ -278,7 +279,7 @@ void main()
|
||||||
RenderTarget0 = fragmentColor;
|
RenderTarget0 = fragmentColor;
|
||||||
#endif // EMISSIVE_MAPPING
|
#endif // EMISSIVE_MAPPING
|
||||||
#else
|
#else
|
||||||
RenderTarget0 = fragmentColor;
|
RenderTarget0 = diffuseColor;
|
||||||
#endif // LIGHTING
|
#endif // LIGHTING
|
||||||
#endif // FLAG_DEFERRED
|
#endif // FLAG_DEFERRED
|
||||||
}
|
}
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue