Loading files
3d097a032This file is pinned to the selected release. Download the original to open it in your design tool.
// Copyright (c) 2025 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
// clang-format off
// This file has been automatically generated from resource file resources/Shaders/PhongShading.fs
static const char Shaders_PhongShading_fs[] =
"// Created on: 2013-10-10\n"
"// Created by: Denis BOGOLEPOV\n"
"// Copyright (c) 2013-2014 OPEN CASCADE SAS\n"
"//\n"
"// This file is part of Open CASCADE Technology software library.\n"
"//\n"
"// This library is free software; you can redistribute it and/or modify it under\n"
"// the terms of the GNU Lesser General Public License version 2.1 as published\n"
"// by the Free Software Foundation, with special exception defined in the file\n"
"// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT\n"
"// distribution for complete text of the license and disclaimer of any warranty.\n"
"//\n"
"// Alternatively, this file may be used under the terms of Open CASCADE\n"
"// commercial license or contractual agreement.\n"
"\n"
"varying vec3 View; //!< Direction to the viewer\n"
"varying vec3 Normal; //!< Vertex normal in view space\n"
"varying vec4 Position; //!< Vertex position in view space.\n"
"varying vec4 PositionWorld; //!< Vertex position in world space\n"
"\n"
"vec3 Ambient; //!< Ambient contribution of light sources\n"
"vec3 Diffuse; //!< Diffuse contribution of light sources\n"
"vec3 Specular; //!< Specular contribution of light sources\n"
"\n"
"//! Computes contribution of isotropic point light source\n"
"void pointLight (in int theId,\n"
" in vec3 theNormal,\n"
" in vec3 theView,\n"
" in vec3 thePoint)\n"
"{\n"
" vec3 aLight = occLight_Position (theId).xyz;\n"
" if (!occLight_IsHeadlight (theId))\n"
" {\n"
" aLight = vec3 (occWorldViewMatrix * vec4 (aLight, 1.0));\n"
" }\n"
" aLight -= thePoint;\n"
"\n"
" float aDist = length (aLight);\n"
" aLight = aLight * (1.0 / aDist);\n"
"\n"
" float anAtten = 1.0 / (occLight_ConstAttenuation (theId)\n"
" + occLight_LinearAttenuation (theId) * aDist);\n"
"\n"
" vec3 aHalf = normalize (aLight + theView);\n"
"\n"
" vec3 aFaceSideNormal = gl_FrontFacing ? 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, occMaterial_Shininess (gl_FrontFacing));\n"
" }\n"
"\n"
" Diffuse += occLight_Diffuse (theId).rgb * aNdotL * anAtten;\n"
" Specular += occLight_Specular (theId).rgb * aSpecl * anAtten;\n"
"}\n"
"\n"
"//! Computes contribution of spotlight source\n"
"void spotLight (in int theId,\n"
" in vec3 theNormal,\n"
" in vec3 theView,\n"
" in vec3 thePoint)\n"
"{\n"
" vec3 aLight = occLight_Position (theId).xyz;\n"
" vec3 aSpotDir = occLight_SpotDirection (theId).xyz;\n"
" if (!occLight_IsHeadlight (theId))\n"
" {\n"
" aLight = vec3 (occWorldViewMatrix * vec4 (aLight, 1.0));\n"
" aSpotDir = vec3 (occWorldViewMatrix * vec4 (aSpotDir, 0.0));\n"
" }\n"
" aLight -= thePoint;\n"
"\n"
" float aDist = length (aLight);\n"
" aLight = aLight * (1.0 / aDist);\n"
"\n"
" aSpotDir = normalize (aSpotDir);\n"
"\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"
" float anAtten = 1.0 / (occLight_ConstAttenuation (theId)\n"
" + occLight_LinearAttenuation (theId) * aDist);\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 = gl_FrontFacing ? 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, occMaterial_Shininess (gl_FrontFacing));\n"
" }\n"
"\n"
" Diffuse += occLight_Diffuse (theId).rgb * aNdotL * anAtten;\n"
" Specular += occLight_Specular (theId).rgb * aSpecl * anAtten;\n"
"}\n"
"\n"
"//! Computes contribution of directional light source\n"
"void directionalLight (in int theId,\n"
" in vec3 theNormal,\n"
" in vec3 theView)\n"
"{\n"
" vec3 aLight = normalize (occLight_Position (theId).xyz);\n"
" if (!occLight_IsHeadlight (theId))\n"
" {\n"
" aLight = vec3 (occWorldViewMatrix * vec4 (aLight, 0.0));\n"
" }\n"
"\n"
" vec3 aHalf = normalize (aLight + theView);\n"
"\n"
" vec3 aFaceSideNormal = gl_FrontFacing ? 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, occMaterial_Shininess (gl_FrontFacing));\n"
" }\n"
"\n"
" Diffuse += occLight_Diffuse (theId).rgb * aNdotL;\n"
" Specular += occLight_Specular (theId).rgb * aSpecl;\n"
"}\n"
"\n"
"//! Computes illumination from light sources\n"
"vec4 computeLighting (in vec3 theNormal,\n"
" in vec3 theView,\n"
" in vec4 thePoint)\n"
"{\n"
" // Clear the light intensity accumulators\n"
" Ambient = occLightAmbient.rgb;\n"
" Diffuse = vec3 (0.0);\n"
" Specular = vec3 (0.0);\n"
" vec3 aPoint = thePoint.xyz / thePoint.w;\n"
" for (int anIndex = 0; anIndex < occLightSourcesCount; ++anIndex)\n"
" {\n"
" int aType = occLight_Type (anIndex);\n"
" if (aType == OccLightType_Direct)\n"
" {\n"
" directionalLight (anIndex, theNormal, theView);\n"
" }\n"
" else if (aType == OccLightType_Point)\n"
" {\n"
" pointLight (anIndex, theNormal, theView, aPoint);\n"
" }\n"
" else if (aType == OccLightType_Spot)\n"
" {\n"
" spotLight (anIndex, theNormal, theView, aPoint);\n"
" }\n"
" }\n"
"\n"
" vec3 aMatAmbient = occMaterial_Ambient (gl_FrontFacing);\n"
" vec4 aMatDiffuse = occMaterial_Diffuse (gl_FrontFacing);\n"
" vec3 aMatSpecular = occMaterial_Specular(gl_FrontFacing);\n"
" vec3 aMatEmission = occMaterial_Emission(gl_FrontFacing);\n"
" vec3 aColor = Ambient * aMatAmbient.rgb\n"
" + Diffuse * aMatDiffuse.rgb\n"
" + Specular * aMatSpecular.rgb\n"
" + aMatEmission.rgb;\n"
" return vec4 (aColor, aMatDiffuse.a);\n"
"}\n"
"\n"
"//! Entry point to the Fragment Shader\n"
"void main()\n"
"{\n"
" // process clipping planes\n"
" for (int anIndex = 0; anIndex < occClipPlaneCount; ++anIndex)\n"
" {\n"
" vec4 aClipEquation = occClipPlaneEquations[anIndex];\n"
" if (dot (aClipEquation.xyz, PositionWorld.xyz / PositionWorld.w) + aClipEquation.w < 0.0)\n"
" {\n"
" discard;\n"
" }\n"
" }\n"
"\n"
" vec4 aColor = computeLighting (normalize (Normal), normalize (View), Position);\n"
" occSetFragColor (aColor);\n"
"}\n";
// clang-format on