1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-09-03 14:10:33 +03:00

0031099: Visualization, TKOpenGl - support Point light source with artistic full cut-off distance

"Range" parameter of point light sources (positional and spot) concidering in PBR has been added.
Angular attenuation parameter of spot light in PBR has been reimplemented based on existing "concentration" parameter.
This commit is contained in:
iko
2019-12-24 16:05:00 +03:00
committed by bugmaster
parent 0858125fd4
commit 88b312d3a4
12 changed files with 232 additions and 27 deletions

View File

@@ -156,6 +156,9 @@ uniform THE_PREC_ENUM int occLightSourcesCount; //!< Total number of light sour
//! Direction of specified spot light source, vec3.
#define occLight_SpotDirection(theId) occLightSources[theId * 4 + 2].xyz
//! Range on which point light source (positional or spot) can affect (>= 0), float.
#define occLight_Range(theId) occLightSources[theId * 4 + 2].w
//! Maximum spread angle of the spot light (in radians), float.
#define occLight_SpotCutOff(theId) occLightSources[theId * 4 + 3].z

View File

@@ -9,6 +9,7 @@ srcinc:::PBRGeometry.glsl
srcinc:::PBRIllumination.glsl
srcinc:::PhongShading.fs
srcinc:::PhongShading.vs
srcinc:::PointLightAttenuation.glsl
srcinc:::Display.fs
srcinc:::RaytraceBase.fs
srcinc:::RaytraceRender.fs
@@ -25,6 +26,7 @@ Shaders_PBREnvBaking_vs.pxx
Shaders_PBRFresnel_glsl.pxx
Shaders_PBRGeometry_glsl.pxx
Shaders_PBRIllumination_glsl.pxx
Shaders_PointLightAttenuation_glsl.pxx
Shaders_RaytraceBase_fs.pxx
Shaders_RaytraceRender_fs.pxx
Shaders_PathtraceBase_fs.pxx

View File

@@ -0,0 +1,35 @@
//! Returns point light source attenuation factor
float occRangedPointLightAttenuation (in float theDistance, in float theRange)
{
if (theDistance <= theRange)
{
float aResult = theDistance / theRange;
aResult *= aResult;
aResult *= aResult;
aResult = 1.0 - aResult;
aResult = clamp(aResult, 0.0, 1.0);
aResult /= max(0.0001, theDistance * theDistance);
return aResult;
}
return -1.0;
}
//! Returns point light source attenuation factor with quadratic attenuation in case of zero range.
float occPointLightAttenuation (in float theDistance, in float theRange)
{
if (theRange == 0.0)
{
return 1.0 / max(0.0001, theDistance * theDistance);
}
return occRangedPointLightAttenuation (theDistance, theRange);
}
//! Returns point light source attenuation factor with linear attenuation in case of zero range.
float occPointLightAttenuation (in float theDistance, in float theRange, in float theLinearAttenuation, in float theConstAttenuation)
{
if (theRange == 0.0)
{
return 1.0 / (theConstAttenuation + theLinearAttenuation * theDistance);
}
return occRangedPointLightAttenuation (theDistance, theRange);
}

View File

@@ -159,6 +159,9 @@ static const char Shaders_Declarations_glsl[] =
"//! Direction of specified spot light source, vec3.\n"
"#define occLight_SpotDirection(theId) occLightSources[theId * 4 + 2].xyz\n"
"\n"
"//! Range on which point light source (positional or spot) can affect (>= 0), float.\n"
"#define occLight_Range(theId) occLightSources[theId * 4 + 2].w\n"
"\n"
"//! Maximum spread angle of the spot light (in radians), float.\n"
"#define occLight_SpotCutOff(theId) occLightSources[theId * 4 + 3].z\n"
"\n"

View File

@@ -0,0 +1,38 @@
// This file has been automatically generated from resource file src/Shaders/PointLightAttenuation.glsl
static const char Shaders_PointLightAttenuation_glsl[] =
"//! Returns point light source attenuation factor\n"
"float occRangedPointLightAttenuation (in float theDistance, in float theRange)\n"
"{\n"
" if (theDistance <= theRange)\n"
" {\n"
" float aResult = theDistance / theRange;\n"
" aResult *= aResult;\n"
" aResult *= aResult;\n"
" aResult = 1.0 - aResult;\n"
" aResult = clamp(aResult, 0.0, 1.0);\n"
" aResult /= max(0.0001, theDistance * theDistance);\n"
" return aResult;\n"
" }\n"
" return -1.0;\n"
"}\n"
"\n"
"//! Returns point light source attenuation factor with quadratic attenuation in case of zero range.\n"
"float occPointLightAttenuation (in float theDistance, in float theRange)\n"
"{\n"
" if (theRange == 0.0)\n"
" {\n"
" return 1.0 / max(0.0001, theDistance * theDistance);\n"
" }\n"
" return occRangedPointLightAttenuation (theDistance, theRange);\n"
"}\n"
"\n"
"//! Returns point light source attenuation factor with linear attenuation in case of zero range.\n"
"float occPointLightAttenuation (in float theDistance, in float theRange, in float theLinearAttenuation, in float theConstAttenuation)\n"
"{\n"
" if (theRange == 0.0)\n"
" {\n"
" return 1.0 / (theConstAttenuation + theLinearAttenuation * theDistance);\n"
" }\n"
" return occRangedPointLightAttenuation (theDistance, theRange);\n"
"}\n";