EOL" in bool theIsFront,"
EOL" in float theShadow)"
EOL"{"
- EOL" vec3 aLight = vec3 (occWorldViewMatrix * vec4 (occLight_Position (0), 0.0));"
+ EOL" vec3 aLight = occLight_Position (0);"
EOL
EOL" vec3 aHalf = normalize (aLight + theView);"
EOL
if ((theBits & Graphic3d_ShaderFlags_ClipPlanesN) != 0)
{
aStageInOuts.Append (Graphic3d_ShaderObject::ShaderVariable ("vec4 PositionWorld", Graphic3d_TOS_VERTEX | Graphic3d_TOS_FRAGMENT));
- aStageInOuts.Append (Graphic3d_ShaderObject::ShaderVariable ("vec4 Position", Graphic3d_TOS_VERTEX | Graphic3d_TOS_FRAGMENT));
aSrcVertExtraMain +=
- EOL" PositionWorld = occModelWorldMatrix * occVertex;"
- EOL" Position = occWorldViewMatrix * PositionWorld;";
+ EOL" PositionWorld = occModelWorldMatrix * occVertex;";
if ((theBits & Graphic3d_ShaderFlags_ClipPlanesN) == Graphic3d_ShaderFlags_ClipPlanesN)
{
if ((theBits & Graphic3d_ShaderFlags_ClipPlanesN) != 0)
{
aStageInOuts.Append (Graphic3d_ShaderObject::ShaderVariable ("vec4 PositionWorld", Graphic3d_TOS_VERTEX | Graphic3d_TOS_FRAGMENT));
- aStageInOuts.Append (Graphic3d_ShaderObject::ShaderVariable ("vec4 Position", Graphic3d_TOS_VERTEX | Graphic3d_TOS_FRAGMENT));
aSrcVertExtraMain +=
- EOL" PositionWorld = aPositionWorld;"
- EOL" Position = aPosition;";
+ EOL" PositionWorld = aPositionWorld;";
if ((theBits & Graphic3d_ShaderFlags_ClipPlanesN) == Graphic3d_ShaderFlags_ClipPlanesN)
{
Standard_Integer aNbLights = 0;
const TCollection_AsciiString aLights = stdComputeLighting (aNbLights, theLights, !aSrcVertColor.IsEmpty(), false, toUseTexColor, 0);
aSrcVert = TCollection_AsciiString()
- + THE_FUNC_transformNormal_view
+ + THE_FUNC_transformNormal_world
+ EOL
+ aSrcVertColor
+ aLights
+ EOL"void main()"
EOL"{"
EOL" vec4 aPositionWorld = occModelWorldMatrix * occVertex;"
- EOL" vec4 aPosition = occWorldViewMatrix * aPositionWorld;"
EOL" vec3 aNormal = transformNormal (occNormal);"
- EOL" vec3 aView = vec3 (0.0, 0.0, 1.0);"
- EOL" FrontColor = computeLighting (aNormal, aView, aPosition, true);"
- EOL" BackColor = computeLighting (aNormal, aView, aPosition, false);"
+ EOL" vec3 aView = (occWorldViewMatrixInverse * vec4(0.0, 0.0, 1.0, 0.0)).xyz;"
+ EOL" FrontColor = computeLighting (aNormal, aView, aPositionWorld, true);"
+ EOL" BackColor = computeLighting (aNormal, aView, aPositionWorld, false);"
+ aSrcVertExtraMain
+ THE_VERT_gl_Position
+ EOL"}";
const Standard_Boolean theIsPBR,
const Standard_Integer theNbShadowMaps) const
{
- TCollection_AsciiString aPosition = theIsPBR ? "PositionWorld" : "Position";
TCollection_AsciiString aPhongCompLight = TCollection_AsciiString() +
- "computeLighting (normalize (Normal), normalize (View), " + aPosition + ", gl_FrontFacing)";
+ "computeLighting (normalize (Normal), normalize (View), PositionWorld, gl_FrontFacing)";
const bool isFlatNormal = theIsFlatNormal && myHasFlatShading;
const char* aDFdxSignReversion = myToReverseDFdxSign ? "-" : "";
bool toUseTexColor = false;
if (isFlatNormal)
{
aSrcFragExtraMain += TCollection_AsciiString()
- + EOL" Normal = " + aDFdxSignReversion + "normalize (cross (dFdx (" + aPosition + ".xyz / " + aPosition + ".w), dFdy (" + aPosition + ".xyz / " + aPosition + ".w)));"
+ + EOL" Normal = " + aDFdxSignReversion + "normalize (cross (dFdx (PositionWorld.xyz / PositionWorld.w), dFdy (PositionWorld.xyz / PositionWorld.w)));"
EOL" if (!gl_FrontFacing) { Normal = -Normal; }";
}
else
EOL" }"
EOL"#endif";
}
- if (!theIsPBR)
- {
- aSrcFragExtraMain +=
- EOL" Normal = normalize ((occWorldViewMatrixInverseTranspose * vec4 (Normal, 0.0)).xyz);";
- }
}
aStageInOuts.Append (Graphic3d_ShaderObject::ShaderVariable ("vec4 PositionWorld", Graphic3d_TOS_VERTEX | Graphic3d_TOS_FRAGMENT));
- aStageInOuts.Append (Graphic3d_ShaderObject::ShaderVariable ("vec4 Position", Graphic3d_TOS_VERTEX | Graphic3d_TOS_FRAGMENT));
aStageInOuts.Append (Graphic3d_ShaderObject::ShaderVariable ("vec3 View", Graphic3d_TOS_VERTEX | Graphic3d_TOS_FRAGMENT));
if (theNbShadowMaps > 0)
{
+ EOL"void main()"
EOL"{"
EOL" PositionWorld = occModelWorldMatrix * occVertex;"
- EOL" Position = occWorldViewMatrix * PositionWorld;"
EOL" if (occProjectionMatrix[3][3] == 1.0)"
EOL" {"
EOL" View = vec3(0.0, 0.0, 1.0);"
EOL" }"
EOL" else"
EOL" {"
- EOL" View = -Position.xyz;"
+ EOL" vec4 aPosition = occWorldViewMatrix * PositionWorld;"
+ EOL" View = -aPosition.xyz;"
EOL" }"
- + (theIsPBR ? EOL" View = (occWorldViewMatrixInverse * vec4(View, 0.0)).xyz;" : "")
+ EOL" View = (occWorldViewMatrixInverse * vec4(View, 0.0)).xyz;"
+ aSrcVertExtraMain
+ THE_VERT_gl_Position
+ EOL"}";
//! @param theId light source index
//! @param theNormal surface normal
//! @param theView view direction
-//! @param thePoint 3D position (view space)
+//! @param thePoint 3D position (world space)
//! @param theIsFront front/back face flag
void occSpotLight (in int theId,
in vec3 theNormal,
in vec3 thePoint,
in bool theIsFront)
{
- vec3 aLight = vec3 (occWorldViewMatrix * vec4 (occLight_Position (theId), 1.0)) - thePoint;
+ vec3 aLight = occLight_Position (theId) - thePoint;
float aDist = length (aLight);
float aRange = occLight_Range (theId);
if (anAtten <= 0.0) return;
aLight /= aDist;
- vec3 aSpotDir = vec3 (occWorldViewMatrix * vec4 (occLight_SpotDirection (theId), 0.0));
- aSpotDir = normalize (aSpotDir);
+ vec3 aSpotDir = occLight_SpotDirection (theId);
// light cone
float aCosA = dot (aSpotDir, -aLight);
if (aCosA >= 1.0 || aCosA < cos (occLight_SpotCutOff (theId)))
"//! @param theId light source index\n"
"//! @param theNormal surface normal\n"
"//! @param theView view direction\n"
- "//! @param thePoint 3D position (view space)\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 thePoint,\n"
" in bool theIsFront)\n"
"{\n"
- " vec3 aLight = vec3 (occWorldViewMatrix * vec4 (occLight_Position (theId), 1.0)) - thePoint;\n"
+ " vec3 aLight = occLight_Position (theId) - thePoint;\n"
"\n"
" float aDist = length (aLight);\n"
" float aRange = occLight_Range (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"
+ " vec3 aSpotDir = occLight_SpotDirection (theId);\n"
" // light cone\n"
" float aCosA = dot (aSpotDir, -aLight);\n"
" if (aCosA >= 1.0 || aCosA < cos (occLight_SpotCutOff (theId)))\n"