Is there a way to add a code from glsl shader to another glsl shader?

Example moving the film grain feature from image-adjustment.glsl to crt-pi.glsl

1 Like

Depends on the code. That specific function should be fairly portable, though.

2 Likes

Honestly, the film grain, vignettes, (most) curvature, and mask code we have in the repo atm is pretty portable/drag n’ drop (with minor edits; mainly renaming shit).

That’s just my opinion tho.

1 Like

What is the film grain code and how to insert it

You just use notepad, personally I use notepad ++

I’m currently on mobile, so it’s taking me longer to grab that code.

1 Like

Can you give me an example of how to add a code from shader to another?

Alright, I’m going to preface this with I haven’t messed with this in like a year almost but here’s stuff to paste in order of where it appears in the shader. (Hunterk or someone will probably have to fill in some blanks for me tbh)

This goes near the top

#pragma parameter ia_GRAIN_STR "Film Grain" 0.0 0.0 72.0 6.0

This goes with some other shit that says uniform at the beginning.

uniform COMPAT_PRECISION int FrameCount;

This goes in kinda obvious places, pretty easy to guess where stuff goes by following patterns imho.

uniform COMPAT_PRECISION float ia_GRAIN_STR;

Almost immediately after

#define ia_GRAIN_STR 0.0       // grain filter strength; default is 0.0

Followed by this again, I guess

uniform COMPAT_PRECISION int FrameCount;

This is the actual film grain.

//https://www.shadertoy.com/view/4sXSWs strength= 16.0
vec3 filmGrain(vec2 uv, float strength )
{
   float x = (uv.x + 4.0 ) * (uv.y + 4.0 ) * ((mod(vec2(FrameCount, FrameCount).x, 800.0) + 10.0) * 10.0);
   return  vec3(mod((mod(x, 13.0) + 1.0) * (mod(x, 123.0) + 1.0), 0.01)-0.005) * strength;
}

This goes in a lower section.

   vec3 film_grain = filmGrain(vTexCoord, ia_GRAIN_STR);

You still need to add this to the end of a line somewhere near the very end like literally add it into an existing line of code, not sure where you should pick exactly from the top of my head, I imagine hunter or someone will correct my potato-ness.

+ film_grain

The line of code still needs to finish with this tho ; that symbol.

P.S. - This 1000% will not work as is, probably a few different lines that need 1/2 different tweaks on where shit is pointing to basically.

1 Like

Thank you very much. Please give me information on how to include it

1 Like

@hunterk I think that’s everything, but I’m just backseat blind doing this on mobile and wanted a second set of eyes.

1 Like

I’m going to try tonight, it’s confusing for me but it’s okay I think I’ll make it in the end I appreciate your effort, greetings I’m using google translator, excuse me for not speaking correctly, I’m a beginner in English

1 Like

I’d personally wait to see if anyone else adds anything before getting really into it, but it’s worth getting a look at the code.

The error log is super helpful for this kind of stuff as well, mainly for trying to troubleshoot.

1 Like

Are scan lines good?