- Home /
Glass shadow problem
In this picture you can see the light passes through a window and ends on a surface... unfortunately you can see a lot of tiny points on the surface, but the glass is transparent. I don't know why this happens: shadow resolution and strenght are at maximum.
Anybody knows how to solve this?
Try increasing the bias of the light/modifying the clipping planes of your camera.
How did you do the glass? I tried but i can't figure out how to make a glass texture =/
Answer by Eno-Khaon · Jul 16, 2016 at 01:24 AM
What you're seeing is the result of working around the shadow mapping's limitation that it is (almost, but not exactly) all-or-nothing in the shaders.
I'm assuming you're using the Standard Transparent shader, which supports a rather fascinating form of shadow casting. Specifically, it's using a 3-dimensional dithering texture to generate shadows based on the alpha value of the texture/color casting the shadow.
In the shader, it looks something like:
alphaRef = tex3D(_DitherMaskLOD, float3(input.pos.xy*0.25, alpha*0.9375)).a;
The texture consists of a black and white texture (all or nothing), ranging from completely unshadowed to shadowed (0-1) for its z-axis depth, then following dithering patterns to add more and more interwoven pixels to transition between colors across the x and y axes.
That's great background information. How would you suggest the poster solve the problem?
Unfortunately, doing something about it isn't as easy as identifying the cause.
Any change, as an example, to create a higher-resolution variation on the dithered shadow Texture3D (The texture is 4x4x8, or 4x32 in 2D) would generally involve creating a custom shader, but since the shadowing details are in a reference file for the Standard shader, that means rebuilding parts of the shader just to make a tiny change.
After making such a shader, it would then be necessary to construct the Texture3D (either programmatically or by converting a 2D image into a 3D texture. Then, the image would be sent into the shader using $$anonymous$$aterial.SetTexture() or Shader.SetGlobalTexture to act as a replacement dithering texture.
As an example, I implemented an 8x8x16 variant in my own shader (created as an 8x256 Texture2D) and used it with:
alphaRef = tex3D(_HQDither, float3(input.pos.xy*0.125, alpha*0.96875)).a;
The position values for x, y, and z all needed to be modified to accommodate the new dimensions of the texture, as well.
That said, even then, this doesn't actually solve the "problem" in the shadow. The "problem" is one that's not easily solved... at least, not in a realtime engine... However, this does mitigate the symptoms greatly by increasing the granularity in the shadow dithering.
(I'll add an image here once Unity Answers decides to let me)
Answer by bromley · Jul 16, 2016 at 05:57 AM
Here the material properties
Bias adjustment "solve" the problem, but i think that i have to modify material properties
Thanks for answers... now i think that ShaderLab may be a good solution
Answer by Glurth · Jul 16, 2016 at 01:25 PM
If you are willing to eliminate the shadow completely: You could put the glass on a layer that is ignored by the light (light's culling mask field). This way it won't cast any shadow (alas, NOR be lit normally).
You could also just disable shadow casting on the mesh renderer.
Well, if you want to be all efficient and stuff... ;) I want to delete my answer now, ok?
Your answer
Follow this Question
Related Questions
Custom Sprite Shader Ignore Light 1 Answer
Unity 3d Lights, Shadows and material of objects? 1 Answer
Odd shadow effect, help! 1 Answer
"Interesting" Shader 2 Answers