首先,对于着色器和 GLSL,我完全是个菜鸟。所以,事情是这样的:
我正在尝试将这个 ShaderToy 着色器解析为 GLSL 着色器片段,以便在这个 GPUImage 库中使用。我使用这个 file 作为解析示例。
// Fork of "Simple Film Grain Shader" by terchapone. https://shadertoy.com/view/3sGGRz
// 2022-04-24 03:48:40
const float grainFactor = 0.1; //[0.0, 1.0]
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
// Normalized pixel coordinates (from 0 to 1)
vec2 uv = fragCoord/iResolution.xy;
// Calculate noise and sample texture
float mdf = grainFactor; // increase for noise amount
float noise = (fract(sin(dot(uv, vec2(12.9898,78.233)*2.0)) * 43758.5453));
vec4 tex = texture(iChannel0, uv);
vec4 col = tex - noise * mdf;
// Output to screen
fragColor = col;
}
uniform sampler2D inputImageTexture;
varying highp vec2 textureCoordinate;
uniform lowp float grain;
void main(){
lowp vec4 source = texture2D(inputImageTexture, textureCoordinate);
// Normalized pixel coordinates (from 0 to 1)
vec2 uv = textureCoordinate.xy ;
// Calculate noise and sample texture
float mdf = grain; // increase for noise amount
float noise = (fract(sin(dot(uv, vec2(12.9898,78.233)*2.0)) * 43758.5453));
vec4 col = source - (noise * mdf);
// Output to screen
gl_FragColor = col;
}
当我在 0f 和 1f 之间更改
grain
值时,我得到的输出是对角虚线。我在这里做错了什么?
如果它完全糟糕,我怎样才能让胶片颗粒着色器在这里工作?有什么想法吗?
这个问题你解决了吗?如果有的话可以分享给我吗?谢谢!