diff options
author | Pasi Keränen <pasi.keranen@qt.io> | 2019-06-06 16:22:02 +0300 |
---|---|---|
committer | Pasi Keränen <pasi.keranen@qt.io> | 2019-06-07 13:52:44 +0300 |
commit | b4954701093739e7a4e54a0669f306922d0d4605 (patch) | |
tree | 73d71319a921234f6b507c9098fdc842f7fe06dc /res/effectlib/funccalculateDiffuseAreaOld.glsllib | |
parent | 8548a5f5579e3eee7e5ae6b1f6901dcc8bfee19e (diff) |
Long live the slayer!
Initial commit of OpenGL Runtime to repository.
Based on SHA1 61823aaccc6510699a54b34a2fe3f7523dab3b4e
of qt3dstudio repository.
Task-number: QT3DS-3600
Change-Id: Iaeb80237399f0e5656a19ebec9d1ab3a681d8832
Reviewed-by: Pasi Keränen <pasi.keranen@qt.io>
Diffstat (limited to 'res/effectlib/funccalculateDiffuseAreaOld.glsllib')
-rw-r--r-- | res/effectlib/funccalculateDiffuseAreaOld.glsllib | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/res/effectlib/funccalculateDiffuseAreaOld.glsllib b/res/effectlib/funccalculateDiffuseAreaOld.glsllib new file mode 100644 index 0000000..fc37390 --- /dev/null +++ b/res/effectlib/funccalculateDiffuseAreaOld.glsllib @@ -0,0 +1,29 @@ +float calculateDiffuseAreaOld(in vec3 lightDir, in vec3 lightPos, in vec4 lightUp, + in vec4 lightRt, in vec3 worldPos, out vec3 outDir) +{ + if ( dot( worldPos-lightPos, lightDir) < 0.0 ) + return 0.0; + + vec3 v0 = lightPos - (lightRt.xyz * lightRt.w * 0.5) - (lightUp.xyz * lightUp.w * 0.5); + vec3 v1 = lightPos - (lightRt.xyz * lightRt.w * 0.5) + (lightUp.xyz * lightUp.w * 0.5); + vec3 v2 = lightPos + (lightRt.xyz * lightRt.w * 0.5) + (lightUp.xyz * lightUp.w * 0.5); + vec3 v3 = lightPos + (lightRt.xyz * lightRt.w * 0.5) - (lightUp.xyz * lightUp.w * 0.5); + v0 = normalize( v0 - worldPos ); v1 = normalize( v1 - worldPos ); + v2 = normalize( v2 - worldPos ); v3 = normalize( v3 - worldPos ); + + float a01 = acos( clamp( dot(v0, v1), -1.0, 1.0 ) ); + float a12 = acos( clamp( dot(v1, v2), -1.0, 1.0 ) ); + float a23 = acos( clamp( dot(v2, v3), -1.0, 1.0 ) ); + float a30 = acos( clamp( dot(v3, v0), -1.0, 1.0 ) ); + + outDir = vec3( 0.0 ); + outDir -= normalize(cross( v0, v1 )) * a01; + outDir -= normalize(cross( v1, v2 )) * a12; + outDir -= normalize(cross( v2, v3 )) * a23; + outDir -= normalize(cross( v3, v0 )) * a30; + + float retVal = length(outDir) * 0.15915494309; // solid angle / 2*pi + outDir = normalize(outDir); + retVal *= clamp( dot( worldPos-lightPos, lightDir), 0.0, 1.0 ); + return retVal; +} |