WebGPU-Art / wgsl-shadertoy

Toy for WGSL
https://webgpu.art/wgsl-shadertoy/
5 stars 0 forks source link

records #5

Open tiye opened 1 year ago

tiye commented 1 year ago

learnt from https://twitter.com/TETH_function/status/1702517606270505056

@fragment
fn fragment_main(vs_out: VertexOut) -> @location(0) vec4<f32> {
  // provide (x,y) in pixels, center is (0,0)
  let pos = vs_out.pos;
  let x = pos.x * inner_width * 0.5;
  let y = pos.y * inner_height * 0.5;
  let angle = atan2(y, x);

  // draw a circle
  let l = length(vec2<f32>(x, y));

  let x2 = x * 0.001;
  let y2 = y * 0.001;
  let norm = sqrt(x2*x2 + y2*y2);
  let v = pow(sin(cos(atan2(y2,x2))/norm),10) 
        + pow(sin(sin(atan2(y2,x2))/norm), 10);
  if (v >= 1.0) {
    return vec4(1.0, 1.0, 0.0, 1.0);
  }

  return vec4(vs_out.color, 1.0);
}
image
tiye commented 1 year ago

from https://twitter.com/TETH_function/status/1643813156274225153


@fragment
fn fragment_main(vs_out: VertexOut) -> @location(0) vec4<f32> {
  // provide (x,y) in pixels, center is (0,0)
  let pos = vs_out.pos;
  let x = pos.x * inner_width * 0.5;
  let y = pos.y * inner_height * 0.5;
  let angle = atan2(y, x);

  // draw a circle
  let l = length(vec2<f32>(x, y)) * 0.1;

  let u = cos(l - 7 * angle);
  let v = cos(l + 7 * angle);
  if (max(u, v) <= 0.5) {
    return vec4f(1.0, 1.0, 0., 1.0);
  }

  return vec4(vs_out.color, 1.0);
}
image
tiye commented 1 year ago

https://twitter.com/TETH_function/status/1632939123966382082

@fragment
fn fragment_main(vs_out: VertexOut) -> @location(0) vec4<f32> {
  // provide (x,y) in pixels, center is (0,0)
  let pos = vs_out.pos;
  let x = pos.x * inner_width * 0.5;
  let y = pos.y * inner_height * 0.5;
  let angle = atan2(y, x);

  // draw a circle
  let l = length(vec2<f32>(x, y)) * 0.0025;

  let v = sin(cos(angle)/l + PI * sin(sin(angle) / l));
  if (v <= 0.0) {
    return vec4f(1.0, 1.0, 0., 1.0);
  }

  return vec4(vs_out.color, 1.0);
}
image image
tiye commented 1 year ago

https://twitter.com/TETH_function/status/1619168393277341699


@fragment
fn fragment_main(vs_out: VertexOut) -> @location(0) vec4<f32> {
  // provide (x,y) in pixels, center is (0,0)
  let pos = vs_out.pos;
  let x = pos.x * inner_width * 0.5;
  let y = pos.y * inner_height * 0.5;
  let angle = atan2(y, x);

  // draw a circle
  let l = length(vec2<f32>(x, y)) * 0.001;

  let v = sin(cos(angle)/l + sin(angle)/l
    + asin(sin(
      sin(cos(angle)/l - sin(angle)/l)
    ))) * sin(sin(angle)/l);

  if (v <= 0) {
    return vec4f(1.0, 1.0, 0.0, 1.0);
  }

  return vec4(vs_out.color, 1.0);
}
image image
tiye commented 1 year ago

from https://twitter.com/TETH_function/status/1608659271440338944

@fragment
fn fragment_main(vs_out: VertexOut) -> @location(0) vec4<f32> {
  // provide (x,y) in pixels, center is (0,0)
  let pos = vs_out.pos;
  let x = pos.x * inner_width * 0.5;
  let y = pos.y * inner_height * 0.5;
  let angle = atan2(y, x);

  // draw a circle
  let l = length(vec2<f32>(x, y)) * 0.0002;

  let x2 = x * 0.05;
  let y2 = y * 0.05;

  let v = cos(length(vec2(y2 * sin(x2), x2 * cos(y2))) - atan2(y2 * sin(x2), x2 * cos(y2)));

  if (v <= 0) {
    return vec4f(1.0, 1.0, 0.0, 1.0);
  }

  return vec4(vs_out.color, 1.0);
}
image image
tiye commented 1 year ago
@fragment
fn fragment_main(vs_out: VertexOut) -> @location(0) vec4<f32> {
  // provide (x,y) in pixels, center is (0,0)
  let pos = vs_out.pos;
  let x = pos.x * inner_width * 0.5;
  let y = pos.y * inner_height * 0.5;
  let angle = atan2(y, x);

  // draw a circle
  let l = length(vec2<f32>(x, y)) * 0.0004;

  let v = pow(sin(cos(angle)/l) ,2)
        + pow(
            sin(sin(angle)/l) - 0.5 * abs(sin(cos(angle)/l))
          , 2);

  if (v <= 0.5) {
    return vec4f(1.0, 1.0, 0.0, 1.0);
  }

  return vec4(vs_out.color, 1.0);
}
image image
tiye commented 1 year ago

https://twitter.com/TETH_function/status/1469864596794081282

@fragment
fn fragment_main(vs_out: VertexOut) -> @location(0) vec4<f32> {
  // provide (x,y) in pixels, center is (0,0)
  let pos = vs_out.pos;
  let x = pos.x * inner_width * 0.5;
  let y = pos.y * inner_height * 0.5;
  let angle = atan2(y, x);

  // draw a circle
  let l = length(vec2<f32>(x, y)) * 0.001;
  let x2 = x * 0.06;
  let y2 = y * 0.06;

  let v = modf(floor(pow(2, length(vec2(round(x2), round(y2)))))/2).fract;

  if (v >= 0.2) {
    return vec4f(1.0, 1.0, 0.0, 1.0);
  }

  return vec4(vs_out.color, 1.0);
}
image