| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- // Copyright (C) 2009-present, 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
- #pragma anki technique vert pixel
- #include <AnKi/Shaders/Common.hlsl>
- struct Constants
- {
- Vec4 m_transform; // x: x scale, y: y scale, z: x transl, w: y transl
- Vec4 m_colorScale;
- Vec4 m_depth; // Used in 3D textures.
- };
- ANKI_FAST_CONSTANTS(Constants, g_consts)
- struct VertIn
- {
- Vec2 m_position : POSITION;
- Vec4 m_color : COLOR;
- Vec2 m_uv : TEXCOORD;
- };
- struct VertOut
- {
- Vec2 m_uv : TEXCOORD;
- Vec4 m_color : COLOR;
- Vec4 m_svPosition : SV_POSITION;
- };
- #if ANKI_VERTEX_SHADER
- VertOut main(VertIn input)
- {
- VertOut output;
- output.m_uv = input.m_uv;
- output.m_uv.y = 1.0 - output.m_uv.y;
- output.m_color = input.m_color;
- const Vec2 pos = g_consts.m_transform.xy * input.m_position + g_consts.m_transform.zw;
- output.m_svPosition = Vec4(pos, 0.0, 1.0);
- return output;
- }
- #endif // ANKI_VERTEX_SHADER
- #if ANKI_PIXEL_SHADER
- SamplerState g_trilinearRepeatSampler : register(s0);
- # if TEXTURE_TYPE == 0
- Texture2D<Vec4> g_tex2d : register(t0);
- # else
- Texture3D<Vec4> g_tex3d : register(t0);
- # endif
- Vec4 main(VertOut input) : SV_TARGET0
- {
- # if TEXTURE_TYPE == 0
- const Vec4 rgba = g_tex2d.Sample(g_trilinearRepeatSampler, input.m_uv);
- # else
- const Vec4 rgba = g_tex3d.Sample(g_trilinearRepeatSampler, Vec3(input.m_uv, g_consts.m_depth.x));
- # endif
- Vec3 outColor = input.m_color.rgb * rgba.rgb * g_consts.m_colorScale.rgb;
- if(g_consts.m_colorScale.a == 1.0)
- {
- // Draw a pattern to visualize alpha
- F32 alphaPattern = ((U32(input.m_svPosition.x) / 16u) & 1u) == 1u ? 1.0 : 0.75;
- alphaPattern *= ((U32(input.m_svPosition.y) / 16u) & 1u) == 1u ? 1.0 : 0.75;
- outColor = lerp(Vec3(alphaPattern, alphaPattern, alphaPattern), outColor, rgba.a);
- }
- return Vec4(outColor, 1.0);
- }
- #endif // ANKI_PIXEL_SHADER
|