| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <!--
- Copyright (C) 2009-2018, Panagiotis Christopoulos Charitos and contributors.
- All rights reserved.
- Code licensed under the BSD License.
- http://www.anki3d.org/LICENSE
- -->
- <shaderProgram>
- <inputs>
- <input name="IN_DEPTH_MAP_SIZE" type="vec2" const="1"/>
- </inputs>
- <shaders>
- <shader type="comp">
- <source><![CDATA[
- #include "shaders/Common.glsl"
- const uint WORKGROUP_SIZE = 8;
- layout(local_size_x = WORKGROUP_SIZE, local_size_y = WORKGROUP_SIZE, local_size_z = 1) in;
- struct DrawArraysIndirectInfo
- {
- uint count;
- uint instanceCount;
- uint first;
- uint baseInstance;
- };
- layout(ANKI_SS_BINDING(0, 0), std430, row_major) readonly buffer ss0_
- {
- mat4 u_mvp;
- vec4 u_flarePositions[];
- };
- layout(ANKI_SS_BINDING(0, 1), std430) writeonly buffer ss1_
- {
- DrawArraysIndirectInfo u_indirectInfo[];
- };
- layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2D u_depthMap;
- shared uint s_maxDepth;
- void main()
- {
- // Init the s_maxDepth
- if(gl_LocalInvocationIndex == 0)
- {
- s_maxDepth = 0;
- }
- memoryBarrierShared();
- barrier();
-
- // Project the flare
- uint flareIdx = gl_WorkGroupID.x;
- vec4 posClip = u_mvp * u_flarePositions[flareIdx];
- vec3 posNdc = posClip.xyz / posClip.w;
- float depth = posNdc.z;
- // Compute the UVs to sample the depth map
- vec2 displacement = vec2(gl_LocalInvocationID.xy) - vec2(WORKGROUP_SIZE / 2u); // [-WORKGROUP_SIZE, WORKGROUP_SIZE]
- const vec2 TEXEL_SIZE = 1.0 / IN_DEPTH_MAP_SIZE;
- vec2 uv = NDC_TO_UV(posNdc.xy) + displacement * TEXEL_SIZE;
- // Sample and store depth
- float refDepth = textureLod(u_depthMap, uv, 0.0).r;
- atomicMax(s_maxDepth, uint(refDepth * float(MAX_U32)));
- // Sync
- memoryBarrierShared();
- barrier();
- if(gl_LocalInvocationIndex == 0)
- {
- float refDepth = float(s_maxDepth) / float(MAX_U32);
- u_indirectInfo[flareIdx].count = (depth > refDepth) ? 0u : 4u;
- u_indirectInfo[flareIdx].instanceCount = 1u;
- u_indirectInfo[flareIdx].first = 0u;
- u_indirectInfo[flareIdx].baseInstance = 0u;
- }
- }
- ]]></source>
- </shader>
- </shaders>
- </shaderProgram>
|