-
-
Notifications
You must be signed in to change notification settings - Fork 35.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shading issue #1509
Comments
That's probably because you are using alpha testing. For visual rendering some parts of triangles are thrown away but for shadows whole mesh is visible. Solution is to use custom depth material matching the visible material. mesh.customDepthMaterial = myDepthMaterial; You can create custom depth material as https://github.com/mrdoob/three.js/blob/master/src/renderers/WebGLShaders.js#L1668 |
To be exact, I have to play around smth like that? 'depthRGBA': {
uniforms: {
'texture': {type: 't', value:0, texture: []}
},
vertexShader: [
THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
"void main() {",
"vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
THREE.ShaderChunk[ "morphtarget_vertex" ],
THREE.ShaderChunk[ "default_vertex" ],
"}"
].join("\n"),
fragmentShader: [
"uniform sample2D texture;",
"vec4 pack_depth( const in float depth ) {",
"const vec4 bit_shift = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );",
"const vec4 bit_mask = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );",
"vec4 res = fract( depth * bit_shift );",
"res -= res.xxyz * bit_mask;",
"return res;",
"}",
"void main() {",
"if (texture.a < 0.5)",
"discard;",
"gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z );",
"}"
].join("\n")
} Am I right? |
I guess, I was right :) I created that shader, but it only changed the shadow on the cylinder so that it now respects alpha, but still no changes for a character. I've updated demo, so you can see this. |
You can try to play with Your particular model + light direction setup seems to respond best to small negative bias. I got somehow okeish shadows with Just seems you've got your material too bright, probably to compensate for self-shadowing, you need to tune ambient and directional lights; shadows look more "in place" when lighting is different: Also make light frustum as tight as possible (in all six planes). Plus as this model has a lot of open surfaces, you may want to try setting: renderer.shadowMapCullFrontFaces = false; This will get you different type of artefacts. This is a complex model seen from very close, so I think there'll always be some artefacts. You'll need to experiment and see what looks the best. Tweaking shadow maps is more art than science. If you play with numbers (light frustum, shadow bias, light direction, shadow map resolution), you'll get a feel for what are tradeoffs. |
Oh, man, thank you! This just looks awesome! The main problem was that i had rather small
And a bit of offtopic - how to create on GitHub formatted text like in #1135? In "GitHub Flavored Markdown" I've only found ```javascript, but it seems that it doesn't work for me... |
That looks much better than before ;)
Shadow map is computed from the real geometry, so things that are just "painted" on surface have no effects (like smooth shading or normal maps), the only thing that enters shadow computation is mesh outline. But these artefacts on the face are not caused by this. Most likely it's coming from light direction vs triangles orientation. Some combinations perform really badly (more parallel the worse). You can try to move your light in different directions, you may hit better or worse artefacts. Also you can try to turn off shadow filtering: renderer.shadowMapSoft = false; This will give you different type of artefacts.
Not really, this would be more complicated, you would need to somehow compute shadows from normal map separately in normal map shader and mix them with shadows from shadowmapping. I think this is done by raycasting using heightmap and in general is really slow.
It's
I use |
Different specular term, more accurate but also more costly.
Light frustum for directional lights (which use
Not really. You could try to use smaller resolution shadow map, but then it would just look uglier. We would need something like this: http://www.glge.org/variance-shadow-maps-in-webgl/ Variance shadow maps however come with own specific artefacts, in some situations there are very ugly light patches inside shadowed areas. And they are more expensive. Still may be worth trying. One day.
You don't turn shadows on/off with If you want to turn off shadows dynamically, you will need to turn off shadow casting on all objects that cast shadow. Shadow receiving can't be turned off, this is baked in materials, but you can turn off shadow casting to achieve shadow-less look.
Whatever works for you ;). That's beauty of git, everybody works on own clone and if there some piece of code interesting for others, they can merge it. Fixes for Opera would be interesting. |
Bah :S. I had to switch from Though this was with
I don't know how to do shadows for semi-transparent things. I didn't even start touching that topic. Regular shadowmaps are just on/off, either you have shadow or you don't, there is no in between. Transparent object alone are massive pain, I expect transparent objects + shadows would be even worse. |
In the last Opera build (12.00.1359) |
Hi guys! I'm having another trouble. I've included shadow mapping into my scene, but it doesn't work as I expected. Here's the simple demo: http://malgalad.dyndns.org/demo. As you can see, shadows are correctly projected on the Cylinder geometry, but shadows on the character... they're completely broken. I'm actually porting shaders from Aion: The tower of eternity (CryEngine 1), and this is how it should look ingame: http://ipic.su/img/img3/fs/Aion0003.1331749429.jpg - hair drops shadow on the face, shoulder pads - on the arms, face itself - on the neck etc. I don't have any idea where's the solution, do you have any ideas?
The text was updated successfully, but these errors were encountered: