#include "../Shaders/Shaders_DirectionalLightShadow_glsl.pxx"
#include "../Shaders/Shaders_PBRDistribution_glsl.pxx"
+#include "../Shaders/Shaders_PBRDirectionalLight_glsl.pxx"
#include "../Shaders/Shaders_PBRGeometry_glsl.pxx"
#include "../Shaders/Shaders_PBRFresnel_glsl.pxx"
#include "../Shaders/Shaders_PBRCookTorrance_glsl.pxx"
#include "../Shaders/Shaders_PBRIllumination_glsl.pxx"
+#include "../Shaders/Shaders_PBRPointLight_glsl.pxx"
+#include "../Shaders/Shaders_PBRSpotLight_glsl.pxx"
#include "../Shaders/Shaders_PBREnvBaking_fs.pxx"
#include "../Shaders/Shaders_PBREnvBaking_vs.pxx"
+#include "../Shaders/Shaders_PhongDirectionalLight_glsl.pxx"
+#include "../Shaders/Shaders_PhongPointLight_glsl.pxx"
+#include "../Shaders/Shaders_PhongSpotLight_glsl.pxx"
#include "../Shaders/Shaders_PointLightAttenuation_glsl.pxx"
#include "../Shaders/Shaders_TangentSpaceNormal_glsl.pxx"
EOL"vec3 Emission;" //!< Light intensity emitted by material
EOL"float IOR;"; //!< Material's index of refraction
-//! Function computes contribution of isotropic point light source
-const char THE_FUNC_pointLight[] =
- EOL"void pointLight (in int theId,"
- EOL" in vec3 theNormal,"
- EOL" in vec3 theView,"
- EOL" in vec3 thePoint,"
- EOL" in bool theIsFront)"
- EOL"{"
- EOL" vec3 aLight = vec3 (occWorldViewMatrix * vec4 (occLight_Position (theId), 1.0)) - thePoint;"
- EOL
- EOL" float aDist = length (aLight);"
- EOL" float aRange = occLight_Range (theId);"
- EOL" float anAtten = occPointLightAttenuation (aDist, aRange, occLight_LinearAttenuation (theId), occLight_ConstAttenuation (theId));"
- EOL" if (anAtten <= 0.0) return;"
- EOL" aLight /= aDist;"
- EOL
- EOL" vec3 aHalf = normalize (aLight + theView);"
- EOL
- EOL" vec3 aFaceSideNormal = theIsFront ? theNormal : -theNormal;"
- EOL" float aNdotL = max (0.0, dot (aFaceSideNormal, aLight));"
- EOL" float aNdotH = max (0.0, dot (aFaceSideNormal, aHalf ));"
- EOL
- EOL" float aSpecl = 0.0;"
- EOL" if (aNdotL > 0.0)"
- EOL" {"
- EOL" aSpecl = pow (aNdotH, theIsFront ? occFrontMaterial_Shininess() : occBackMaterial_Shininess());"
- EOL" }"
- EOL
- EOL" Diffuse += occLight_Diffuse (theId) * aNdotL * anAtten;"
- EOL" Specular += occLight_Specular(theId) * aSpecl * anAtten;"
- EOL"}";
-
-//! Function computes contribution of isotropic point light source
-const char THE_FUNC_PBR_pointLight[] =
- EOL"void pointLight (in int theId,"
- EOL" in vec3 theNormal,"
- EOL" in vec3 theView,"
- EOL" in vec3 thePoint,"
- EOL" in bool theIsFront)"
- EOL"{"
- EOL" vec3 aLight = occLight_Position (theId) - thePoint;"
- EOL
- EOL" float aDist = length (aLight);"
- EOL" float aRange = occLight_Range (theId);"
- EOL" float anAtten = occPointLightAttenuation (aDist, aRange);"
- EOL" if (anAtten <= 0.0) return;"
- EOL" aLight /= aDist;"
- EOL
- EOL" theNormal = theIsFront ? theNormal : -theNormal;"
- EOL" DirectLighting += occPBRIllumination (theView, aLight, theNormal,"
- EOL" BaseColor, Metallic, Roughness, IOR,"
- EOL" occLight_Specular (theId),"
- EOL" occLight_Intensity(theId) * anAtten);"
- EOL"}";
-
-//! Function computes contribution of spotlight source
-const char THE_FUNC_spotLight[] =
- EOL"void spotLight (in int theId,"
- EOL" in vec3 theNormal,"
- EOL" in vec3 theView,"
- EOL" in vec3 thePoint,"
- EOL" in bool theIsFront)"
- EOL"{"
- EOL" vec3 aLight = vec3 (occWorldViewMatrix * vec4 (occLight_Position (theId), 1.0)) - thePoint;"
- EOL
- EOL" float aDist = length (aLight);"
- EOL" float aRange = occLight_Range (theId);"
- EOL" float anAtten = occPointLightAttenuation (aDist, aRange, occLight_LinearAttenuation (theId), occLight_ConstAttenuation (theId));"
- EOL" if (anAtten <= 0.0) return;"
- EOL" aLight /= aDist;"
- EOL
- EOL" vec3 aSpotDir = vec3 (occWorldViewMatrix * vec4 (occLight_SpotDirection (theId), 0.0));"
- EOL" aSpotDir = normalize (aSpotDir);"
- // light cone
- EOL" float aCosA = dot (aSpotDir, -aLight);"
- EOL" if (aCosA >= 1.0 || aCosA < cos (occLight_SpotCutOff (theId)))"
- EOL" {"
- EOL" return;"
- EOL" }"
- EOL
- EOL" float anExponent = occLight_SpotExponent (theId);"
- EOL" if (anExponent > 0.0)"
- EOL" {"
- EOL" anAtten *= pow (aCosA, anExponent * 128.0);"
- EOL" }"
- EOL
- EOL" vec3 aHalf = normalize (aLight + theView);"
- EOL
- EOL" vec3 aFaceSideNormal = theIsFront ? theNormal : -theNormal;"
- EOL" float aNdotL = max (0.0, dot (aFaceSideNormal, aLight));"
- EOL" float aNdotH = max (0.0, dot (aFaceSideNormal, aHalf ));"
- EOL
- EOL" float aSpecl = 0.0;"
- EOL" if (aNdotL > 0.0)"
- EOL" {"
- EOL" aSpecl = pow (aNdotH, theIsFront ? occFrontMaterial_Shininess() : occBackMaterial_Shininess());"
- EOL" }"
- EOL
- EOL" Diffuse += occLight_Diffuse (theId) * aNdotL * anAtten;"
- EOL" Specular += occLight_Specular(theId) * aSpecl * anAtten;"
- EOL"}";
-
-//! Function computes contribution of spotlight source
- const char THE_FUNC_PBR_spotLight[] =
- EOL"void spotLight (in int theId,"
- EOL" in vec3 theNormal,"
- EOL" in vec3 theView,"
- EOL" in vec3 thePoint,"
- EOL" in bool theIsFront)"
- EOL"{"
- EOL" vec3 aLight = occLight_Position (theId) - thePoint;"
- EOL
- EOL" float aDist = length (aLight);"
- EOL" float aRange = occLight_Range (theId);"
- EOL" float anAtten = occPointLightAttenuation (aDist, aRange);"
- EOL" if (anAtten <= 0.0) return;"
- EOL" aLight /= aDist;"
- EOL
- EOL" vec3 aSpotDir = occLight_SpotDirection (theId);"
- // light cone
- EOL" float aCosA = dot (aSpotDir, -aLight);"
- EOL" float aRelativeAngle = 2.0 * acos(aCosA) / occLight_SpotCutOff(theId);"
- EOL" if (aCosA >= 1.0 || aRelativeAngle > 1.0)"
- EOL" {"
- EOL" return;"
- EOL" }"
- EOL" float anExponent = occLight_SpotExponent (theId);"
- EOL" if ((1.0 - aRelativeAngle) <= anExponent)"
- EOL" {"
- EOL" float anAngularAttenuationOffset = cos(0.5 * occLight_SpotCutOff(theId));"
- EOL" float anAngularAttenuationScale = 1.0 / max(0.001, cos(0.5 * occLight_SpotCutOff(theId) * (1.0 - anExponent)) - anAngularAttenuationOffset);"
- EOL" anAngularAttenuationOffset *= -anAngularAttenuationScale;"
- EOL" float anAngularAttenuantion = clamp(aCosA * anAngularAttenuationScale + anAngularAttenuationOffset, 0.0, 1.0);"
- EOL" anAtten *= anAngularAttenuantion * anAngularAttenuantion;"
- EOL" }"
- EOL" theNormal = theIsFront ? theNormal : -theNormal;"
- EOL" DirectLighting += occPBRIllumination (theView, aLight, theNormal,"
- EOL" BaseColor, Metallic, Roughness, IOR,"
- EOL" occLight_Specular(theId),"
- EOL" occLight_Intensity(theId) * anAtten);"
- EOL"}";
-
-//! Function computes contribution of directional light source
-const char THE_FUNC_directionalLight[] =
- EOL"void directionalLight (in int theId,"
- EOL" in vec3 theNormal,"
- EOL" in vec3 theView,"
- EOL" in bool theIsFront,"
- EOL" in float theShadow)"
- EOL"{"
- EOL" vec3 aLight = vec3 (occWorldViewMatrix * vec4 (occLight_Position (theId), 0.0));"
- EOL
- EOL" vec3 aHalf = normalize (aLight + theView);"
- EOL
- EOL" vec3 aFaceSideNormal = theIsFront ? theNormal : -theNormal;"
- EOL" float aNdotL = max (0.0, dot (aFaceSideNormal, aLight));"
- EOL" float aNdotH = max (0.0, dot (aFaceSideNormal, aHalf ));"
- EOL
- EOL" float aSpecl = 0.0;"
- EOL" if (aNdotL > 0.0)"
- EOL" {"
- EOL" aSpecl = pow (aNdotH, theIsFront ? occFrontMaterial_Shininess() : occBackMaterial_Shininess());"
- EOL" }"
- EOL
- EOL" Diffuse += occLight_Diffuse (theId) * aNdotL * theShadow;"
- EOL" Specular += occLight_Specular (theId) * aSpecl * theShadow;"
- EOL"}";
-
-//! Function computes contribution of directional light source
-const char THE_FUNC_PBR_directionalLight[] =
- EOL"void directionalLight (in int theId,"
- EOL" in vec3 theNormal,"
- EOL" in vec3 theView,"
- EOL" in bool theIsFront,"
- EOL" in float theShadow)"
- EOL"{"
- EOL" vec3 aLight = occLight_Position (theId);"
- EOL
- EOL" theNormal = theIsFront ? theNormal : -theNormal;"
- EOL" DirectLighting += occPBRIllumination (theView, aLight, theNormal,"
- EOL" BaseColor, Metallic, Roughness, IOR,"
- EOL" occLight_Specular (theId),"
- EOL" occLight_Intensity(theId)) * theShadow;"
- EOL"}";
-
-//! The same as THE_FUNC_directionalLight but for the light with zero index
+//! The same as Shaders_PhongDirectionalLight_glsl but for the light with zero index
//! (avoids limitations on some mobile devices).
const char THE_FUNC_directionalLightFirst[] =
EOL"void directionalLightFirst (in vec3 theNormal,"
if (aLightIter.Value()->Type() == Graphic3d_TOLS_DIRECTIONAL
&& aLightIter.Value()->ToCastShadows())
{
- aLightsLoop = aLightsLoop + EOL" directionalLight (" + anIndex + ", theNormal, theView, theIsFront,"
- EOL" occDirectionalLightShadow (" + anIndex + ", theNormal));";
+ aLightsLoop = aLightsLoop + EOL" occDirectionalLight (" + anIndex + ", theNormal, theView, theIsFront,"
+ EOL" occDirectionalLightShadow (" + anIndex + ", theNormal));";
++anIndex;
}
}
{
break;
}
- aLightsLoop = aLightsLoop + EOL" directionalLight (" + anIndex + ", theNormal, theView, theIsFront, 1.0);";
+ aLightsLoop = aLightsLoop + EOL" occDirectionalLight (" + anIndex + ", theNormal, theView, theIsFront, 1.0);";
++anIndex;
break;
}
case Graphic3d_TOLS_POSITIONAL:
{
- aLightsLoop = aLightsLoop + EOL" pointLight (" + anIndex + ", theNormal, theView, aPoint, theIsFront);";
+ aLightsLoop = aLightsLoop + EOL" occPointLight (" + anIndex + ", theNormal, theView, aPoint, theIsFront);";
++anIndex;
break;
}
case Graphic3d_TOLS_SPOT:
{
- aLightsLoop = aLightsLoop + EOL" spotLight (" + anIndex + ", theNormal, theView, aPoint, theIsFront);";
+ aLightsLoop = aLightsLoop + EOL" occSpotLight (" + anIndex + ", theNormal, theView, aPoint, theIsFront);";
++anIndex;
break;
}
aLightsLoop +=
EOL" if (aType == OccLightType_Direct)"
EOL" {"
- EOL" directionalLight (anIndex, theNormal, theView, theIsFront, 1.0);"
+ EOL" occDirectionalLight (anIndex, theNormal, theView, theIsFront, 1.0);"
EOL" }";
}
if (aLights->NbEnabledLightsOfType (Graphic3d_TOLS_POSITIONAL) > 0)
aLightsLoop +=
EOL" if (aType == OccLightType_Point)"
EOL" {"
- EOL" pointLight (anIndex, theNormal, theView, aPoint, theIsFront);"
+ EOL" occPointLight (anIndex, theNormal, theView, aPoint, theIsFront);"
EOL" }";
}
if (aLights->NbEnabledLightsOfType (Graphic3d_TOLS_SPOT) > 0)
aLightsLoop +=
EOL" if (aType == OccLightType_Spot)"
EOL" {"
- EOL" spotLight (anIndex, theNormal, theView, aPoint, theIsFront);"
+ EOL" occSpotLight (anIndex, theNormal, theView, aPoint, theIsFront);"
EOL" }";
}
aLightsLoop += EOL" }";
{
aLightsFunc += Shaders_DirectionalLightShadow_glsl;
}
- aLightsFunc += theIsPBR ? THE_FUNC_PBR_directionalLight : THE_FUNC_directionalLight;
+ aLightsFunc += theIsPBR ? Shaders_PBRDirectionalLight_glsl : Shaders_PhongDirectionalLight_glsl;
}
if (aLights->NbEnabledLightsOfType (Graphic3d_TOLS_POSITIONAL) > 0)
{
- aLightsFunc += theIsPBR ? THE_FUNC_PBR_pointLight : THE_FUNC_pointLight;
+ aLightsFunc += theIsPBR ? Shaders_PBRPointLight_glsl : Shaders_PhongPointLight_glsl;
}
if (aLights->NbEnabledLightsOfType (Graphic3d_TOLS_SPOT) > 0)
{
- aLightsFunc += theIsPBR ? THE_FUNC_PBR_spotLight : THE_FUNC_spotLight;
+ aLightsFunc += theIsPBR ? Shaders_PBRSpotLight_glsl : Shaders_PhongSpotLight_glsl;
}
}
srcinc:::DeclarationsImpl.glsl
srcinc:::DirectionalLightShadow.glsl
srcinc:::PBRCookTorrance.glsl
+srcinc:::PBRDirectionalLight.glsl
srcinc:::PBRDistribution.glsl
srcinc:::PBREnvBaking.fs
srcinc:::PBREnvBaking.vs
srcinc:::PBRFresnel.glsl
srcinc:::PBRGeometry.glsl
srcinc:::PBRIllumination.glsl
+srcinc:::PBRPointLight.glsl
+srcinc:::PBRSpotLight.glsl
srcinc:::PhongShading.fs
srcinc:::PhongShading.vs
+srcinc:::PhongDirectionalLight.glsl
+srcinc:::PhongPointLight.glsl
+srcinc:::PhongSpotLight.glsl
srcinc:::PointLightAttenuation.glsl
srcinc:::Display.fs
srcinc:::RaytraceBase.fs
Shaders_DirectionalLightShadow_glsl.pxx
Shaders_Display_fs.pxx
Shaders_PBRCookTorrance_glsl.pxx
+Shaders_PBRDirectionalLight_glsl.pxx
Shaders_PBRDistribution_glsl.pxx
Shaders_PBREnvBaking_fs.pxx
Shaders_PBREnvBaking_vs.pxx
Shaders_PBRFresnel_glsl.pxx
Shaders_PBRGeometry_glsl.pxx
Shaders_PBRIllumination_glsl.pxx
+Shaders_PBRPointLight_glsl.pxx
+Shaders_PBRSpotLight_glsl.pxx
+Shaders_PhongDirectionalLight_glsl.pxx
+Shaders_PhongPointLight_glsl.pxx
+Shaders_PhongSpotLight_glsl.pxx
Shaders_PointLightAttenuation_glsl.pxx
Shaders_RaytraceBase_fs.pxx
Shaders_RaytraceRender_fs.pxx
--- /dev/null
+//! Function computes contribution of directional light source
+//! into global variable DirectLighting (PBR shading).
+//! @param theId light source index
+//! @param theNormal surface normal
+//! @param theView view direction
+//! @param theIsFront front/back face flag
+//! @param theShadow shadow attenuation
+void occDirectionalLight (in int theId,
+ in vec3 theNormal,
+ in vec3 theView,
+ in bool theIsFront,
+ in float theShadow)
+{
+ vec3 aLight = occLight_Position (theId);
+ theNormal = theIsFront ? theNormal : -theNormal;
+ DirectLighting += occPBRIllumination (theView, aLight, theNormal,
+ BaseColor, Metallic, Roughness, IOR,
+ occLight_Specular (theId),
+ occLight_Intensity(theId)) * theShadow;
+}
--- /dev/null
+//! Function computes contribution of isotropic point light source
+//! into global variable DirectLighting (PBR shading).
+//! @param theId light source index
+//! @param theNormal surface normal
+//! @param theView view direction
+//! @param thePoint 3D position (world space)
+//! @param theIsFront front/back face flag
+void occPointLight (in int theId,
+ in vec3 theNormal,
+ in vec3 theView,
+ in vec3 thePoint,
+ in bool theIsFront)
+{
+ vec3 aLight = occLight_Position (theId) - thePoint;
+
+ float aDist = length (aLight);
+ float aRange = occLight_Range (theId);
+ float anAtten = occPointLightAttenuation (aDist, aRange);
+ if (anAtten <= 0.0) return;
+ aLight /= aDist;
+
+ theNormal = theIsFront ? theNormal : -theNormal;
+ DirectLighting += occPBRIllumination (theView, aLight, theNormal,
+ BaseColor, Metallic, Roughness, IOR,
+ occLight_Specular (theId),
+ occLight_Intensity(theId) * anAtten);
+}
--- /dev/null
+//! Function computes contribution of spotlight source
+//! into global variable DirectLighting (PBR shading).
+//! @param theId light source index
+//! @param theNormal surface normal
+//! @param theView view direction
+//! @param thePoint 3D position (world space)
+//! @param theIsFront front/back face flag
+void occSpotLight (in int theId,
+ in vec3 theNormal,
+ in vec3 theView,
+ in vec3 thePoint,
+ in bool theIsFront)
+{
+ vec3 aLight = occLight_Position (theId) - thePoint;
+
+ float aDist = length (aLight);
+ float aRange = occLight_Range (theId);
+ float anAtten = occPointLightAttenuation (aDist, aRange);
+ if (anAtten <= 0.0) return;
+ aLight /= aDist;
+
+ vec3 aSpotDir = occLight_SpotDirection (theId);
+ // light cone
+ float aCosA = dot (aSpotDir, -aLight);
+ float aRelativeAngle = 2.0 * acos(aCosA) / occLight_SpotCutOff(theId);
+ if (aCosA >= 1.0 || aRelativeAngle > 1.0)
+ {
+ return;
+ }
+ float anExponent = occLight_SpotExponent (theId);
+ if ((1.0 - aRelativeAngle) <= anExponent)
+ {
+ float anAngularAttenuationOffset = cos(0.5 * occLight_SpotCutOff(theId));
+ float anAngularAttenuationScale = 1.0 / max(0.001, cos(0.5 * occLight_SpotCutOff(theId) * (1.0 - anExponent)) - anAngularAttenuationOffset);
+ anAngularAttenuationOffset *= -anAngularAttenuationScale;
+ float anAngularAttenuantion = clamp(aCosA * anAngularAttenuationScale + anAngularAttenuationOffset, 0.0, 1.0);
+ anAtten *= anAngularAttenuantion * anAngularAttenuantion;
+ }
+ theNormal = theIsFront ? theNormal : -theNormal;
+ DirectLighting += occPBRIllumination (theView, aLight, theNormal,
+ BaseColor, Metallic, Roughness, IOR,
+ occLight_Specular(theId),
+ occLight_Intensity(theId) * anAtten);
+}
--- /dev/null
+//! Function computes contribution of directional light source
+//! into global variables Diffuse and Specular (Phong shading).
+//! @param theId light source index
+//! @param theNormal surface normal
+//! @param theView view direction
+//! @param theIsFront front/back face flag
+//! @param theShadow shadow attenuation
+void occDirectionalLight (in int theId,
+ in vec3 theNormal,
+ in vec3 theView,
+ in bool theIsFront,
+ in float theShadow)
+{
+ vec3 aLight = vec3 (occWorldViewMatrix * vec4 (occLight_Position (theId), 0.0));
+ vec3 aHalf = normalize (aLight + theView);
+
+ vec3 aFaceSideNormal = theIsFront ? theNormal : -theNormal;
+ float aNdotL = max (0.0, dot (aFaceSideNormal, aLight));
+ float aNdotH = max (0.0, dot (aFaceSideNormal, aHalf ));
+
+ float aSpecl = 0.0;
+ if (aNdotL > 0.0)
+ {
+ aSpecl = pow (aNdotH, theIsFront ? occFrontMaterial_Shininess() : occBackMaterial_Shininess());
+ }
+
+ Diffuse += occLight_Diffuse (theId) * aNdotL * theShadow;
+ Specular += occLight_Specular (theId) * aSpecl * theShadow;
+}
--- /dev/null
+//! Function computes contribution of isotropic point light source
+//! into global variables Diffuse and Specular (Phong shading).
+//! @param theId light source index
+//! @param theNormal surface normal
+//! @param theView view direction
+//! @param thePoint 3D position (view space)
+//! @param theIsFront front/back face flag
+void occPointLight (in int theId,
+ in vec3 theNormal,
+ in vec3 theView,
+ in vec3 thePoint,
+ in bool theIsFront)
+{
+ vec3 aLight = vec3 (occWorldViewMatrix * vec4 (occLight_Position (theId), 1.0)) - thePoint;
+
+ float aDist = length (aLight);
+ float aRange = occLight_Range (theId);
+ float anAtten = occPointLightAttenuation (aDist, aRange, occLight_LinearAttenuation (theId), occLight_ConstAttenuation (theId));
+ if (anAtten <= 0.0) return;
+ aLight /= aDist;
+
+ vec3 aHalf = normalize (aLight + theView);
+
+ vec3 aFaceSideNormal = theIsFront ? theNormal : -theNormal;
+ float aNdotL = max (0.0, dot (aFaceSideNormal, aLight));
+ float aNdotH = max (0.0, dot (aFaceSideNormal, aHalf ));
+
+ float aSpecl = 0.0;
+ if (aNdotL > 0.0)
+ {
+ aSpecl = pow (aNdotH, theIsFront ? occFrontMaterial_Shininess() : occBackMaterial_Shininess());
+ }
+
+ Diffuse += occLight_Diffuse (theId) * aNdotL * anAtten;
+ Specular += occLight_Specular(theId) * aSpecl * anAtten;
+}
--- /dev/null
+//! Function computes contribution of spotlight source
+//! into global variables Diffuse and Specular (Phong shading).
+//! @param theId light source index
+//! @param theNormal surface normal
+//! @param theView view direction
+//! @param thePoint 3D position (view space)
+//! @param theIsFront front/back face flag
+void occSpotLight (in int theId,
+ in vec3 theNormal,
+ in vec3 theView,
+ in vec3 thePoint,
+ in bool theIsFront)
+{
+ vec3 aLight = vec3 (occWorldViewMatrix * vec4 (occLight_Position (theId), 1.0)) - thePoint;
+
+ float aDist = length (aLight);
+ float aRange = occLight_Range (theId);
+ float anAtten = occPointLightAttenuation (aDist, aRange, occLight_LinearAttenuation (theId), occLight_ConstAttenuation (theId));
+ if (anAtten <= 0.0) return;
+ aLight /= aDist;
+
+ vec3 aSpotDir = vec3 (occWorldViewMatrix * vec4 (occLight_SpotDirection (theId), 0.0));
+ aSpotDir = normalize (aSpotDir);
+ // light cone
+ float aCosA = dot (aSpotDir, -aLight);
+ if (aCosA >= 1.0 || aCosA < cos (occLight_SpotCutOff (theId)))
+ {
+ return;
+ }
+
+ float anExponent = occLight_SpotExponent (theId);
+ if (anExponent > 0.0)
+ {
+ anAtten *= pow (aCosA, anExponent * 128.0);
+ }
+
+ vec3 aHalf = normalize (aLight + theView);
+
+ vec3 aFaceSideNormal = theIsFront ? theNormal : -theNormal;
+ float aNdotL = max (0.0, dot (aFaceSideNormal, aLight));
+ float aNdotH = max (0.0, dot (aFaceSideNormal, aHalf ));
+
+ float aSpecl = 0.0;
+ if (aNdotL > 0.0)
+ {
+ aSpecl = pow (aNdotH, theIsFront ? occFrontMaterial_Shininess() : occBackMaterial_Shininess());
+ }
+
+ Diffuse += occLight_Diffuse (theId) * aNdotL * anAtten;
+ Specular += occLight_Specular(theId) * aSpecl * anAtten;
+}
--- /dev/null
+// This file has been automatically generated from resource file src/Shaders/PBRDirectionalLight.glsl
+
+static const char Shaders_PBRDirectionalLight_glsl[] =
+ "//! Function computes contribution of directional light source\n"
+ "//! into global variable DirectLighting (PBR shading).\n"
+ "//! @param theId light source index\n"
+ "//! @param theNormal surface normal\n"
+ "//! @param theView view direction\n"
+ "//! @param theIsFront front/back face flag\n"
+ "//! @param theShadow shadow attenuation\n"
+ "void occDirectionalLight (in int theId,\n"
+ " in vec3 theNormal,\n"
+ " in vec3 theView,\n"
+ " in bool theIsFront,\n"
+ " in float theShadow)\n"
+ "{\n"
+ " vec3 aLight = occLight_Position (theId);\n"
+ " theNormal = theIsFront ? theNormal : -theNormal;\n"
+ " DirectLighting += occPBRIllumination (theView, aLight, theNormal,\n"
+ " BaseColor, Metallic, Roughness, IOR,\n"
+ " occLight_Specular (theId),\n"
+ " occLight_Intensity(theId)) * theShadow;\n"
+ "}\n";
--- /dev/null
+// This file has been automatically generated from resource file src/Shaders/PBRPointLight.glsl
+
+static const char Shaders_PBRPointLight_glsl[] =
+ "//! Function computes contribution of isotropic point light source\n"
+ "//! into global variable DirectLighting (PBR shading).\n"
+ "//! @param theId light source index\n"
+ "//! @param theNormal surface normal\n"
+ "//! @param theView view direction\n"
+ "//! @param thePoint 3D position (world space)\n"
+ "//! @param theIsFront front/back face flag\n"
+ "void occPointLight (in int theId,\n"
+ " in vec3 theNormal,\n"
+ " in vec3 theView,\n"
+ " in vec3 thePoint,\n"
+ " in bool theIsFront)\n"
+ "{\n"
+ " vec3 aLight = occLight_Position (theId) - thePoint;\n"
+ "\n"
+ " float aDist = length (aLight);\n"
+ " float aRange = occLight_Range (theId);\n"
+ " float anAtten = occPointLightAttenuation (aDist, aRange);\n"
+ " if (anAtten <= 0.0) return;\n"
+ " aLight /= aDist;\n"
+ "\n"
+ " theNormal = theIsFront ? theNormal : -theNormal;\n"
+ " DirectLighting += occPBRIllumination (theView, aLight, theNormal,\n"
+ " BaseColor, Metallic, Roughness, IOR,\n"
+ " occLight_Specular (theId),\n"
+ " occLight_Intensity(theId) * anAtten);\n"
+ "}\n";
--- /dev/null
+// This file has been automatically generated from resource file src/Shaders/PBRSpotLight.glsl
+
+static const char Shaders_PBRSpotLight_glsl[] =
+ "//! Function computes contribution of spotlight source\n"
+ "//! into global variable DirectLighting (PBR shading).\n"
+ "//! @param theId light source index\n"
+ "//! @param theNormal surface normal\n"
+ "//! @param theView view direction\n"
+ "//! @param thePoint 3D position (world space)\n"
+ "//! @param theIsFront front/back face flag\n"
+ "void occSpotLight (in int theId,\n"
+ " in vec3 theNormal,\n"
+ " in vec3 theView,\n"
+ " in vec3 thePoint,\n"
+ " in bool theIsFront)\n"
+ "{\n"
+ " vec3 aLight = occLight_Position (theId) - thePoint;\n"
+ "\n"
+ " float aDist = length (aLight);\n"
+ " float aRange = occLight_Range (theId);\n"
+ " float anAtten = occPointLightAttenuation (aDist, aRange);\n"
+ " if (anAtten <= 0.0) return;\n"
+ " aLight /= aDist;\n"
+ "\n"
+ " vec3 aSpotDir = occLight_SpotDirection (theId);\n"
+ " // light cone\n"
+ " float aCosA = dot (aSpotDir, -aLight);\n"
+ " float aRelativeAngle = 2.0 * acos(aCosA) / occLight_SpotCutOff(theId);\n"
+ " if (aCosA >= 1.0 || aRelativeAngle > 1.0)\n"
+ " {\n"
+ " return;\n"
+ " }\n"
+ " float anExponent = occLight_SpotExponent (theId);\n"
+ " if ((1.0 - aRelativeAngle) <= anExponent)\n"
+ " {\n"
+ " float anAngularAttenuationOffset = cos(0.5 * occLight_SpotCutOff(theId));\n"
+ " float anAngularAttenuationScale = 1.0 / max(0.001, cos(0.5 * occLight_SpotCutOff(theId) * (1.0 - anExponent)) - anAngularAttenuationOffset);\n"
+ " anAngularAttenuationOffset *= -anAngularAttenuationScale;\n"
+ " float anAngularAttenuantion = clamp(aCosA * anAngularAttenuationScale + anAngularAttenuationOffset, 0.0, 1.0);\n"
+ " anAtten *= anAngularAttenuantion * anAngularAttenuantion;\n"
+ " }\n"
+ " theNormal = theIsFront ? theNormal : -theNormal;\n"
+ " DirectLighting += occPBRIllumination (theView, aLight, theNormal,\n"
+ " BaseColor, Metallic, Roughness, IOR,\n"
+ " occLight_Specular(theId),\n"
+ " occLight_Intensity(theId) * anAtten);\n"
+ "}\n";
--- /dev/null
+// This file has been automatically generated from resource file src/Shaders/PhongDirectionalLight.glsl
+
+static const char Shaders_PhongDirectionalLight_glsl[] =
+ "//! Function computes contribution of directional light source\n"
+ "//! into global variables Diffuse and Specular (Phong shading).\n"
+ "//! @param theId light source index\n"
+ "//! @param theNormal surface normal\n"
+ "//! @param theView view direction\n"
+ "//! @param theIsFront front/back face flag\n"
+ "//! @param theShadow shadow attenuation\n"
+ "void occDirectionalLight (in int theId,\n"
+ " in vec3 theNormal,\n"
+ " in vec3 theView,\n"
+ " in bool theIsFront,\n"
+ " in float theShadow)\n"
+ "{\n"
+ " vec3 aLight = vec3 (occWorldViewMatrix * vec4 (occLight_Position (theId), 0.0));\n"
+ " vec3 aHalf = normalize (aLight + theView);\n"
+ "\n"
+ " vec3 aFaceSideNormal = theIsFront ? theNormal : -theNormal;\n"
+ " float aNdotL = max (0.0, dot (aFaceSideNormal, aLight));\n"
+ " float aNdotH = max (0.0, dot (aFaceSideNormal, aHalf ));\n"
+ "\n"
+ " float aSpecl = 0.0;\n"
+ " if (aNdotL > 0.0)\n"
+ " {\n"
+ " aSpecl = pow (aNdotH, theIsFront ? occFrontMaterial_Shininess() : occBackMaterial_Shininess());\n"
+ " }\n"
+ "\n"
+ " Diffuse += occLight_Diffuse (theId) * aNdotL * theShadow;\n"
+ " Specular += occLight_Specular (theId) * aSpecl * theShadow;\n"
+ "}\n";
--- /dev/null
+// This file has been automatically generated from resource file src/Shaders/PhongPointLight.glsl
+
+static const char Shaders_PhongPointLight_glsl[] =
+ "//! Function computes contribution of isotropic point light source\n"
+ "//! into global variables Diffuse and Specular (Phong shading).\n"
+ "//! @param theId light source index\n"
+ "//! @param theNormal surface normal\n"
+ "//! @param theView view direction\n"
+ "//! @param thePoint 3D position (view space)\n"
+ "//! @param theIsFront front/back face flag\n"
+ "void occPointLight (in int theId,\n"
+ " in vec3 theNormal,\n"
+ " in vec3 theView,\n"
+ " in vec3 thePoint,\n"
+ " in bool theIsFront)\n"
+ "{\n"
+ " vec3 aLight = vec3 (occWorldViewMatrix * vec4 (occLight_Position (theId), 1.0)) - thePoint;\n"
+ "\n"
+ " float aDist = length (aLight);\n"
+ " float aRange = occLight_Range (theId);\n"
+ " float anAtten = occPointLightAttenuation (aDist, aRange, occLight_LinearAttenuation (theId), occLight_ConstAttenuation (theId));\n"
+ " if (anAtten <= 0.0) return;\n"
+ " aLight /= aDist;\n"
+ "\n"
+ " vec3 aHalf = normalize (aLight + theView);\n"
+ "\n"
+ " vec3 aFaceSideNormal = theIsFront ? theNormal : -theNormal;\n"
+ " float aNdotL = max (0.0, dot (aFaceSideNormal, aLight));\n"
+ " float aNdotH = max (0.0, dot (aFaceSideNormal, aHalf ));\n"
+ "\n"
+ " float aSpecl = 0.0;\n"
+ " if (aNdotL > 0.0)\n"
+ " {\n"
+ " aSpecl = pow (aNdotH, theIsFront ? occFrontMaterial_Shininess() : occBackMaterial_Shininess());\n"
+ " }\n"
+ "\n"
+ " Diffuse += occLight_Diffuse (theId) * aNdotL * anAtten;\n"
+ " Specular += occLight_Specular(theId) * aSpecl * anAtten;\n"
+ "}\n";
--- /dev/null
+// This file has been automatically generated from resource file src/Shaders/PhongSpotLight.glsl
+
+static const char Shaders_PhongSpotLight_glsl[] =
+ "//! Function computes contribution of spotlight source\n"
+ "//! into global variables Diffuse and Specular (Phong shading).\n"
+ "//! @param theId light source index\n"
+ "//! @param theNormal surface normal\n"
+ "//! @param theView view direction\n"
+ "//! @param thePoint 3D position (view space)\n"
+ "//! @param theIsFront front/back face flag\n"
+ "void occSpotLight (in int theId,\n"
+ " in vec3 theNormal,\n"
+ " in vec3 theView,\n"
+ " in vec3 thePoint,\n"
+ " in bool theIsFront)\n"
+ "{\n"
+ " vec3 aLight = vec3 (occWorldViewMatrix * vec4 (occLight_Position (theId), 1.0)) - thePoint;\n"
+ "\n"
+ " float aDist = length (aLight);\n"
+ " float aRange = occLight_Range (theId);\n"
+ " float anAtten = occPointLightAttenuation (aDist, aRange, occLight_LinearAttenuation (theId), occLight_ConstAttenuation (theId));\n"
+ " if (anAtten <= 0.0) return;\n"
+ " aLight /= aDist;\n"
+ "\n"
+ " vec3 aSpotDir = vec3 (occWorldViewMatrix * vec4 (occLight_SpotDirection (theId), 0.0));\n"
+ " aSpotDir = normalize (aSpotDir);\n"
+ " // light cone\n"
+ " float aCosA = dot (aSpotDir, -aLight);\n"
+ " if (aCosA >= 1.0 || aCosA < cos (occLight_SpotCutOff (theId)))\n"
+ " {\n"
+ " return;\n"
+ " }\n"
+ "\n"
+ " float anExponent = occLight_SpotExponent (theId);\n"
+ " if (anExponent > 0.0)\n"
+ " {\n"
+ " anAtten *= pow (aCosA, anExponent * 128.0);\n"
+ " }\n"
+ "\n"
+ " vec3 aHalf = normalize (aLight + theView);\n"
+ "\n"
+ " vec3 aFaceSideNormal = theIsFront ? theNormal : -theNormal;\n"
+ " float aNdotL = max (0.0, dot (aFaceSideNormal, aLight));\n"
+ " float aNdotH = max (0.0, dot (aFaceSideNormal, aHalf ));\n"
+ "\n"
+ " float aSpecl = 0.0;\n"
+ " if (aNdotL > 0.0)\n"
+ " {\n"
+ " aSpecl = pow (aNdotH, theIsFront ? occFrontMaterial_Shininess() : occBackMaterial_Shininess());\n"
+ " }\n"
+ "\n"
+ " Diffuse += occLight_Diffuse (theId) * aNdotL * anAtten;\n"
+ " Specular += occLight_Specular(theId) * aSpecl * anAtten;\n"
+ "}\n";