Skip to content

Instantly share code, notes, and snippets.

@Absulit
Last active January 5, 2023 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Absulit/b466f2d4617fe8c7a75ff67d00ce6027 to your computer and use it in GitHub Desktop.
Save Absulit/b466f2d4617fe8c7a75ff67d00ce6027 to your computer and use it in GitHub Desktop.
video texture issue in fragment shader
struct Params {
utime:f32,
epoch:f32,
screenWidth:f32,
screenHeight:f32,
mouseX:f32,
mouseY:f32,
sliderA:f32,
sliderB:f32,
sliderC:f32,
}
@group(1) @binding(0) var <uniform> params: Params;
struct Fragment {
@builtin(position) Position: vec4<f32>,
@location(0) Color: vec4<f32>,
@location(1) uv: vec2<f32>,
@location(2) ratio: vec2<f32>,
@location(3) mouse: vec2<f32>
}
const workgroupSize = 8;
@compute @workgroup_size(workgroupSize,workgroupSize,1)
fn main(
@builtin(global_invocation_id) GlobalId: vec3<u32>,
@builtin(workgroup_id) WorkGroupID: vec3<u32>,
@builtin(local_invocation_id) LocalInvocationID: vec3<u32>
) {
let utime = params.utime;
}
struct Params {
utime:f32,
epoch:f32,
screenWidth:f32,
screenHeight:f32,
mouseX:f32,
mouseY:f32,
sliderA:f32,
sliderB:f32,
sliderC:f32,
}
@group(1) @binding(0) var <uniform> params: Params;
@group(1) @binding(1) var feedbackSampler: sampler;
@group(1) @binding(2) var video: texture_external;
struct Fragment {
@builtin(position) Position: vec4<f32>,
@location(0) Color: vec4<f32>,
@location(1) uv: vec2<f32>,
@location(2) ratio: vec2<f32>,
@location(3) mouse: vec2<f32>
}
@fragment
fn main(
@location(0) Color: vec4<f32>,
@location(1) uv: vec2<f32>,
@location(2) ratio: vec2<f32>,
@location(3) mouse: vec2<f32>,
@builtin(position) position: vec4<f32>
) -> @location(0) vec4<f32> {
let videoDims = textureDimensions(video);
let videoDimsRatio = f32(videoDims.x) / f32(videoDims.y);
let videoUV = uv * vec2(1,-1 * videoDimsRatio) * ratio.y / params.sliderA; // params.sliderA(B/C) is a value between 0 and 1
let rgbaVideo = textureSampleBaseClampToEdge(video, feedbackSampler, uv /*videoUV*/ );
return rgbaVideo;
}
struct Params {
utime:f32,
epoch:f32,
screenWidth:f32,
screenHeight:f32,
mouseX:f32,
mouseY:f32,
sliderA:f32,
sliderB:f32,
sliderC:f32,
}
@group(1) @binding(0) var <uniform> params: Params;
struct Fragment {
@builtin(position) Position: vec4<f32>,
@location(0) Color: vec4<f32>,
@location(1) uv: vec2<f32>,
@location(2) ratio: vec2<f32>,
@location(3) mouse: vec2<f32>
}
;
fn defaultVertexBody(position: vec4<f32>, color: vec4<f32>, uv: vec2<f32>) -> Fragment{
var result: Fragment;
let ratioX = params.screenWidth / params.screenHeight;
let ratioY = 1 / ratioX / (params.screenHeight / params.screenWidth);
result.ratio = vec2(ratioX, ratioY);
result.Position = vec4<f32>(position);
result.Color = vec4<f32>(color);
result.uv = vec2(uv.x * result.ratio.x, uv.y);
result.mouse = vec2(params.mouseX / params.screenWidth, params.mouseY / params.screenHeight);
return result;
}
@vertex
fn main(
@location(0) position: vec4<f32>,
@location(1) color: vec4<f32>,
@location(2) uv: vec2<f32>,
@builtin(vertex_index) VertexIndex: u32
) -> Fragment {
return defaultVertexBody(position, color, uv);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment