Martins improved Film Grain shader

  • Alo81
  • Topic Author
More
8 years 9 months ago - 8 years 9 months ago #1 by Alo81 Martins improved Film Grain shader was created by Alo81
Reshades current film grain implementation is decent, but it is very noticeably faked.

A while back, I ported Martins Film Grain shader to GeDoSaTo and I believe it to be a significantly improved implementation of film grain.

Martin details the process and includes the shader code at his blog here: devlog-martinsh.blogspot.com/2013/05/ima...film-grain-post.html
Last edit: 8 years 9 months ago by Alo81.

Please Log in or Create an account to join the conversation.

  • Alo81
  • Topic Author
More
8 years 9 months ago #2 by Alo81 Replied by Alo81 on topic Martins improved Film Grain shader
I'm making this as a second post because unfortunately the spam filter caught my original post for including too many links...

Check out the blog link above for some great examples showcasing it.
Comparison of real film grain to Martins simulated example:


Now, I am perfectly happy to admit I'm a complete amateur, and that being able to port it over was basically a lot of dumb luck and slapped together code that is probably not very well done. I think that if someone could implement this shader into Reshade, it would be a huge benefit. It is a fantastic implementation and would be awesome to be able to use it in many different DX9-11/OGL games.

Just incase it might be useful, direct link to shader code ported to GeDoSaTo

Please Log in or Create an account to join the conversation.

  • Alo81
  • Topic Author
More
8 years 9 months ago #3 by Alo81 Replied by Alo81 on topic Martins improved Film Grain shader
Here are some in game examples

Crysis:


Showing off varying intensities from the version ported to GeDoSaTo.

Please Log in or Create an account to join the conversation.

  • robgrab
More
8 years 8 months ago #4 by robgrab Replied by robgrab on topic Martins improved Film Grain shader
I, for one, would like to see this implemented.
The following user(s) said Thank You: Alo81

Please Log in or Create an account to join the conversation.

  • Kleio420
More
8 years 8 months ago #5 by Kleio420 Replied by Kleio420 on topic Martins improved Film Grain shader

Alo81 wrote: Reshades current film grain implementation is decent, but it is very noticeably faked.

A while back, I ported Martins Film Grain shader to GeDoSaTo and I believe it to be a significantly improved implementation of film grain.

Martin details the process and includes the shader code at his blog here: devlog-martinsh.blogspot.com/2013/05/ima...film-grain-post.html

wow lmao ive been looking for that blog again for a while i lost the link a bit back

Please Log in or Create an account to join the conversation.

  • Alo81
  • Topic Author
More
8 years 8 months ago - 8 years 8 months ago #6 by Alo81 Replied by Alo81 on topic Martins improved Film Grain shader
I'm working on porting it but have run into a rather unhelpful error unfortunately. Anyone have any idea what it could mean?
21/07/2015 12:28:15:013 [12348] | INFO  | Loading effect from "H:\Steam\steamapps\common\Tony Hawk's Pro Skater HD\Binaries\Win32\d3d9.fx" ...
21/07/2015 12:28:16:606 [12348] | ERROR | Failed to compile effect on context 0A3FC5E8:

H:\Steam\steamapps\common\Tony Hawk's Pro Skater HD\Binaries\Win32\/ReShade/CustomFX/Grain.h(9, 7): warning X5000: global variables are considered 'uniform' by default
H:\Steam\steamapps\common\Tony Hawk's Pro Skater HD\Binaries\Win32\/ReShade/CustomFX/Grain.h(10, 7): warning X5000: global variables are considered 'uniform' by default
H:\Steam\steamapps\common\Tony Hawk's Pro Skater HD\Binaries\Win32\/ReShade/CustomFX/Grain.h(13, 7): warning X5000: global variables are considered 'uniform' by default
H:\Steam\steamapps\common\Tony Hawk's Pro Skater HD\Binaries\Win32\/ReShade/CustomFX/Grain.h(14, 7): warning X5000: global variables are considered 'uniform' by default
H:\Steam\steamapps\common\Tony Hawk's Pro Skater HD\Binaries\Win32\/ReShade/CustomFX/Grain.h(15, 7): warning X5000: global variables are considered 'uniform' by default
H:\Steam\steamapps\common\Tony Hawk's Pro Skater HD\Binaries\Win32\/ReShade/CustomFX/Grain.h(16, 7): warning X5000: global variables are considered 'uniform' by default
H:\Steam\steamapps\common\Tony Hawk's Pro Skater HD\Binaries\Win32\/ReShade/CustomFX/Grain.h(104, 8): error: internal shader creation failed with '2289436780'!

