- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
总的来说,我对 Shadertoy 和 GLSL 相当陌生。我已经成功地将许多 Shadertoy 着色器复制到 Blender 中,但实际上并不知道它是如何工作的。我一直在寻找教程,但我更像是一个视觉学习者。
如果有人可以解释,或者甚至更好,提供一些描述 fragCoord、iResolution 和 fragColor 之间差异的图像。那很好啊!
我主要对数字感兴趣。因为我使用 Blender 我习惯了 Canvas 是 0 到 1 -或- -1 到 1
这个特别让我有点困惑。
vec2 u = (fragCoord - iResolution.xy * .5) / iResolution.y * 8.;
最佳答案
这是正常的,您无法在不知道坐标系的情况下在 blender 中重现此代码。
The Shadertoy documentation states:
Image shaders implement the mainImage() function to generateprocedural images by calculating a color for each pixel in the image.This function is invoked once in each pixel and the host applicationmust provide the appropriate input data and retrieve the output colorto assign it to the corresponding pixel on the screen. The signatureof this function is:
void mainImage( out vec4 fragColor, in vec2 fragCoord);
where fragCoord contains the coordinates of the pixel for which theshader must calculate a color. These coordinates are counted in pixelswith values from 0.5 to resolution-0.5 over the entire renderingsurface and the resolution of this surface is transmitted to theshader via the uniform iResolution variable.
iResolution
变量是
uniform vec3
它包含窗口的尺寸,并通过一些 openGL 代码发送到着色器。
fragCoord
variable 是一个内置变量,它包含应用着色器的像素的坐标。
vec2
即 X 轴上的 0 > 640 和 Y 轴上的 0 > 360 vec2
X 值为 640,Y 值为 360 // Normalized pixel coordinates (between 0 and 1)
vec2 uv = fragCoord/iResolution.xy;
// Set R and G values based on position
vec3 col = vec3(uv.x,uv.y,0);
// Output to screen
fragColor = vec4(col,1.0);
输出范围从
0,0
在左下角和
1,1
在右上角。这是 OpenGL 设置的默认左下角窗口空间。
// Normalized pixel coordinates (between -0.5 and 0.5)
vec2 uv = (fragCoord - iResolution.xy * 0.5)/iResolution.xy;
// Set R and G values based on position
vec3 col = vec3(uv.x,uv.y,0);
// Output to screen
fragColor = vec4(col,1.0);
输出范围从
-0.5,-0.5
在左下角和
0.5,0.5
因为
0.5
] 从每个像素坐标 [
fragCoord
]。您可以看到红色和绿色值直到很久以后才开始可见的效果。
vec2 uv = (fragCoord - iResolution.xy * 0.5)/iResolution.y;
根据我们的目的,如果您对两个轴进行标准化,图像可能看起来很奇怪,因此这是一种可能的策略。
// Normalized pixel coordinates (between -0.5 to 0.5)
vec2 uv = (fragCoord - iResolution.xy * 0.5)/iResolution.xy;
// Set R and G values based on position using ceil() function
// The ceil() function returns the smallest integer that is greater than the uv value
vec3 col = vec3(ceil(uv.x),ceil(uv.y),0);
// Output to screen
fragColor = vec4(col,1.0);
ceil()
函数可以让我们看到图像的中心是 0, 0
The output color is returned in fragColor as a four-component vector,the last component being ignored by the client. The result isretrieved in an "out" variable in anticipation of the future additionof several rendering targets.
fragColor
包含四个值,这些值被购买到渲染管道的下一个阶段。
You can find more about in and out variables here .
fragColor
中的值确定应用着色器的像素的颜色。
关于glsl - Shadertoy - fragCoord vs iResolution vs fragColor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58684315/
我是 GLSL 新手。我发现每个演示中都有一个变量iResolution https://www.shadertoy.com/new 。这是什么意思? 如果我想将此变量传递给着色器,我需要做什么? 最
总的来说,我对 Shadertoy 和 GLSL 相当陌生。我已经成功地将许多 Shadertoy 着色器复制到 Blender 中,但实际上并不知道它是如何工作的。我一直在寻找教程,但我更像是一个视
我是一名优秀的程序员,十分优秀!