Martins improved Film Grain shader
- Alo81
- Topic Author
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
Please Log in or Create an account to join the conversation.
- Alo81
- Topic Author
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
Crysis:
Showing off varying intensities from the version ported to GeDoSaTo.
Please Log in or Create an account to join the conversation.
- robgrab
Please Log in or Create an account to join the conversation.
- Kleio420
wow lmao ive been looking for that blog again for a while i lost the link a bit backAlo81 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
Please Log in or Create an account to join the conversation.
- Alo81
- Topic Author
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!
Please Log in or Create an account to join the conversation.
- crosire
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.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?
Please Log in or Create an account to join the conversation.
- Alo81
- Topic Author
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
Please Log in or Create an account to join the conversation.
- Alo81
- Topic Author
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?
Please Log in or Create an account to join the conversation.
- crosire
Please Log in or Create an account to join the conversation.
- Alo81
- Topic Author
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
Please Log in or Create an account to join the conversation.
- Ganossa
Please Log in or Create an account to join the conversation.
- Alo81
- Topic Author
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.
Please Log in or Create an account to join the conversation.
- Ganossa
Please Log in or Create an account to join the conversation.
- Ganossa
I love it by the way, will be one of my new standard shader for games
Please Log in or Create an account to join the conversation.
- Alo81
- Topic Author
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
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
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
LuciferHawk wrote: Ported it, so will definitely be in the new release! Thanks again!
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
Please Log in or Create an account to join the conversation.