| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- // Copyright (C) 2009-2018, Panagiotis Christopoulos Charitos and contributors.
- // All rights reserved.
- // Code licensed under the BSD License.
- // http://www.anki3d.org/LICENSE
- #pragma anki mutator COLOR_TEXTURE 0 1
- #pragma anki mutator DITHERED_DEPTH_TEST 0 1
- #pragma anki input const U32 INSTANCE_COUNT
- #pragma anki start vert
- #include <shaders/Common.glsl>
- layout(location = 0) in Vec3 in_position;
- #if COLOR_TEXTURE == 1
- layout(location = 1) in Vec2 in_uv;
- layout(location = 0) out Vec2 out_uv;
- #endif
- layout(ANKI_UBO_BINDING(1, 0), row_major) uniform u0_
- {
- Mat4 u_mvp[INSTANCE_COUNT];
- Vec4 u_color;
- };
- out gl_PerVertex
- {
- Vec4 gl_Position;
- };
- void main()
- {
- #if COLOR_TEXTURE == 1
- out_uv = in_uv;
- #endif
- gl_Position = u_mvp[gl_InstanceID] * Vec4(in_position, 1.0);
- }
- #pragma anki end
- #pragma anki start frag
- #include <shaders/Common.glsl>
- #if COLOR_TEXTURE == 1
- layout(location = 0) in Vec2 in_uv;
- layout(ANKI_TEX_BINDING(1, 0)) uniform sampler2D u_tex;
- #endif
- layout(ANKI_UBO_BINDING(1, 0), row_major) uniform u0_
- {
- Mat4 u_mvp[INSTANCE_COUNT];
- Vec4 u_color;
- };
- // NOTE: Don't eliminate the binding because it confuses the descriptor set creation
- #if DITHERED_DEPTH_TEST == 1 || 1
- layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2D u_depthRt;
- #endif
- layout(location = 0) out Vec4 out_color;
- void main()
- {
- // Check if we should skip the frag
- #if DITHERED_DEPTH_TEST == 1
- Vec2 uv = gl_FragCoord.xy / Vec2(textureSize(u_depthRt, 0));
- F32 depthRef = textureLod(u_depthRt, uv, 0.0).r;
- Bool depthTestFailed = gl_FragCoord.z >= depthRef;
- IVec2 fragCoordi = IVec2(gl_FragCoord.xy);
- if(depthTestFailed && ((fragCoordi.x + fragCoordi.y) % 8) != 0)
- {
- discard;
- }
- #endif
- // Write the color
- #if COLOR_TEXTURE == 1
- out_color = texture(u_tex, in_uv) * u_color;
- #else
- out_color = u_color;
- #endif
- }
- #pragma anki end
|