summaryrefslogtreecommitdiffstats
path: root/res
diff options
context:
space:
mode:
authorAndy Nichols <andy.nichols@qt.io>2017-12-05 16:02:54 +0100
committerLaszlo Agocs <laszlo.agocs@qt.io>2017-12-07 14:07:30 +0000
commit71b625cdebae8f15a7e3a9c861a2628099254bb7 (patch)
treea4e606a8ecb5262e5b57f2c09d0d27b75b9ce079 /res
parent6a44253da49d6818d70662ae07465765bf71d288 (diff)
Integrate Custom Material + Shader Generators
Change-Id: I15290541bfb58bb194d70cfe9004af1033bb8fb2 Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
Diffstat (limited to 'res')
-rw-r--r--res/effectlib/sampleArea.glsllib43
1 files changed, 43 insertions, 0 deletions
diff --git a/res/effectlib/sampleArea.glsllib b/res/effectlib/sampleArea.glsllib
index ca04988..7b1d142 100644
--- a/res/effectlib/sampleArea.glsllib
+++ b/res/effectlib/sampleArea.glsllib
@@ -75,6 +75,49 @@ float getUVHitBounds( in vec3 pos, in mat3 lightFrame, in vec3 lightPos, in floa
return wtsum;
}
+// Shooting a narrow beam, and then scaling up that beam based on the actual roughness
+vec4 sampleAreaGlossy( in mat3 tanFrame, in vec3 pos, in int lightIdx, in vec3 viewDir, in float roughU, in float roughV )
+{
+ float sigmaU = clamp( 0.5 * roughU, 0.005, 0.5 );
+ float sigmaV = clamp( 0.5 * roughV, 0.005, 0.5 );
+ vec2 UVset[5];
+
+ mat3 lightFrame = mat3( arealights[lightIdx].right.xyz, arealights[lightIdx].up.xyz, arealights[lightIdx].direction.xyz );
+
+ float thetaI = acos( dot(viewDir, lightFrame[2]) );
+ vec2 minMaxThetaH = vec2( (thetaI - 1.5707) * 0.5,
+ (thetaI + 1.5707) * 0.5 );
+ vec4 sinCosThetaH = vec4( abs(sin(minMaxThetaH)), abs(cos(minMaxThetaH)) );
+
+ // First thing we do is compute a small-scale version of the ray hit for a very tiny roughness
+ // then we scale that up based on the _actual_ roughness.
+ float wt = computeMicroHit( pos, tanFrame, arealights[lightIdx].position.xyz, lightFrame,
+ arealights[lightIdx].right.w, arealights[lightIdx].up.w, viewDir, UVset );
+ UVset[0] -= UVset[4]; UVset[1] -= UVset[4];
+ UVset[2] -= UVset[4]; UVset[3] -= UVset[4];
+
+ UVset[0] *= mix(1.0, sinCosThetaH.y / 0.005, sigmaU); UVset[1] *= mix(1.0, sinCosThetaH.x / 0.005, sigmaU);
+ UVset[2] *= mix(1.0, sinCosThetaH.y / 0.005, sigmaV); UVset[3] *= mix(1.0, sinCosThetaH.x / 0.005, sigmaV);
+
+ UVset[0] += UVset[4]; UVset[1] += UVset[4];
+ UVset[2] += UVset[4]; UVset[3] += UVset[4];
+
+ vec2 UVmin = UVset[4], UVmax = UVset[4];
+ vec2 cminUV, cmaxUV;
+ UVmin = min(UVmin, UVset[0]); UVmax = max(UVmax, UVset[0]);
+ UVmin = min(UVmin, UVset[1]); UVmax = max(UVmax, UVset[1]);
+ UVmin = min(UVmin, UVset[2]); UVmax = max(UVmax, UVset[2]);
+ UVmin = min(UVmin, UVset[3]); UVmax = max(UVmax, UVset[3]);
+
+ cminUV = clamp( UVmin, vec2(0.0), vec2(1.0) );
+ cmaxUV = clamp( UVmax, vec2(0.0), vec2(1.0) );
+
+ vec2 hitScale = (cmaxUV - cminUV);
+ vec2 fullScale = (UVmax - UVmin);
+ float intensity = ( hitScale.x * hitScale.y ) / max( fullScale.x * fullScale.y, 0.0001 );
+
+ return vec4( wt * intensity );
+}
vec4 sampleAreaDiffuse( in mat3 tanFrame, in vec3 pos, in int lightIdx )
{