Skip to content
Permalink
master
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time
#version 450
/* Copyright (c) 2020-2022 Hans-Kristian Arntzen
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#extension GL_EXT_samplerless_texture_functions : require
layout(local_size_x = 4, local_size_y = 4, local_size_z = 4) in;
#include "rgtc.h"
layout(set = 0, binding = 0) writeonly uniform image2D uOutput;
layout(set = 0, binding = 1) uniform utexture2D uInput;
layout(push_constant) uniform Registers
{
ivec2 resolution;
} registers;
layout(constant_id = 0) const bool DUAL_COMPONENT = false;
ivec2 build_coord()
{
ivec2 base = ivec2(gl_WorkGroupID.xy) * 8;
base.x += 4 * (int(gl_LocalInvocationID.z) & 1);
base.y += 2 * (int(gl_LocalInvocationID.z) & 2);
base += ivec2(gl_LocalInvocationID.xy);
return base;
}
void main()
{
ivec2 coord = build_coord();
if (any(greaterThanEqual(coord, registers.resolution)))
return;
ivec2 tile_coord = coord >> 2;
ivec2 pixel_coord = coord & 3;
int linear_pixel = 4 * pixel_coord.y + pixel_coord.x;
uvec4 payload = texelFetch(uInput, tile_coord, 0);
vec4 rg = vec4(0);
rg.x = decode_alpha_rgtc(payload.xy, linear_pixel);
if (DUAL_COMPONENT)
rg.y = decode_alpha_rgtc(payload.zw, linear_pixel);
imageStore(uOutput, coord, rg);
}