The most relevant parts I believe being:
21/07/2015 12:28:16:606 [12348] | ERROR | Failed to compile effect on context 0A3FC5E8:
...
H:\Steam\steamapps\common\Tony Hawk's Pro Skater HD\Binaries\Win32\/ReShade/CustomFX/Grain.h(104, 8): error: internal shader creation failed with '2289436780'!

Line 104, 8 is the GrainPass method.
float4 GrainPass(float4 position : SV_Position, float2 texcoord : TEXCOORD0) : SV_Target
{
    float3 rotOffset = float3(1.425,3.892,5.835); //rotation offset values  
    float2 rotCoordsR = coordRot(texcoord, timer + rotOffset.x);
    float2 rot = rotCoordsR*float2(width/grainsize,height/grainsize);
    float pNoise = pnoise3D(float3(rot.x,rot.y,0.0));
    float3 noise = float3(pNoise, pNoise, pNoise);
  
    if (colored == 1)
    {
        float2 rotCoordsG = coordRot(texcoord, timer + rotOffset.y);
        float2 rotCoordsB = coordRot(texcoord, timer + rotOffset.z);
        noise.g = lerp(noise.r,pnoise3D(float3(rotCoordsG*float2(width/grainsize,height/grainsize),1.0)),coloramount);
        noise.b = lerp(noise.r,pnoise3D(float3(rotCoordsB*float2(width/grainsize,height/grainsize),2.0)),coloramount);
    }
    
    float3 col = position.rgb;

    //noisiness response curve based on scene luminance
    float3 lumcoeff = float3(0.299,0.587,0.114);
    float luminance = lerp(0.0,dot(col, lumcoeff),lumamount);
    float lum = smoothstep(0.2,0.0,luminance);
    lum += luminance;
    
    float2 thepow = pow(lum, 4.0);
    
    noise = lerp(noise,float3(0.0, 0.0, 0.0),pow(lum,4.0));
    col += noise*grainamount;
   
    return float4(col,1.0);
}

Which I call using
technique Grain_Tech <bool enabled = RFX_Start_Enabled; int toggle = Cel_ToggleKey; >
{
	pass Grain_Pass
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = GrainPass;
	}
}

I'm realizing this post is getting kind of messy so rather than posting code snippets here, I'll post a pastebin link to the full code as it currently stands. Hopefully someone can help me figure this out because I'm not sure where to go with it from this point.

Full code link

Kleio420 wrote: wow lmao ive been looking for that blog again for a while i lost the link a bit back


Glad I could help you find it!
Last edit: 8 years 8 months ago by Alo81.

Please Log in or Create an account to join the conversation.

  • crosire
More
8 years 8 months ago #7 by crosire Replied by crosire on topic Martins improved Film Grain shader

Alo81 wrote: I'm working on porting it but have run into a rather unhelpful error unfortunately. Anyone have any idea what it could mean?

