// =======================================================================
void Graphic3d_CLight::SetCastShadows (Standard_Boolean theToCast)
{
- if (myType != Graphic3d_TypeOfLightSource_Directional)
+ if (myType != Graphic3d_TypeOfLightSource_Directional
+ && myType != Graphic3d_TypeOfLightSource_Spot)
{
throw Standard_NotImplemented ("Graphic3d_CLight::SetCastShadows() is not implemented for this light type");
}
#include <Graphic3d_TextureSetBits.hxx>
#include <Message.hxx>
-#include "../Shaders/Shaders_DirectionalLightShadow_glsl.pxx"
+#include "../Shaders/Shaders_LightShadow_glsl.pxx"
#include "../Shaders/Shaders_PBRDistribution_glsl.pxx"
#include "../Shaders/Shaders_PBRDirectionalLight_glsl.pxx"
#include "../Shaders/Shaders_PBRGeometry_glsl.pxx"
if (theNbLights <= THE_NB_UNROLLED_LIGHTS_MAX)
{
Standard_Integer anIndex = 0;
- if (theNbShadowMaps > 0)
- {
- for (Graphic3d_LightSet::Iterator aLightIter (theLights, Graphic3d_LightSet::IterationFilter_ExcludeDisabledAndAmbient);
- aLightIter.More(); aLightIter.Next())
- {
- if (aLightIter.Value()->Type() == Graphic3d_TypeOfLightSource_Directional
- && aLightIter.Value()->ToCastShadows())
- {
- aLightsLoop = aLightsLoop + EOL" occDirectionalLight (" + anIndex + ", theNormal, theView, theIsFront,"
- EOL" occDirectionalLightShadow (occShadowMapSamplers[" + anIndex + "], " + anIndex + ", theNormal));";
- ++anIndex;
- }
- }
- }
for (Graphic3d_LightSet::Iterator aLightIter (theLights, Graphic3d_LightSet::IterationFilter_ExcludeDisabledAndAmbient);
aLightIter.More(); aLightIter.Next())
{
if (theNbShadowMaps > 0
&& aLightIter.Value()->ToCastShadows())
{
- break;
+ aLightsLoop = aLightsLoop +
+ EOL" occDirectionalLight (" + anIndex + ", theNormal, theView, theIsFront,"
+ EOL" occLightShadow (occShadowMapSamplers[" + anIndex + "], " + anIndex + ", theNormal));";
+ }
+ else
+ {
+ aLightsLoop = aLightsLoop + EOL" occDirectionalLight (" + anIndex + ", theNormal, theView, theIsFront, 1.0);";
}
- aLightsLoop = aLightsLoop + EOL" occDirectionalLight (" + anIndex + ", theNormal, theView, theIsFront, 1.0);";
++anIndex;
break;
}
}
case Graphic3d_TypeOfLightSource_Spot:
{
- aLightsLoop = aLightsLoop + EOL" occSpotLight (" + anIndex + ", theNormal, theView, aPoint, theIsFront);";
+ if (theNbShadowMaps > 0
+ && aLightIter.Value()->ToCastShadows())
+ {
+ aLightsLoop = aLightsLoop +
+ EOL" occSpotLight (" + anIndex + ", theNormal, theView, aPoint, theIsFront,"
+ EOL" occLightShadow (occShadowMapSamplers[" + anIndex + "], " + anIndex + ", theNormal));";
+ }
+ else
+ {
+ aLightsLoop = aLightsLoop + EOL" occSpotLight (" + anIndex + ", theNormal, theView, aPoint, theIsFront, 1.0);";
+ }
++anIndex;
break;
}
aLightsLoop +=
EOL" if (aType == OccLightType_Spot)"
EOL" {"
- EOL" occSpotLight (anIndex, theNormal, theView, aPoint, theIsFront);"
+ EOL" occSpotLight (anIndex, theNormal, theView, aPoint, theIsFront, 1.0);"
EOL" }";
}
aLightsLoop += EOL" }";
aLightsFunc += Shaders_PBRIllumination_glsl;
}
+ bool isShadowShaderAdded = false;
if (theLights->NbEnabledLightsOfType (Graphic3d_TypeOfLightSource_Directional) == 1
&& theNbLights == 1
&& !theIsPBR
}
else if (theLights->NbEnabledLightsOfType (Graphic3d_TypeOfLightSource_Directional) > 0)
{
- if (theNbShadowMaps > 0)
+ if (theNbShadowMaps > 0 && !isShadowShaderAdded)
{
- aLightsFunc += Shaders_DirectionalLightShadow_glsl;
+ aLightsFunc += Shaders_LightShadow_glsl;
+ isShadowShaderAdded = true;
}
aLightsFunc += theIsPBR ? Shaders_PBRDirectionalLight_glsl : Shaders_PhongDirectionalLight_glsl;
}
}
if (theLights->NbEnabledLightsOfType (Graphic3d_TypeOfLightSource_Spot) > 0)
{
+ if (theNbShadowMaps > 0 && !isShadowShaderAdded)
+ {
+ aLightsFunc += Shaders_LightShadow_glsl;
+ }
aLightsFunc += theIsPBR ? Shaders_PBRSpotLight_glsl : Shaders_PhongSpotLight_glsl;
}
}
{
if (myLightSourceState.ShadowMaps().IsNull()
|| myLightSourceState.ToCastShadows() == theToCast)
- {
+ {
return myLightSourceState.ToCastShadows();
}
}
case Graphic3d_TypeOfLightSource_Spot:
{
- //myShadowCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
- //myShadowCamera->SetEye (theCastShadowLight->Position());
- return false; // not implemented
+ if (theOrigin != NULL)
+ {
+ Graphic3d_Mat4d aTrans;
+ aTrans.Translate (Graphic3d_Vec3d (theOrigin->X(), theOrigin->Y(), theOrigin->Z()));
+ Graphic3d_Mat4d anOrientMat = myShadowCamera->OrientationMatrix() * aTrans;
+ myLightMatrix = myShadowCamera->ProjectionMatrixF() * Graphic3d_Mat4 (anOrientMat);
+ return true;
+ }
+
+ Graphic3d_Vec4d aDir (myShadowLight->Direction().X(), myShadowLight->Direction().Y(), myShadowLight->Direction().Z(), 0.0);
+ if (myShadowLight->IsHeadlight())
+ {
+ Graphic3d_Mat4d anOrientInv;
+ theView.Camera()->OrientationMatrix().Inverted (anOrientInv);
+ aDir = anOrientInv * aDir;
+ }
+
+ myShadowCamera->SetZeroToOneDepth (theView.Camera()->IsZeroToOneDepth());
+ myShadowCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
+
+ const gp_Pnt& aLightPos = myShadowLight->Position();
+ Standard_Real aDistance (aMinMaxBox.Distance (Bnd_Box (aLightPos, aLightPos))
+ + aMinMaxBox.CornerMin().Distance (aMinMaxBox.CornerMax()));
+ myShadowCamera->SetDistance (aDistance);
+ myShadowCamera->MoveEyeTo (aLightPos);
+ myShadowCamera->SetDirectionFromEye (myShadowLight->Direction());
+ myShadowCamera->SetUp (!myShadowCamera->Direction().IsParallel (gp::DY(), Precision::Angular())
+ ? gp::DY()
+ : gp::DX());
+ myShadowCamera->OrthogonalizeUp();
+ myShadowCamera->SetZRange (1.0, aDistance);
+
+ myLightMatrix = myShadowCamera->ProjectionMatrixF() * myShadowCamera->OrientationMatrixF();
+
+ return true;
}
}
return false;
aCtx->core11fwd->glClearDepth (1.0);
aCtx->core11fwd->glClear (GL_DEPTH_BUFFER_BIT);
+ Graphic3d_Camera::Projection aProjection = theShadowMap->LightSource()->Type() == Graphic3d_TypeOfLightSource_Directional
+ ? Graphic3d_Camera::Projection_Orthographic
+ : Graphic3d_Camera::Projection_Perspective;
myWorkspace->SetRenderFilter (myWorkspace->RenderFilter() | OpenGl_RenderFilter_SkipTrsfPersistence);
- renderScene (Graphic3d_Camera::Projection_Orthographic, aShadowBuffer.get(), NULL, false);
- myWorkspace->SetRenderFilter (myWorkspace->RenderFilter() & ~(Standard_Integer )OpenGl_RenderFilter_SkipTrsfPersistence);
+ renderScene (aProjection, aShadowBuffer.get(), NULL, false);
+ myWorkspace->SetRenderFilter (myWorkspace->RenderFilter() & ~(Standard_Integer)OpenGl_RenderFilter_SkipTrsfPersistence);
aCtx->SetColorMask (true);
myWorkspace->ResetAppliedAspect();
+++ /dev/null
-#if (__VERSION__ >= 120)
-//! Coefficients for gathering close samples for antialiasing.
-//! Use only with decent OpenGL (array constants cannot be initialized with GLSL 1.1 / GLSL ES 1.1)
-const vec2 occPoissonDisk16[16] = vec2[](
- vec2(-0.94201624,-0.39906216), vec2( 0.94558609,-0.76890725), vec2(-0.09418410,-0.92938870), vec2( 0.34495938, 0.29387760),
- vec2(-0.91588581, 0.45771432), vec2(-0.81544232,-0.87912464), vec2(-0.38277543, 0.27676845), vec2( 0.97484398, 0.75648379),
- vec2( 0.44323325,-0.97511554), vec2( 0.53742981,-0.47373420), vec2(-0.26496911,-0.41893023), vec2( 0.79197514, 0.19090188),
- vec2(-0.24188840, 0.99706507), vec2(-0.81409955, 0.91437590), vec2( 0.19984126, 0.78641367), vec2( 0.14383161,-0.14100790)
-);
-#endif
-
-//! Function computes directional light shadow attenuation (1.0 means no shadow).
-float occDirectionalLightShadow (in sampler2D theShadow,
- in int theId,
- in vec3 theNormal)
-{
- vec4 aPosLightSpace = PosLightSpace[occLight_Index(theId)];
- vec3 aLightDir = occLight_Position (theId);
- vec3 aProjCoords = (aPosLightSpace.xyz / aPosLightSpace.w);
-#ifdef THE_ZERO_TO_ONE_DEPTH
- aProjCoords.xy = aProjCoords.xy * 0.5 + vec2 (0.5);
-#else
- aProjCoords = aProjCoords * 0.5 + vec3 (0.5);
-#endif
- float aCurrentDepth = aProjCoords.z;
- if (aProjCoords.x < 0.0 || aProjCoords.x > 1.0
- || aProjCoords.y < 0.0 || aProjCoords.y > 1.0
- || aCurrentDepth > 1.0)
- {
- return 1.0;
- }
-
- vec2 aTexelSize = vec2 (occShadowMapSizeBias.x);
- float aBias = max (occShadowMapSizeBias.y * (1.0 - dot (theNormal, aLightDir)), occShadowMapSizeBias.y * 0.1);
-#if (__VERSION__ >= 120)
- float aShadow = 0.0;
- for (int aPosIter = 0; aPosIter < 16; ++aPosIter)
- {
- float aClosestDepth = occTexture2D (theShadow, aProjCoords.xy + occPoissonDisk16[aPosIter] * aTexelSize).r;
- aShadow += (aCurrentDepth - aBias) > aClosestDepth ? 1.0 : 0.0;
- }
- return 1.0 - aShadow / 16.0;
-#else
- float aClosestDepth = occTexture2D (theShadow, aProjCoords.xy).r;
- float aShadow = (aCurrentDepth - aBias) > aClosestDepth ? 1.0 : 0.0;
- return 1.0 - aShadow;
-#endif
-}
srcinc:::Declarations.glsl
srcinc:::DeclarationsImpl.glsl
-srcinc:::DirectionalLightShadow.glsl
+srcinc:::LightShadow.glsl
srcinc:::PBRCookTorrance.glsl
srcinc:::PBRDirectionalLight.glsl
srcinc:::PBRDistribution.glsl
srcinc:::SkydomBackground.fs
Shaders_Declarations_glsl.pxx
Shaders_DeclarationsImpl_glsl.pxx
-Shaders_DirectionalLightShadow_glsl.pxx
+Shaders_LightShadow_glsl.pxx
Shaders_Display_fs.pxx
Shaders_PBRCookTorrance_glsl.pxx
Shaders_PBRDirectionalLight_glsl.pxx
--- /dev/null
+#if (__VERSION__ >= 120)
+//! Coefficients for gathering close samples for antialiasing.
+//! Use only with decent OpenGL (array constants cannot be initialized with GLSL 1.1 / GLSL ES 1.1)
+const vec2 occPoissonDisk16[16] = vec2[](
+ vec2(-0.94201624,-0.39906216), vec2( 0.94558609,-0.76890725), vec2(-0.09418410,-0.92938870), vec2( 0.34495938, 0.29387760),
+ vec2(-0.91588581, 0.45771432), vec2(-0.81544232,-0.87912464), vec2(-0.38277543, 0.27676845), vec2( 0.97484398, 0.75648379),
+ vec2( 0.44323325,-0.97511554), vec2( 0.53742981,-0.47373420), vec2(-0.26496911,-0.41893023), vec2( 0.79197514, 0.19090188),
+ vec2(-0.24188840, 0.99706507), vec2(-0.81409955, 0.91437590), vec2( 0.19984126, 0.78641367), vec2( 0.14383161,-0.14100790)
+);
+#endif
+
+//! Function computes directional and spot light shadow attenuation (1.0 means no shadow).
+float occLightShadow (in sampler2D theShadow,
+ in int theId,
+ in vec3 theNormal)
+{
+ vec4 aPosLightSpace = PosLightSpace[occLight_Index(theId)];
+ vec3 aLightDir = occLight_Position (theId);
+ vec3 aProjCoords = (aPosLightSpace.xyz / aPosLightSpace.w);
+#ifdef THE_ZERO_TO_ONE_DEPTH
+ aProjCoords.xy = aProjCoords.xy * 0.5 + vec2 (0.5);
+#else
+ aProjCoords = aProjCoords * 0.5 + vec3 (0.5);
+#endif
+ float aCurrentDepth = aProjCoords.z;
+ if (aProjCoords.x < 0.0 || aProjCoords.x > 1.0
+ || aProjCoords.y < 0.0 || aProjCoords.y > 1.0
+ || aCurrentDepth > 1.0)
+ {
+ return 1.0;
+ }
+
+ vec2 aTexelSize = vec2 (occShadowMapSizeBias.x);
+ float aBias = max (occShadowMapSizeBias.y * (1.0 - dot (theNormal, aLightDir)), occShadowMapSizeBias.y * 0.1);
+#if (__VERSION__ >= 120)
+ float aShadow = 0.0;
+ for (int aPosIter = 0; aPosIter < 16; ++aPosIter)
+ {
+ float aClosestDepth = occTexture2D (theShadow, aProjCoords.xy + occPoissonDisk16[aPosIter] * aTexelSize).r;
+ aShadow += (aCurrentDepth - aBias) > aClosestDepth ? 1.0 : 0.0;
+ }
+ return 1.0 - aShadow / 16.0;
+#else
+ float aClosestDepth = occTexture2D (theShadow, aProjCoords.xy).r;
+ float aShadow = (aCurrentDepth - aBias) > aClosestDepth ? 1.0 : 0.0;
+ return 1.0 - aShadow;
+#endif
+}
in vec3 theNormal,
in vec3 theView,
in vec3 thePoint,
- in bool theIsFront)
+ in bool theIsFront,
+ in float theShadow)
{
vec3 aLight = occLight_Position (theId) - thePoint;
DirectLighting += occPBRIllumination (theView, aLight, theNormal,
BaseColor, Metallic, Roughness, IOR,
occLight_Specular(theId),
- occLight_Intensity(theId) * anAtten);
+ occLight_Intensity(theId) * anAtten) * theShadow;
}
//! @param theView view direction
//! @param thePoint 3D position (world space)
//! @param theIsFront front/back face flag
+//! @param theShadow the value from shadow map
void occSpotLight (in int theId,
in vec3 theNormal,
in vec3 theView,
in vec3 thePoint,
- in bool theIsFront)
+ in bool theIsFront,
+ in float theShadow)
{
vec3 aLight = occLight_Position (theId) - thePoint;
aSpecl = pow (aNdotH, occMaterial_Shininess (theIsFront));
}
- Diffuse += occLight_Diffuse (theId) * aNdotL * anAtten;
- Specular += occLight_Specular(theId) * aSpecl * anAtten;
+ Diffuse += occLight_Diffuse (theId) * aNdotL * anAtten * theShadow;
+ Specular += occLight_Specular(theId) * aSpecl * anAtten * theShadow;
}
+++ /dev/null
-// This file has been automatically generated from resource file src/Shaders/DirectionalLightShadow.glsl
-
-static const char Shaders_DirectionalLightShadow_glsl[] =
- "#if (__VERSION__ >= 120)\n"
- "//! Coefficients for gathering close samples for antialiasing.\n"
- "//! Use only with decent OpenGL (array constants cannot be initialized with GLSL 1.1 / GLSL ES 1.1)\n"
- "const vec2 occPoissonDisk16[16] = vec2[](\n"
- " vec2(-0.94201624,-0.39906216), vec2( 0.94558609,-0.76890725), vec2(-0.09418410,-0.92938870), vec2( 0.34495938, 0.29387760),\n"
- " vec2(-0.91588581, 0.45771432), vec2(-0.81544232,-0.87912464), vec2(-0.38277543, 0.27676845), vec2( 0.97484398, 0.75648379),\n"
- " vec2( 0.44323325,-0.97511554), vec2( 0.53742981,-0.47373420), vec2(-0.26496911,-0.41893023), vec2( 0.79197514, 0.19090188),\n"
- " vec2(-0.24188840, 0.99706507), vec2(-0.81409955, 0.91437590), vec2( 0.19984126, 0.78641367), vec2( 0.14383161,-0.14100790)\n"
- ");\n"
- "#endif\n"
- "\n"
- "//! Function computes directional light shadow attenuation (1.0 means no shadow).\n"
- "float occDirectionalLightShadow (in sampler2D theShadow,\n"
- " in int theId,\n"
- " in vec3 theNormal)\n"
- "{\n"
- " vec4 aPosLightSpace = PosLightSpace[occLight_Index(theId)];\n"
- " vec3 aLightDir = occLight_Position (theId);\n"
- " vec3 aProjCoords = (aPosLightSpace.xyz / aPosLightSpace.w);\n"
- "#ifdef THE_ZERO_TO_ONE_DEPTH\n"
- " aProjCoords.xy = aProjCoords.xy * 0.5 + vec2 (0.5);\n"
- "#else\n"
- " aProjCoords = aProjCoords * 0.5 + vec3 (0.5);\n"
- "#endif\n"
- " float aCurrentDepth = aProjCoords.z;\n"
- " if (aProjCoords.x < 0.0 || aProjCoords.x > 1.0\n"
- " || aProjCoords.y < 0.0 || aProjCoords.y > 1.0\n"
- " || aCurrentDepth > 1.0)\n"
- " {\n"
- " return 1.0;\n"
- " }\n"
- "\n"
- " vec2 aTexelSize = vec2 (occShadowMapSizeBias.x);\n"
- " float aBias = max (occShadowMapSizeBias.y * (1.0 - dot (theNormal, aLightDir)), occShadowMapSizeBias.y * 0.1);\n"
- "#if (__VERSION__ >= 120)\n"
- " float aShadow = 0.0;\n"
- " for (int aPosIter = 0; aPosIter < 16; ++aPosIter)\n"
- " {\n"
- " float aClosestDepth = occTexture2D (theShadow, aProjCoords.xy + occPoissonDisk16[aPosIter] * aTexelSize).r;\n"
- " aShadow += (aCurrentDepth - aBias) > aClosestDepth ? 1.0 : 0.0;\n"
- " }\n"
- " return 1.0 - aShadow / 16.0;\n"
- "#else\n"
- " float aClosestDepth = occTexture2D (theShadow, aProjCoords.xy).r;\n"
- " float aShadow = (aCurrentDepth - aBias) > aClosestDepth ? 1.0 : 0.0;\n"
- " return 1.0 - aShadow;\n"
- "#endif\n"
- "}\n";
--- /dev/null
+// This file has been automatically generated from resource file src/Shaders/LightShadow.glsl
+
+static const char Shaders_LightShadow_glsl[] =
+ "#if (__VERSION__ >= 120)\n"
+ "//! Coefficients for gathering close samples for antialiasing.\n"
+ "//! Use only with decent OpenGL (array constants cannot be initialized with GLSL 1.1 / GLSL ES 1.1)\n"
+ "const vec2 occPoissonDisk16[16] = vec2[](\n"
+ " vec2(-0.94201624,-0.39906216), vec2( 0.94558609,-0.76890725), vec2(-0.09418410,-0.92938870), vec2( 0.34495938, 0.29387760),\n"
+ " vec2(-0.91588581, 0.45771432), vec2(-0.81544232,-0.87912464), vec2(-0.38277543, 0.27676845), vec2( 0.97484398, 0.75648379),\n"
+ " vec2( 0.44323325,-0.97511554), vec2( 0.53742981,-0.47373420), vec2(-0.26496911,-0.41893023), vec2( 0.79197514, 0.19090188),\n"
+ " vec2(-0.24188840, 0.99706507), vec2(-0.81409955, 0.91437590), vec2( 0.19984126, 0.78641367), vec2( 0.14383161,-0.14100790)\n"
+ ");\n"
+ "#endif\n"
+ "\n"
+ "//! Function computes directional and spot light shadow attenuation (1.0 means no shadow).\n"
+ "float occLightShadow (in sampler2D theShadow,\n"
+ " in int theId,\n"
+ " in vec3 theNormal)\n"
+ "{\n"
+ " vec4 aPosLightSpace = PosLightSpace[occLight_Index(theId)];\n"
+ " vec3 aLightDir = occLight_Position (theId);\n"
+ " vec3 aProjCoords = (aPosLightSpace.xyz / aPosLightSpace.w);\n"
+ "#ifdef THE_ZERO_TO_ONE_DEPTH\n"
+ " aProjCoords.xy = aProjCoords.xy * 0.5 + vec2 (0.5);\n"
+ "#else\n"
+ " aProjCoords = aProjCoords * 0.5 + vec3 (0.5);\n"
+ "#endif\n"
+ " float aCurrentDepth = aProjCoords.z;\n"
+ " if (aProjCoords.x < 0.0 || aProjCoords.x > 1.0\n"
+ " || aProjCoords.y < 0.0 || aProjCoords.y > 1.0\n"
+ " || aCurrentDepth > 1.0)\n"
+ " {\n"
+ " return 1.0;\n"
+ " }\n"
+ "\n"
+ " vec2 aTexelSize = vec2 (occShadowMapSizeBias.x);\n"
+ " float aBias = max (occShadowMapSizeBias.y * (1.0 - dot (theNormal, aLightDir)), occShadowMapSizeBias.y * 0.1);\n"
+ "#if (__VERSION__ >= 120)\n"
+ " float aShadow = 0.0;\n"
+ " for (int aPosIter = 0; aPosIter < 16; ++aPosIter)\n"
+ " {\n"
+ " float aClosestDepth = occTexture2D (theShadow, aProjCoords.xy + occPoissonDisk16[aPosIter] * aTexelSize).r;\n"
+ " aShadow += (aCurrentDepth - aBias) > aClosestDepth ? 1.0 : 0.0;\n"
+ " }\n"
+ " return 1.0 - aShadow / 16.0;\n"
+ "#else\n"
+ " float aClosestDepth = occTexture2D (theShadow, aProjCoords.xy).r;\n"
+ " float aShadow = (aCurrentDepth - aBias) > aClosestDepth ? 1.0 : 0.0;\n"
+ " return 1.0 - aShadow;\n"
+ "#endif\n"
+ "}\n";
" in vec3 theNormal,\n"
" in vec3 theView,\n"
" in vec3 thePoint,\n"
- " in bool theIsFront)\n"
+ " in bool theIsFront,\n"
+ " in float theShadow)\n"
"{\n"
" vec3 aLight = occLight_Position (theId) - thePoint;\n"
"\n"
" DirectLighting += occPBRIllumination (theView, aLight, theNormal,\n"
" BaseColor, Metallic, Roughness, IOR,\n"
" occLight_Specular(theId),\n"
- " occLight_Intensity(theId) * anAtten);\n"
+ " occLight_Intensity(theId) * anAtten) * theShadow;\n"
"}\n";
"//! @param theView view direction\n"
"//! @param thePoint 3D position (world space)\n"
"//! @param theIsFront front/back face flag\n"
+ "//! @param theShadow the value from shadow map\n"
"void occSpotLight (in int theId,\n"
" in vec3 theNormal,\n"
" in vec3 theView,\n"
" in vec3 thePoint,\n"
- " in bool theIsFront)\n"
+ " in bool theIsFront,\n"
+ " in float theShadow)\n"
"{\n"
" vec3 aLight = occLight_Position (theId) - thePoint;\n"
"\n"
" aSpecl = pow (aNdotH, occMaterial_Shininess (theIsFront));\n"
" }\n"
"\n"
- " Diffuse += occLight_Diffuse (theId) * aNdotL * anAtten;\n"
- " Specular += occLight_Specular(theId) * aSpecl * anAtten;\n"
+ " Diffuse += occLight_Diffuse (theId) * aNdotL * anAtten * theShadow;\n"
+ " Specular += occLight_Specular(theId) * aSpecl * anAtten * theShadow;\n"
"}\n";
<< (aLight->IsEnabled() ? "ON" : "OFF") << "\n";
switch (aLight->Type())
{
- case V3d_AMBIENT:
+ case Graphic3d_TypeOfLightSource_Ambient:
{
theDi << " Type: Ambient\n"
<< " Intensity: " << aLight->Intensity() << "\n";
break;
}
- case V3d_DIRECTIONAL:
+ case Graphic3d_TypeOfLightSource_Directional:
{
theDi << " Type: Directional\n"
<< " Intensity: " << aLight->Intensity() << "\n"
<< " Direction: " << aLight->PackedDirection().x() << " " << aLight->PackedDirection().y() << " " << aLight->PackedDirection().z() << "\n";
break;
}
- case V3d_POSITIONAL:
+ case Graphic3d_TypeOfLightSource_Positional:
{
theDi << " Type: Positional\n"
<< " Intensity: " << aLight->Intensity() << "\n"
<< " Range: " << aLight->Range() << "\n";
break;
}
- case V3d_SPOT:
+ case Graphic3d_TypeOfLightSource_Spot:
{
theDi << " Type: Spot\n"
<< " Intensity: " << aLight->Intensity() << "\n"
-spotAngle sets spotlight angle;
-spotExp sets spotlight exponenta;
-headlight sets headlight flag;
+ -castShadows enables/disables shadow casting;
-constAtten (obsolete) sets constant attenuation factor;
-linearAtten (obsolete) sets linear attenuation factor.
--- /dev/null
+puts "========"
+puts "0032172: Visualization, TKOpenGl - implement simple shadow mapping for a spot light source"
+puts "Test shadow map from a spot light source on a box geometry."
+puts "========"
+
+pload MODELING VISUALIZATION
+if { $::tcl_platform(os) == "Darwin" } { vcaps -core }
+box b 1 2 3
+box bb -5 -5 0 10 10 0 -preview
+vclear
+vinit View1
+vrenderparams -shadingModel phong
+vdisplay -dispMode 1 b bb
+vaspects b -material STONE -color blue
+vaspects bb -material STONE -color red
+vfit
+vlight -clear
+vlight lamp1 -add spot -castShadows 1 -direction 1 1 -1 -position -10 -10 10
+vlight lamp2 -add spot -castShadows 1 -direction -1 -1 -1 -position 10 10 10 -intensity 1000
+vdump $::imagedir/${::casename}_two_spots.png
+
+vlight -remove lamp1
+
+vline lin1 10 10 10 -5 -5 -0.5
+vline lin2 10 10 10 -3.5 -5 -0.5
+vline lin3 10 10 10 -5 -2 -0.5
+
+if { ![string match "OpenGL ES 2.0*" [vglinfo VERSION]] && ![string match "OpenGL ES 3.0*" [vglinfo VERSION]] } {
+ vraytrace 1
+ vdump $::imagedir/${::casename}_raytrace.png
+}
+
+vraytrace 0
+vrenderparams -shadingModel phong
+vrenderparams -shadowMapBias 0.001
+vdump $::imagedir/${::casename}_phong.png
+
+vrenderparams -shadingModel pbr
+vdump $::imagedir/${::casename}_pbr.png