diff options
| author | Miles Macklin <[email protected]> | 2017-06-09 13:41:15 +1200 |
|---|---|---|
| committer | Miles Macklin <[email protected]> | 2017-06-09 13:41:15 +1200 |
| commit | 688b5f42e9bfe498d7af7075d4d8f4429867f3a3 (patch) | |
| tree | 7e0d0e7c95298f0418723abd92f61ac6e16b055e /demo/d3d/shaders/diffuseGS.hlsl | |
| parent | Update README.md (diff) | |
| download | flex-1.2.0.beta.1.tar.xz flex-1.2.0.beta.1.zip | |
1.2.0.beta.11.2.0.beta.1
Diffstat (limited to 'demo/d3d/shaders/diffuseGS.hlsl')
| -rw-r--r-- | demo/d3d/shaders/diffuseGS.hlsl | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/demo/d3d/shaders/diffuseGS.hlsl b/demo/d3d/shaders/diffuseGS.hlsl new file mode 100644 index 0000000..e7a50d8 --- /dev/null +++ b/demo/d3d/shaders/diffuseGS.hlsl @@ -0,0 +1,83 @@ +#include "shaderCommon.h" + +cbuffer constBuf : register(b0) +{ + DiffuseShaderConst gParams; +}; + +static const float2 corners[4] = +{ + float2(0.0, 1.0), + float2(0.0, 0.0), + float2(1.0, 1.0), + float2(1.0, 0.0) +}; + +[maxvertexcount(4)] +void diffuseGS(point DiffuseVertexOut input[1], inout TriangleStream<DiffuseGeometryOut> triStream) +{ + float4 ndcPos = input[0].ndcPos; + + // frustrum culling + const float ndcBound = 1.0; + if (ndcPos.x < -ndcBound) return; + if (ndcPos.x > ndcBound) return; + if (ndcPos.y < -ndcBound) return; + if (ndcPos.y > ndcBound) return; + + float pointScale = gParams.diffuseScale; + float velocityScale = 1.0; + + float3 v = input[0].viewVel.xyz; + float3 p = input[0].viewPos.xyz; + + // billboard in eye space + float3 u = float3(0.0, pointScale, 0.0); + float3 l = float3(pointScale, 0.0, 0.0); + + // increase size based on life + float lifeTime = input[0].worldPos.w; + + float lifeFade = lerp(1.0f + gParams.diffusion, 1.0, min(1.0, lifeTime*0.25f)); + u *= lifeFade; + l *= lifeFade; + + float fade = 1.0/(lifeFade*lifeFade); + float vlen = length(v)*gParams.motionBlurScale; + + if (vlen > 0.5) + { + float len = max(pointScale, vlen*0.016); + fade = min(1.0, 2.0/(len/pointScale)); + + u = normalize(v)*max(pointScale, vlen*0.016); // assume 60hz + l = normalize(cross(u, float3(0.0, 0.0, -1.0)))*pointScale; + } + + { + DiffuseGeometryOut output; + + output.worldPos = input[0].worldPos; // vertex world pos (life in w) + output.viewPos = input[0].viewPos; // vertex eye pos + output.viewVel.xyz = input[0].viewVel.xyz; // vertex velocity in view space + output.viewVel.w = fade; + output.lightDir = mul(gParams.modelView, float4(gParams.lightDir, 0.0)); + output.color = input[0].color; + + output.uv = float2(0.0, 1.0); + output.clipPos = mul(gParams.projection, float4(p + u - l, 1.0)); + triStream.Append(output); + + output.uv = float2(0.0, 0.0); + output.clipPos = mul(gParams.projection, float4(p - u - l, 1.0)); + triStream.Append(output); + + output.uv = float2(1.0, 1.0); + output.clipPos = mul(gParams.projection, float4(p + u + l, 1.0)); + triStream.Append(output); + + output.uv = float2(1.0, 0.0); + output.clipPos = mul(gParams.projection, float4(p - u + l, 1.0)); + triStream.Append(output); + } +} |