Welcome, Guest.
Username: Password: Remember me

TOPIC: Martins improved Film Grain shader

Martins improved Film Grain shader 1 year 4 months ago #1

  • Alo81
  • Alo81's Avatar
  • Offline
  • Posts: 16
  • Thank you received: 6
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: 1 year 4 months ago by Alo81.
The administrator has disabled public write access.

Martins improved Film Grain shader 1 year 4 months ago #2

  • Alo81
  • Alo81's Avatar
  • Offline
  • Posts: 16
  • Thank you received: 6
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
The administrator has disabled public write access.

Martins improved Film Grain shader 1 year 4 months ago #3

  • Alo81
  • Alo81's Avatar
  • Offline
  • Posts: 16
  • Thank you received: 6
Here are some in game examples

Crysis:


Showing off varying intensities from the version ported to GeDoSaTo.
The administrator has disabled public write access.

Martins improved Film Grain shader 1 year 4 months ago #4

  • robgrab
  • robgrab's Avatar
  • Offline
  • Posts: 122
  • Thank you received: 21
I, for one, would like to see this implemented.
The administrator has disabled public write access.
The following user(s) said Thank You: Alo81

Martins improved Film Grain shader 1 year 4 months ago #5

  • Kleio420
  • Kleio420's Avatar
  • Offline
  • Posts: 216
  • Thank you received: 28
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
The administrator has disabled public write access.

Martins improved Film Grain shader 1 year 4 months ago #6

  • Alo81
  • Alo81's Avatar
  • Offline
  • Posts: 16
  • Thank you received: 6
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: 1 year 4 months ago by Alo81.
The administrator has disabled public write access.

Martins improved Film Grain shader 1 year 4 months ago #7

  • crosire
  • crosire's Avatar
  • Offline
  • Posts: 2438
  • Thank you received: 1387
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.
Cheers, crosire =)
The administrator has disabled public write access.

Martins improved Film Grain shader 1 year 4 months ago #8

  • Alo81
  • Alo81's Avatar
  • Offline
  • Posts: 16
  • Thank you received: 6
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: 1 year 4 months ago by Alo81.
The administrator has disabled public write access.

Martins improved Film Grain shader 1 year 4 months ago #9

  • Alo81
  • Alo81's Avatar
  • Offline
  • Posts: 16
  • Thank you received: 6
@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: 1 year 4 months ago by Alo81.
The administrator has disabled public write access.

Martins improved Film Grain shader 1 year 4 months ago #10

  • crosire
  • crosire's Avatar
  • Offline
  • Posts: 2438
  • Thank you received: 1387
Ah, nice. I'll pass this on to Lucifer, who's managing the framework.
Cheers, crosire =)
The administrator has disabled public write access.

Martins improved Film Grain shader 1 year 4 months ago #11

  • Alo81
  • Alo81's Avatar
  • Offline
  • Posts: 16
  • Thank you received: 6
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: 1 year 4 months ago by Alo81.
The administrator has disabled public write access.
The following user(s) said Thank You: BillyAlt, Ganossa, Mobeeuz

Martins improved Film Grain shader 1 year 4 months ago #12

  • Ganossa
  • Ganossa's Avatar
  • Offline
  • 최정장군
  • Posts: 790
  • Thank you received: 838
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?
The administrator has disabled public write access.

Martins improved Film Grain shader 1 year 4 months ago #13

  • Alo81
  • Alo81's Avatar
  • Offline
  • Posts: 16
  • Thank you received: 6
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: 1 year 4 months ago by Alo81.
The administrator has disabled public write access.

Martins improved Film Grain shader 1 year 4 months ago #14

  • Ganossa
  • Ganossa's Avatar
  • Offline
  • 최정장군
  • Posts: 790
  • Thank you received: 838
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) :-)
The administrator has disabled public write access.

Martins improved Film Grain shader 1 year 4 months ago #15

  • Ganossa
  • Ganossa's Avatar
  • Offline
  • 최정장군
  • Posts: 790
  • Thank you received: 838
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: 1 year 4 months ago by Ganossa.
The administrator has disabled public write access.

Martins improved Film Grain shader 1 year 4 months ago #16

  • Alo81
  • Alo81's Avatar
  • Offline
  • Posts: 16
  • Thank you received: 6
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.
The administrator has disabled public write access.

Martins improved Film Grain shader 1 year 3 months ago #17

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
The administrator has disabled public write access.

Martins improved Film Grain shader 1 year 3 months ago #18

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?


Witanlore: Dreamtime
The administrator has disabled public write access.

Martins improved Film Grain shader 1 year 3 months ago #19

  • Ganossa
  • Ganossa's Avatar
  • Offline
  • 최정장군
  • Posts: 790
  • Thank you received: 838
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. :)
The administrator has disabled public write access.