[Sharing is feedback] Shadows with Sketch

Jun 20, 2012 at 12:34pm

[Sharing is feedback] Shadows with Sketch

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

[attachment=197088,4068]

Attachments:
  1. shadows.jpg
#46084
Jun 20, 2012 at 7:38pm

really awesome! thanks for sharing.

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

#166015
Jun 20, 2012 at 8:59pm

thanks for sharing!

#166016
Jun 20, 2012 at 9:18pm

thanks. crashed my machine pretty hard tho :-)

#166017
Jun 21, 2012 at 10:30am

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. ^^

– Pasted Max Patch, click to expand. –
#166018
Jun 21, 2012 at 6:25pm

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

#166019
Jun 21, 2012 at 7:30pm

Awesome, thanks!

#166020
Jun 21, 2012 at 8:10pm

crashed as in had to hard-reset the machine

#166021
Jun 21, 2012 at 9:11pm

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

#166022
Jul 5, 2012 at 7:35pm

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

#166023
Jul 6, 2012 at 12:32pm

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.

#166024
Jul 6, 2012 at 2:11pm

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

#166025
Jul 7, 2012 at 5:28pm

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.

#166026
Jul 16, 2012 at 4:32pm

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 !

#166027
Jul 17, 2012 at 1:08pm

“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.

#166028
Jul 17, 2012 at 3:09pm

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

cheers

#166029
Jul 18, 2012 at 12:49pm

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.

#166030
May 20, 2013 at 2:16pm

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

#249982

You must be logged in to reply to this topic.