First of all I'm a complete noob when it comes to shaders and GLSL. So, here is the thing:
I'm trying to parse this ShaderToy shader into a GLSL Shader Fragment to use inside this GPUImage lib. I'm using this file as a sample for the parsing.
Original
// 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;
}
The result I got is the following
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;
}
When I'm altering the grain value between 0f and 1f, the output I'm getting is diagonal dotted lines. What am I doing wrong here?
If it's completely bad, how can I get a Film Grain shader to work here? Any ideas?