forked from StrafesNET/roblox-bot-player
56 lines
1.3 KiB
WebGPU Shading Language
56 lines
1.3 KiB
WebGPU Shading Language
struct VertexOutput {
|
|
@builtin(position) position: vec4<f32>,
|
|
@location(1) uv: vec2<f32>,
|
|
}
|
|
|
|
@vertex
|
|
fn vs_main(@builtin(vertex_index) vertex_index: u32) -> VertexOutput {
|
|
// hacky way to draw a large triangle
|
|
let tmp1 = i32(vertex_index) / 2;
|
|
let tmp2 = i32(vertex_index) & 1;
|
|
var result:VertexOutput;
|
|
result.position=vec4<f32>(
|
|
f32(tmp1) * 4.0 - 1.0,
|
|
f32(tmp2) * 4.0 - 1.0,
|
|
1.0,
|
|
1.0
|
|
);
|
|
result.uv=vec2<f32>(
|
|
f32(tmp1) * 2.0,
|
|
1.0 - f32(tmp2) * 2.0
|
|
);
|
|
return result;
|
|
}
|
|
|
|
@group(0)
|
|
@binding(0)
|
|
var texture: texture_2d<f32>;
|
|
@group(0)
|
|
@binding(1)
|
|
var texture_sampler: sampler;
|
|
|
|
const RGB_TO_Y:vec3<f32> =
|
|
vec3(0.2126,0.7152,0.0722);
|
|
const RGB_TO_UV:mat3x2<f32> = mat3x2<f32>(
|
|
-0.09991,0.615,
|
|
-0.33609,-0.55861,
|
|
0.436,-0.05639
|
|
);
|
|
const BIAS:vec2<f32> = vec2<f32>(0.5, 0.5);
|
|
|
|
@fragment
|
|
fn fs_main_y(input: VertexOutput) -> @location(0) f32 {
|
|
let color = textureSample(texture, texture_sampler, input.uv).rgb;
|
|
let y = dot(RGB_TO_Y,color);
|
|
let y_limited = mix(16.0/255.0,240.0/255.0,y);
|
|
return clamp(y_limited, 0.0, 1.0);
|
|
}
|
|
|
|
@fragment
|
|
fn fs_main_uv(input: VertexOutput) -> @location(0) vec2<f32> {
|
|
let color = textureSample(texture, texture_sampler, input.uv).rgb;
|
|
let uv = RGB_TO_UV * color + BIAS;
|
|
let uv_limited = mix(vec2(16.0/255.0),vec2(240.0/255.0),uv);
|
|
return clamp(uv_limited, vec2(0.0, 0.0), vec2(1.0, 1.0));
|
|
}
|