// Copyright (C) 2009-2022, Panagiotis Christopoulos Charitos and contributors. // All rights reserved. // Code licensed under the BSD License. // http://www.anki3d.org/LICENSE #pragma anki mutator TEXTURE_TYPE 0 1 layout(push_constant) uniform b_pc { Vec4 u_transform; // x: x scale, y: y scale, z: x transl, w: y transl Vec4 u_colorScale; Vec4 u_depth; // Used in 3D textures. }; #pragma anki start vert #include layout(location = 0) in Vec2 in_pos; layout(location = 1) in Vec4 in_col; layout(location = 2) in Vec2 in_uv; layout(location = 0) out Vec2 out_uv; layout(location = 1) out Vec4 out_col; void main() { out_uv = in_uv; out_col = in_col; const Vec2 pos = u_transform.xy * in_pos + u_transform.zw; gl_Position = Vec4(pos, 0.0, 1.0); } #pragma anki end #pragma anki start frag #include layout(location = 0) in Vec2 in_uv; layout(location = 1) in Vec4 in_col; layout(location = 0) out Vec4 out_col; layout(set = 0, binding = 0) uniform sampler u_trilinearRepeatSampler; #if TEXTURE_TYPE == 0 layout(set = 0, binding = 1) uniform texture2D u_tex2d; #else layout(set = 0, binding = 1) uniform texture3D u_tex3d; #endif void main() { #if TEXTURE_TYPE == 0 const Vec4 rgba = texture(u_tex2d, u_trilinearRepeatSampler, in_uv); #else const Vec4 rgba = texture(u_tex3d, u_trilinearRepeatSampler, Vec3(in_uv, u_depth.x)); #endif out_col.rgb = in_col.rgb * rgba.rgb * u_colorScale.rgb; if(u_colorScale.a == 1.0) { // Draw a pattern to visualize alpha F32 alphaPattern = ((U32(gl_FragCoord.x) / 16u) & 1u) == 1u ? 1.0 : 0.75; alphaPattern *= ((U32(gl_FragCoord.y) / 16u) & 1u) == 1u ? 1.0 : 0.75; out_col.rgb = mix(Vec3(alphaPattern), out_col.rgb, rgba.a); } out_col.a = 1.0; } #pragma anki end