[Sharing is feedback] Shadows with Sketch

mark2e's icon

Hi,

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.

My approach:
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.
Thanks

4068.shadows.jpg
jpg
Rob Ramirez's icon

really awesome! thanks for sharing.

can you post a basic patch demonstrating the anim.node update problem you're experiencing?

strimbob's icon

thanks for sharing!

oli larkin's icon

thanks. crashed my machine pretty hard tho :-)

mark2e's icon

You're welcome, thank you for having a look at it.

@Oli Larking: Crash as in "freeze" or just absurdly low framerates?

Max Patch
Copy patch and select New From Clipboard in Max.

@Robert Ramirez: This patch should demonstrate the issue.
My guess: the problem lies within my improper use of the locklook attribute. ^^

Rob Ramirez's icon

ok i see what you mean. thanks for the patch. i'll see if i can get this fixed.

mark2e's icon

Awesome, thanks!

oli larkin's icon

crashed as in had to hard-reset the machine

mark2e's icon

Damn. Sry.
This happened to me, only when i tried to change the readback method.
Might I ask which machine you tested it with?

yopla's icon

great :o)
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 !
cheers

mark2e's icon

Hi,

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.

benoit-1842's icon

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 !!!!

mark2e's icon

Hi,

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.

yopla's icon

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 !

mark2e's icon

"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.
http://fabiensanglard.net/shadowmappingVSM/index.php

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.

yopla's icon

hello,
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 (https://cycling74.com/forums/problem-with-jit-gl-node-and-multiple-jit-gl-camera-s) or dieter's (https://cycling74.com/forums/sharing-triplehead2go-rendering-setup-updated-for-max6-and-jit-gl-node)

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

cheers

mark2e's icon

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);

have fun.

zcwaa22's icon

Hello,

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.

Thanks