Hello, i had to make a glassmaterial for a project. This is what i came up with. Any feedback is welcome. Its a modified / expanded version from the water material inside the Nvidia Flex demos.
Youtube Video is on the way.
Pretty cool! I am not familiar with exactly how the flex demo material you mentioned worked, but did you change the reflection code to have some chromatic abberation to achieve that? Or is raytracing the cubemaps as well as the scene texture? kind of looks like less artifacts than you’d get with standard scene texture refraction.
I had no time to set up useful values for now. I also used Tom loomans inner translucent culling. There is one error message though, the material instance preview says [ES2] (Node not supported in feature level ES2) and so on. No idea what that means. Im not a professional at that topic.
You need specular highlights on it. You can try turning on forward shading and using per-pixel lighting, but a cheaper way to do it is with phong shading and a light vector. Add the specular result from Phong to the opacity, and multiply that by your strength (preferably the strength of the lights in your scene, in linear space).
This material was pretty cool so I wanted to see how easy it would be to do in code so that it will work automatically in any material. Turns out it is pretty easy to modify this code to do it.
You can add this code after line 57 in DistortApplyScreenPS.usf. Replace from there up to OutColor=DistColor;
This will actually be more performant since since sampling scene texture inside of translucent materials causes some overhead cost each time it is used whereas doing it in code will have a constant overhead.
Of course you probably also want to make the 1.05 and 1.1 values I hard coded into parameters or something. But these values are just approximations since there is no real raytracing or correct refraction calculation going on.
After pasting that in you simply have to recompile shaders in the editor with ctrl+shift+period and it only takes a few seconds with this file.
This new refraction shader mod is quite interesting, but its difficult for me to find better values and setups.
[video]https://youtu.be/LAr2lICB7N4[/video]
What does that mean exactly ? Does that mean i could extend the material shader inputs ? Never actually knew or thought about digging into that direction. This .usf thing really got me interested
It means make the chromatic abberation intensity a variable you can tweak with the console. You could conceivably add a custom material input node but it would be a lot more work than a cvar.
you only need one variable since the spread between the 3 channels should be linear (or at least I assume for simplicity sake). Then you can calculate the 2 offsets from that.
keep in mind that the post process “fringe” will cause a bit of additional spread on top of this refraction.
I’ve tried to use this by pasting the code into a translucent material but it keep crashing the engine. i’m using ue4.11.2. Am I doing something wrong ? is there maybe a chance we can have a look on how to do it trough nodes or is that impossible to do ?
Well, if this came from Nvidia FleX, then that explains why FleX fluid surface rendering is so **** slow :p. That being said, Nvidia has a knack for creating fantastic shaders for realtime. And now I kinda want to plug your CA into the flex fluid, just for fun. BTW, where are we supposed to paste the Pasteall code to? I crash Unreal whenever I paste it directly to a translucent material.
Good question. There is a file called “C:\Program Files (x86)\Epic Games\4.11\Engine\Shaders\DistortApplyScreenPS.usf”. If you make a copy of this one (and a further as backup - coz you pretty sure need it) and replace the stuff in this file from line 57 up to OutColor=DistColor; with the code that is written here: Advanced Glass Material WIP - Rendering - Epic Developer Community Forums then you would get some significant change if you place your modified copy of that file over the original and hit CTRL-SHIFT-Period in the editor. Unfortunately all of my glass mats (either from market-place or my own one) look pretty wrong afterwards as long as I add some refraction value. If I don’t change the refraction value then it’s “ok” but just translucent anymore (and does not really look that much like glass anymore).
Edit: Got it working. I even replaced the “OutColor=DistColor;” line - which was wrong.
What code are you trying to paste? The code I posted was meant to go into a .usf file, not a material. It could be done in a material but that would just be rewriting what Maternal already did using nodes so I didn’t see much point in it.
Re: could the built in chromatic aberration go into main: Probably not anytime soon. I brought this up with rendering guys and they had a few issues with it being on that are valid:
It wouldn’t let you control the aberration per asset, it would have to be the same for ALL translucency and all would get it
It would have a double chromatic artifact when using the scene color fringe which is another path for chromatic aberration
Doing it in the material using Maternal’s method while more expensive (due to the scene color lookups) is technically more flexible since it gives you the choice of which materials to apple the extra chromatic aberration too. I hope this makes sense. That isn’t to say it won’t ever go in. Feel free to request it and that could change opinions over time.