[Sharing is feedback] Shadows with Sketch
Recently, the need for shadows in my scene arose. So I dove into the whole shader-GL world and after learning a lot new and exciting stuff, I finally have shadows for my scene.
Use 2x sketch for a shadow and a normal-pass within one render-pass.
I also tried to use anim in a reasonable way so i can animate stuff easier in the future.
But, as I am no GL-guru:
Some questions I'd like to ask:
- Is my approach reasonable?
- Are there things which could get overly complicated to implement in the future, such as models with internal textures / materials?
- Is it perhaps even stupid to do it this way?
- Are the shadows correct? (I am not overly gifted concerning visual stuff)
- Why does anim (with automatic 0) only update if i change parameters, even if I send bangs? (or update_node)
- Anything else..?
Any feedback would be greatly appreciated.
really awesome! thanks for sharing.
can you post a basic patch demonstrating the anim.node update problem you’re experiencing?
thanks for sharing!
thanks. crashed my machine pretty hard tho :-)
You’re welcome, thank you for having a look at it.
@Oli Larking: Crash as in "freeze" or just absurdly low framerates?
@Robert Ramirez: This patch should demonstrate the issue.
My guess: the problem lies within my improper use of the locklook attribute. ^^
----------begin_max5_patcher---------- 1266.3oc6Y1sjhhCEG+Z8oHEWsaU1Tj.Hvdky9Lr2s8VcEgHlVHwEB8WSMu6 6IAPQ6VzwE0dpYptDjPL4b9k+ImSR+0wirlKegUZg9CzeiFM5qiGMxTjtfQM OOxJm9RbFszTMqXYdNSnrlT+NE6Eko7urPwJPTwqn6sfxXEBZ18Vn3kTQJaB h8Dq3U0RtHE8rrXUocaCrPJTBZNqtQJ3zr12Hpx4hLlxzu3NUuj+lo5Xhsy1 5JqTsUtsz0TUrtKenfEqpcRRj9GgB80WI902brcP+SyugmXrD47GuCGXoK6a iGquL4DATNqrjlxdGfVKK4JtTfv1HhMb086DAjuGDzxq5hTutlU6+VVa7zOf NdSmpAB1IReKxbEGd.5L8bnS+xmLIMQKQTKYHi4ABpDjppPnKEXm9E4LUgbB pPpnFdVxX4kHt.TXJVxDzJtHgZeu3dwc+0RdIhlUJQKoqWyDP0Vf3MhRSiwE vfBMC5sBXD.rgRjbg4MTAOGANJ.GzukvWrn.raT6nnssM52gd3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j9+IP SmqFN2qq9X6w8LMm5zBnqWCYMU1zjFKAx77w5zLL+OMgADgbapHVErm3s02e rt0913+yKD5oo -----------end_max5_patcher-----------
ok i see what you mean. thanks for the patch. i’ll see if i can get this fixed.
crashed as in had to hard-reset the machine
This happened to me, only when i tried to change the readback method.
Might I ask which machine you tested it with?
i’ll try with gl.sketch.
but at the moment (i don’t pass a lot of time) but i didn’t find how make the grishade invisble with it’s color
my goal is to remove the object and keep the shadow,
thanks for your sharing !
At the moment the only alpha information taken into account while rendering the final image,
is the one stored within the model-textures (colorMap).
Have a look at the last few lines of the shader. where it says gl.FragColor = (…….., base.a)
This "base.a" is the alpha channel of the bound texture. Which is used as value for the written fragment(pixel).
So without changing the code of the shader, you should get invisible objects by using some empty image
(a small *.png with no color whatsoever) as your texture.
When I load my own jit.gl.model object, I am not able to put a texture on… Is it possible or I have to change something more in this awesome patch…Thanx for sharing !!!!
With this patch it should be possible to assign one texture to your model. (At least it works for the demo models, included in Max)
But, as you can see in the image above, the model will be completely textured with the one you chose.
Textures and .mat files included with a model will not work correctly with the setup provided.
To do this, some deeper insight into .mat files and a rewriting of the shader would be necessary.
If you have a look inside the Model-modules, there is a message-box stating: "texture blurSMap colorMap"
"blurSMap" has to be the first texture (as it contains the shadow information)
"colorMap" is the name of the actual texture which will be placed onto the model.
Just make sure the order is correct and it should work.
using a little transparent png as texture works for keeping shadows without objets, thanks
i tried with jit.gl.sketch objets, but it didn’t work (so i export the sketch as .obj and read it in jit.gl.model, then it’s fine :)
using jit.gl.material makes the shadows leaving…
The next step -for me- is using multiple lights. The scene is correct and multiple lights work with gl.material (without shadows..), but only one light is enable with "no material" in your patch.
i think i could mix : create several of the same scene (duplicate objects and cam) with one different light in it, capturing and blend them in screen mode, but if you have a different proposition…
lastly, the shadows are a bit strange with the falof in transprency by distance (the mark2e.point.shadows.tex.jxs shader i think) : the shadow of an object’s face wich is farther of the light could be on front of the shadow of another face, so the complet shadow have a strange look because some transparency of light shouldn’t be …
just try with a simple cube if you don’t understand (my english is ~…) we can see a strange transparency because of one of the face.
with a sAmount at .999, no problems, but it’s quite a shame, beacause the fallof is nice…
thanks again !
"using jit.gl.material makes the shadows leaving…"
Yes, because jit.gl.material generates its own shader and binds it to the object. Which nullifies mine.
"The next step -for me- is using multiple lights."
For shadows from multiple light sources you have to render the scene from the POV of every light.
(what the first sketch does for our single light source)
Then use all those shadowMaps for comparison within the shader. (In a loop probably)
So essentially, what you proposed but without duplicating the scene. But you’d have to rewrite the shader.
"lastly, the shadows are a bit strange with the fallof in transprency by distance"
Yes that’s true. What you see is a disadvantage of the "Variance Shadow Mapping" technique I used here.
The only true method of avoiding this is to use a completely different technique.
But I lack the necessary hardware(> GLSL v. 1.2) for some better looking techniques.
Just have a look around the interwebs. If your hardware supports it, implementing should not be that big of a problem, methinks.
effectively, i’ve made an abstraction of your patch and i fall to 19fps with 3 duplicated scenes with blending… but it works ! ..
i’m not entierly a developer, so i fear about rewrite a shader, but why not trying ..
i’ve also tried to put all the scene (only one this time :) in a jit.gl.node in order to have differents views/camera of the scene, like robert’s patch (http://cycling74.com/forums/topic.php?id=41332) or dieter’s (http://cycling74.com/forums/topic.php?id=38151)
but the night fall.. no more light and/or texture in the node, just black models. Or a big shadow ? or maybe somthing goes wrong with the modelview projection matrice… i don’t now why the forces of the darkness came into my gl world
another question, is there any "variance" variable in your code to have some results like the last picture of fabiensanglard’s site ? (http://fabiensanglard.net/shadowmappingVSM/badUpperLimit.jpg ). It could be relly great to experiment some shadows textures
The whole shader thingy is easier than one would think. At least if you have some experience with code (java, processing…)
The most difficult thing to wrap your head around are the vertex transformations, imho.
If you put the thing in a node you have to be aware that everything has to be part of the node.
Including the jit.gl.shader objects and the textures (especially the shadowmap).
You also could try to play around with jit.window’s "share" attribute, which allows you to share textures across different render-contexts.
The variance is indeed there:
variance = max(variance, 0.000001);
I’m just getting back into an long running (and long neglected) project and it would be amazing to be able to use shadows. Could someone repost MARK2E’s patch? Or am I just not clicking in the right place- the forums have a new look since I was last here.