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/funccomputeMicroHit.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/funccomputeMicroHit.glsllib')
-rw-r--r-- | res/effectlib/funccomputeMicroHit.glsllib | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/res/effectlib/funccomputeMicroHit.glsllib b/res/effectlib/funccomputeMicroHit.glsllib new file mode 100644 index 0000000..7c52691 --- /dev/null +++ b/res/effectlib/funccomputeMicroHit.glsllib @@ -0,0 +1,50 @@ +bool rayToLightUV( in vec3 pos, in mat3 lightFrame, in vec3 lightPos, in float width, in float height, in vec3 rayDir, out vec2 uv ) +{ + float d0 = dot( lightPos, lightFrame[2] ); + float d1 = dot( pos, lightFrame[2] ); + float fac = dot( rayDir, lightFrame[2] ); + + if ((d0 < d1) || ( fac < 0.001 )) + { + uv = vec2(-1.0); + return false; + } + + float t = (d0 - d1) / fac; + vec3 hitPos = pos + t * rayDir; + width *= dot(lightFrame[0], lightFrame[0]); + height *= dot(lightFrame[1], lightFrame[1]); + + hitPos -= lightPos; + uv.x = ( dot(hitPos, lightFrame[0]) / width ) + 0.5; + uv.y = ( dot(hitPos, lightFrame[1]) / height ) + 0.5; + return true; +} + +float computeMicroHit( in vec3 pos, in mat3 tanFrame, in vec3 lightPos, in mat3 lightFrame, in float width, in float height, in vec3 viewDir, out vec2 UV[5] ) +{ + vec3 rayDir = reflect( -viewDir, tanFrame[2] ); + vec2 ctrUV; + bool isHit = rayToLightUV( pos, lightFrame, lightPos, width, height, rayDir, ctrUV ); + if ((!isHit) || ( dot(rayDir, tanFrame[2]) < 0.001 )) { return 0.0; } + + vec3 H0 = 0.99749686716 * tanFrame[2] + 0.005 * tanFrame[0]; + vec3 H1 = 0.99749686716 * tanFrame[2] - 0.005 * tanFrame[0]; + vec3 H2 = 0.99749686716 * tanFrame[2] + 0.005 * tanFrame[1]; + vec3 H3 = 0.99749686716 * tanFrame[2] - 0.005 * tanFrame[1]; + + vec3 R[4]; + R[0] = reflect( -viewDir, H0 ); + R[1] = reflect( -viewDir, H1 ); + R[2] = reflect( -viewDir, H2 ); + R[3] = reflect( -viewDir, H3 ); + + rayToLightUV( pos, lightFrame, lightPos, width, height, R[0], UV[0] ); + rayToLightUV( pos, lightFrame, lightPos, width, height, R[1], UV[1] ); + rayToLightUV( pos, lightFrame, lightPos, width, height, R[2], UV[2] ); + rayToLightUV( pos, lightFrame, lightPos, width, height, R[3], UV[3] ); + + UV[4] = ctrUV; + + return clamp( dot(rayDir, tanFrame[2]), 0.0, 1.0 ); +} |