Help us understand the problem. What is going on with this article?

シェーダー勉強会まとめ

第0回

画像付きで自分で解説する。

https://glslfan.com/

スクリーンショット 2019-08-01 10.13.11(3).png

// - glslfan.com --------------------------------------------------------------
// Ctrl + s or Command + s: compile shader
// Ctrl + m or Command + m: toggle visibility for codepane
// ----------------------------------------------------------------------------
precision mediump float;
uniform vec2  resolution;     // resolution (width, height)
uniform vec2  mouse;          // mouse      (0.0 ~ 1.0)
uniform float time;           // time       (1second == 1.0)
uniform sampler2D backbuffer; // previous scene

void main(){
    vec2 p = gl_FragCoord.xy / resolution;
    vec4 col = vec4(p, mouse.y, 1.1);
    if(length(mouse.xy - p.xy) < abs(sin(time)) / 3.0) {
        col = vec4(0.0, 0.0, 1.0, 1.0);
    }
    gl_FragColor = col;
}

void main からの解説

vector

vec2 p = gl_FragCoord.xy / resolution;
vec4 col = vec4(p, mouse.y, 1.1);
  • vec2 Float32[2]のList
  • vec3 vec4 -> Float[3-4]
    • 値を取り出す際は x y z w の順番で取り出せる。

こういう感じで作成することも可能

vec4 tmp = vec4(vec3(vec2(0.1, 0.1), 0.1), 0.1);
vec4 sample = vec4(tmp.xyzw)

if(length(mouse.xy - p.xy) < abs(sin(time)) / 3.0)

length関数
mouse.xy と p.xyの距離を算出できる。(?)

それを sin(time) で一定期間で変更させる。

三角関数の推移グラフ

それをabs(絶対値表現 マイナスがなくなる形に変換)

col = vec4(0.0, 0.0, 1.0, 1.0); RGBAの形式

青色だけ表示させるように変更

gl_FragColor = col;

組み込み関数 gl_FargColor4vec を渡す事によりピクセルの色を確定させる

今回の勉強会で出た資料一覧

sandbox

入門記事

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away