Diferent shadow strength

on this post i asked if is posible with 1 Directional Light, to change the shadow strength of 1 specific object. They told me to ask it on Shader forums and i am here!

is there a way to create a shader who can change the shadow strength of that object? (basically is to create a transparent object who can cast a softer shadow than a wall.

Not easily… Unity uses basic shadow maps to determine if an object is in a shadow or not. It stores just the depth of the caster, not whether it’s transparent. There are some variants of shadow maps that keep track of that, but Unity does not allow you to mess around with it’s rendering engine enough to implement it… Well, not easily.

There’s one thing you can do, though. When using soft shadows, Unity blurs the visibility result from the shadow map, that means it samples multiple pixels from the shadow map and makes the shadow strength equal to the portion of pixels occluded. So the idea is to modify the shadow caster pass of your glass shader to write it’s depth not every pixel, but in a pattern like these:

Fully opaque:
X X
X X

75% opaque:
X X
_ X

if ((fmod(screenPos.x, 2.0) < 1.0) 
    (fmod(screenPos.y, 2.0) >= 1.0)) {
    discard;
}

50% opaque:
X _
_ X

if (fmod(screenPos.x + screenPos.y, 2.0) >= 1.0) {
    discard;
}

25% opaque:

_ _
X _

if ((fmod(screenPos.x, 2.0) >= 1.0) ||
    (fmod(screenPos.y, 2.0) < 1.0)) {
    discard;
}

// where screenPos is the projected position times shadow map resolution.

Now, as long as you’re using soft shadows and have a high enough shadow resolution to hide the aliasing, you should get softer shadows using these.

seems is time to learn shader programming :frowning: i cant understand yet lots of things and seems to make a transparent wall who cast a soft shadow with d3d11 is not trivial :stuck_out_tongue:

Yeah, there are many seemingly trivial things that are quite hard to achieve with current rendering engines. Try to make two transparent cubes intersect each other.

However, using transparancy and additive blending perhaps you can fool unity’s native shadows to become slightly less drawn by that object :slight_smile: however i have done extremely little concerning shadows and transparancy within shaders that wasn’t complete trial and error.

I fail to see how that could work. Additive blending in what pass? The only pass, where any changes you make affect the shadows, is the shadow caster pass, and blending the depth output additively in there would just… push… the shadow caster to a new imaginary position further away from the light, but the result would still be binary - either fully lit or fully shadowed.