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 22

COORDINATE TRANSFORMATIONS: SCALING

float coordinateGrid(vec2 r) {
	vec3 axesCol = vec3(0.0, 0.0, 1.0);
	vec3 gridCol = vec3(0.5);
	float ret = 0.0;
	const float tickWidth = 0.1;
	for (float i = -2.0; i < 2.0; i += tickWidth)
	{
		ret += 1. - smoothstep(0.0, 0.008, abs(r.x - i));
		ret += 1. - smoothstep(0.0, 0.008, abs(r.y - i));
	}
	ret += 1. - smoothstep(0.001, 0.015, abs(r.x));
	ret += 1. - smoothstep(0.001, 0.015, abs(r.y));
	return ret;
}
float disk(vec2 r, vec2 center, float radius) {
	return 1.0 - smoothstep(radius - 0.005, radius + 0.005, length(r - center));
}
float rectangle(vec2 r, vec2 topLeft, vec2 bottomRight) {
	float ret;
	float d = 0.005;
	ret = smoothstep(topLeft.x - d, topLeft.x + d, r.x);
	ret *= smoothstep(topLeft.y - d, topLeft.y + d, r.y);
	ret *= 1.0 - smoothstep(bottomRight.y - d, bottomRight.y + d, r.y);
	ret *= 1.0 - smoothstep(bottomRight.x - d, bottomRight.x + d, r.x);
	return ret;
}
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 bgCol = vec3(1.0);
	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 = bgCol;
	float scaleFactor = 2.0;
	ret = mix(ret, col1, coordinateGrid(r) / 2.0);
	vec2 q = 0.3 * r;
	ret = mix(ret, col2, coordinateGrid(q));
	ret = mix(ret, col2, disk(q, vec2(0.0, 0.0), 0.1));
	ret = mix(ret, col1, disk(r, vec2(0.0, 0.0), 0.1));
	ret = mix(ret, col1, rectangle(r, vec2(-0.5, 0.0), vec2(-0.2, 0.2)) );
	ret = mix(ret, col2, rectangle(q, vec2(-0.5, 0.0), vec2(-0.2, 0.2)) );
	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?