0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

概要

plunkerでshadertoyのglsl動かしてみた。
TUTORIAL、やってみる。

TUTORIAL 20

COLOR ADDITION AND SUBSTRACTION

float disk(vec2 r, vec2 center, float radius) {
	float distanceFromCenter = length(r - center);
	float outsideOfDisk = smoothstep(radius - 0.005, radius + 0.005, distanceFromCenter);
	float insideOfDisk = 1.0 - outsideOfDisk;
	return insideOfDisk;
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
	vec2 p = vec2(fragCoord.xy / iResolution.xy);
	vec2 r = 2.0 * vec2(fragCoord.xy - 0.5 * iResolution.xy) / iResolution.y;
	float xMax = iResolution.x / iResolution.y;
	vec3 black = vec3(0.0);
	vec3 white = vec3(1.0);
	vec3 gray = vec3(0.3);
	vec3 col1 = vec3(0.216, 0.471, 0.698);
	vec3 col2 = vec3(1.00, 0.329, 0.298);
	vec3 col3 = vec3(0.867, 0.910, 0.247);
	vec3 ret;
	float d;
	if (p.x < 1. / 3.)
	{
		ret = gray;
		d = disk(r, vec2(-1.1, 0.3), 0.4);
		ret = mix(ret, col1, d);
		d = disk(r, vec2(-1.3, 0.0), 0.4);
		ret = mix(ret, col2, d);
		d = disk(r, vec2(-1.05, -0.3), 0.4);
		ret = mix(ret, col3, d);
	}
	else if (p.x < 2. / 3.)
	{
		ret = black;
		ret += disk(r, vec2(0.1, 0.3), 0.4) * col1;
		ret += disk(r, vec2(-.1, 0.0), 0.4) * col2;
		ret += disk(r, vec2(.15, -0.3), 0.4) * col3;
	}
	else if (p.x < 3. / 3.)
	{
		ret = white;
		ret -= disk(r, vec2(1.1, 0.3), 0.4) * col1;
		ret -= disk(r, vec2(1.05, 0.0), 0.4) * col2;
		ret -= disk(r, vec2(1.35, -0.25), 0.4) * col3;
	}
	vec3 pixel = ret;
	fragColor = vec4(pixel, 1.0);
}

写真

image.png

成果物

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?