Jump to content

Cheap transparent shadows


Josh
 Share

Recommended Posts

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:

Untitled.thumb.png.0973188448bf6c5837ccd85f4b30637a.png

And this is what it looks like with normal shadow filtering. (Ambient light is black in this shot.)

Untitled2.thumb.png.831617d55e2c6738be98928e463ca93c.png

  • Like 1
  • Thanks 1

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

Wouldn't the amount of transparency change depending on shadow resolution (Or overall render resolution as a model shader)?

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

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.

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

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;

 

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

Maybe you could add a second object with a shader that discards every pixel in the scene render, but still renders the shadow.

  • Upvote 1

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

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.

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

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.

image.thumb.png.e45a9c6e25da484c0190336938980989.png

Now with that brush hack applied.

image.thumb.png.0f35913368a8ae317e468ec5bfab352d.png

Then we apply the cubemap during map load and this is the final result!

image.thumb.png.f19d195250c1dd6699c7062ff0e43ad7.png

It took like 5 years, but now Leadwerks now has a solution for glass.

  • Like 3
  • Upvote 1

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...