Josh Posted May 12, 2022 Share Posted May 12, 2022 While testing some code I accidentally discovered a way to do cheap semi-transparent shadows. The shadow casting object needs a shadow shader with a fragment program. Just add this line to the fragment main function: if ((int(gl_FragCoord.x + gl_FragCoord.y) % 2) == 1) discard; This is what it looks like with shadow filtering disabled: And this is what it looks like with normal shadow filtering. (Ambient light is black in this shot.) 1 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
havenphillip Posted May 12, 2022 Share Posted May 12, 2022 Dude that's rad. I just tried it on a basic shader and got semi-transparency in-game. It's not z-sorted or anything. 2 Quote Link to comment Share on other sites More sharing options...
Josh Posted May 12, 2022 Author Share Posted May 12, 2022 Mod it by 4 instead of 2 and it will be more transparent. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
IceBurger Posted May 12, 2022 Share Posted May 12, 2022 Wouldn't the amount of transparency change depending on shadow resolution (Or overall render resolution as a model shader)? Quote i now hate love C++ Beeeeeeeeeeeeeep~~This is a test of the emergency signature system~~Beeeeeeeeeeeeeep RX 6800XT | i5-13600KF | 32GB DDR5 | 1440p is perfect Link to comment Share on other sites More sharing options...
Josh Posted May 12, 2022 Author Share Posted May 12, 2022 1 minute ago, IceBurger said: Wouldn't the amount of transparency change depending on shadow render resolution (Or overall render resolution as a model shader)? Nope, it is discarding pixels in a uniform pattern, then the normal shadow blur filter mixes it all together. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
havenphillip Posted May 12, 2022 Share Posted May 12, 2022 Has a little more of a dithered look: if ((int(gl_FragCoord.x + gl_FragCoord.y) % 4) == 1) discard; 1 Quote Link to comment Share on other sites More sharing options...
Josh Posted May 12, 2022 Author Share Posted May 12, 2022 I got that wrong, that would give you 75% opacity. This will make it more transparent: f ((int(gl_FragCoord.x + gl_FragCoord.y) % 4) != 1) discard; Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Josh Posted May 12, 2022 Author Share Posted May 12, 2022 Are you doing the discard in the normal shader or the shadow shader? Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
havenphillip Posted May 12, 2022 Share Posted May 12, 2022 Ok yeah that looks great on shadows if I turn up the lighting quality in the options. Seems like that would be the best use. I cranked everything up on the normal shader but it still looks all dithered. 2 looks pretty good, though, even with the lighting on low: Quote Link to comment Share on other sites More sharing options...
havenphillip Posted May 12, 2022 Share Posted May 12, 2022 This is: if ((int(gl_FragCoord.x + gl_FragCoord.y) % 4) != 1) discard; ...with the lighting quality up. 2 Quote Link to comment Share on other sites More sharing options...
reepblue Posted May 12, 2022 Share Posted May 12, 2022 I'll have to try this. I have a lot of glass in my game. 2 1 Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
reepblue Posted May 13, 2022 Share Posted May 13, 2022 It seems not to work with Z-Sort enabled and that's how my glass works. I don't want any dithering on the material as seen with @havenphillip's screenshots. Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Josh Posted May 13, 2022 Author Share Posted May 13, 2022 Maybe you could add a second object with a shader that discards every pixel in the scene render, but still renders the shadow. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
reepblue Posted May 13, 2022 Share Posted May 13, 2022 That's an idea, but it might register as another drawcall or a light effect. My glass needs a script attached to it anyway so it doesn't get collapsed with the rest of the scene., What I can do is make each glass plane an actor that'll create an invisible box with it's AABB size and have it use that shader. I can also toggle the effect to help performance if it's much of a hit. I can also probably do this when my screne applies the correct cubemap to the shader too. I can pass the entity through a function that'll create the box on level load. Lemme try that first since that'll be easier. I'll see what I can come up with, thanks. Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Josh Posted May 13, 2022 Author Share Posted May 13, 2022 It works. You don't even have to modify your existing materials or objects, just add an invisible dummy block that creates the shadow. glasstest.rar 3 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
reepblue Posted May 13, 2022 Share Posted May 13, 2022 Thanks. I was still going to add the dummy boxes via code but if it can just be collapsed with the scene with no artifacts, I might add it manually. Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Josh Posted May 13, 2022 Author Share Posted May 13, 2022 Now I must be added to the credits of Cyclone (TM), the amazing successful game on Steam! 1 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
reepblue Posted May 13, 2022 Share Posted May 13, 2022 I mean, you already are in the readme.txt because you wrote the engine. 🙂 1 1 Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
reepblue Posted May 14, 2022 Share Posted May 14, 2022 Most of the time, I want as much light coming through as possible, but cases like this is a great example of how to use this effect. Here we have the default setup with no shadows being cast. Now with that brush hack applied. Then we apply the cubemap during map load and this is the final result! It took like 5 years, but now Leadwerks now has a solution for glass. 3 1 Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.