Error 2289436780 is D3DERR_INVALIDCALL, meaning D3D9 did not accept the compiled shader code ReShade produced. This can have various reasons. Like that your GPU does not support shader model 3 (but that would mean ReShade wouldn't work at all). Could you post a full tracelog? It contains the HLSL code ReShade's compiler produced, which would be helpful for debugging.

Please Log in or Create an account to join the conversation.

  • Alo81
  • Topic Author
More
8 years 8 months ago - 8 years 8 months ago #8 by Alo81 Replied by Alo81 on topic Martins improved Film Grain shader

crosire wrote: Error 2289436780 is D3DERR_INVALIDCALL, meaning D3D9 did not accept the compiled shader code ReShade produced. This can have various reasons. Like that your GPU does not support shader model 3 (but that would mean ReShade wouldn't work at all). Could you post a full tracelog? It contains the HLSL code ReShade's compiler produced, which would be helpful for debugging.


Thanks for the response, here's the full tracelog.

Here is what I imagine is just the relevant section. I've run it through a formatter to help with readability hopefully.

pastebin.com/4YZPZJqx
Last edit: 8 years 8 months ago by Alo81.

Please Log in or Create an account to join the conversation.

  • Alo81
  • Topic Author
More
8 years 8 months ago - 8 years 8 months ago #9 by Alo81 Replied by Alo81 on topic Martins improved Film Grain shader
@Crosire, thanks for the Tracelog tip, it was hugely helpful.

I got it figured out! The main issue was this line

float4 PS_Grain(float4 position : SV_Position, float2 texcoord : TEXCOORD) : SV_Target
{
...
float3 col = position.rgb;


which needed to be changed to

float3 col = tex2D(RFX_backbufferColor, texcoord);

Also width and height weren't being read properly and were thus being replaced with 0.0f.

That probably took a lot longer than it should have to figure out!

What should I do to go about getting it included in the default framework?
Last edit: 8 years 8 months ago by Alo81.

Please Log in or Create an account to join the conversation.

  • crosire
More
8 years 8 months ago #10 by crosire Replied by crosire on topic Martins improved Film Grain shader
Ah, nice. I'll pass this on to Lucifer, who's managing the framework.

Please Log in or Create an account to join the conversation.

  • Alo81
  • Topic Author
More
8 years 8 months ago - 8 years 8 months ago #11 by Alo81 Replied by Alo81 on topic Martins improved Film Grain shader

crosire wrote: Ah, nice. I'll pass this on to Lucifer, who's managing the framework.


Alright great! I threw it all together into its own little package to hopefully make it easier.

As it is currently, you can just extract this ZIP into the reshade folder and film grain should be functional.

sta.sh/0xh88722ugg
Last edit: 8 years 8 months ago by Alo81.
The following user(s) said Thank You: BillyAlt, Ganossa, Mobeeuz

Please Log in or Create an account to join the conversation.

  • Ganossa
More
8 years 8 months ago #12 by Ganossa Replied by Ganossa on topic Martins improved Film Grain shader
Hey Alo81 :-) great work. I will look through it and add it to the framework. Thanks alot for the contribution! Any thoughts about credits or other things to note?

Please Log in or Create an account to join the conversation.

  • Alo81
  • Topic Author
More
8 years 8 months ago - 8 years 8 months ago #13 by Alo81 Replied by Alo81 on topic Martins improved Film Grain shader

LuciferHawk wrote: Hey Alo81 :-) great work. I will look through it and add it to the framework. Thanks alot for the contribution! Any thoughts about credits or other things to note?


I added my credit to the heading comments of the Grain.h file. If that's not how you all typically do it, I'm fine with whatever the typical crediting method is.

No other things to note. If you've got any questions when trying to implement it let me know, but it should be as simple as extracting that ZIP into the default Reshade folder setup and it'll be golden.
Last edit: 8 years 8 months ago by Alo81.

Please Log in or Create an account to join the conversation.

  • Ganossa
More
8 years 8 months ago #14 by Ganossa Replied by Ganossa on topic Martins improved Film Grain shader
I will have to add it to an existing suite so most likely CustomFX. Every shader can have a small description box in the mediator where you can add information like link or credits in case you want that (besides whats in the header of the shader file) :-)

Please Log in or Create an account to join the conversation.

  • Ganossa
More
8 years 8 months ago - 8 years 8 months ago #15 by Ganossa Replied by Ganossa on topic Martins improved Film Grain shader
Ported it, so will definitely be in the new release! Thanks again! :side:

I love it by the way, will be one of my new standard shader for games ;)

Last edit: 8 years 8 months ago by Ganossa.

Please Log in or Create an account to join the conversation.

  • Alo81
  • Topic Author
More
8 years 8 months ago #16 by Alo81 Replied by Alo81 on topic Martins improved Film Grain shader

LuciferHawk wrote: I will have to add it to an existing suite so most likely CustomFX. Every shader can have a small description box in the mediator where you can add information like link or credits in case you want that (besides whats in the header of the shader file) :-)


Oh dang I wish I had known, I actually originally had it all working within the custom fx suite but isolated it out so you could choose whatever was best for it :p

ah well, I'll know for next time.

And glad you like it, I've always thought it was a really impressive film grain implementation so good to see others dig it as well.

Please Log in or Create an account to join the conversation.

  • sucht
More
8 years 8 months ago #17 by sucht Replied by sucht on topic Martins improved Film Grain shader
i try to use this on Final Fantasy XIV, but i always get an error and Reshade says "Compiling Effect ... Failed"
the error it throws is " ReShade/MartinsFG/Grain.h(29, 15): error X3003: redefinition of 'timer' ".

so my question is, what can i do to make it compile?


ciao
sucht

Please Log in or Create an account to join the conversation.

  • vfxninjaeditor
More
8 years 8 months ago #18 by vfxninjaeditor Replied by vfxninjaeditor on topic Martins improved Film Grain shader

LuciferHawk wrote: Ported it, so will definitely be in the new release! Thanks again! :side:

I love it by the way, will be one of my new standard shader for games ;)


Any chance you could provide an update to your standard shader preset like you have in the past so we can copy settings from it?

Please Log in or Create an account to join the conversation.

  • Ganossa
More
8 years 8 months ago #19 by Ganossa Replied by Ganossa on topic Martins improved Film Grain shader
Sure, will create this presets for theLazy.Net later today so you can get it from the build in crawler. Wanted to test that feature anyway. :)

Please Log in or Create an account to join the conversation.

We use cookies
We use cookies on our website. Some of them are essential for the operation of the forum. You can decide for yourself whether you want to allow cookies or not. Please note that if you reject them, you may not be able to use all the functionalities of the site.