Comments (5)
Thanks, glad you're finding the library useful 😃
It's possible that there's a bug or something that has changed in recent versions of the Three.js library - which version are you using?
Also, since shadows work with a phong material, I assume you have set your objects to cast shadows?
from three.terrain.
Yeah, my objects all cast their shadows when I change the material to Phong Material. I'm just not getting them to work when using your blend shader material... And that one looks the best by far :-)
So I'm thinking it's a problem with the shadowmap not going through to the shader anymore or incorrectly somehow?
Any ideas where I can start looking?
PS. sorry forgot to mention which version i'm using, i'm using r76 (the latest one at the time of this post)
from three.terrain.
I think I found the problem, it seems to be this part:
THREE.ShaderChunk.shadowmap_fragment,
that chunk doesn't exist in the new r76 anymore so it doesn't do any model shadow calculations in the fragment loop. Unfortunately my shader skills are a little lacking so i'm not sure what to put in there. I tried to copy the fragment piece from an earlier three js version, but it just throws more errors :/
Is there any chance you can see what has changed around that bit?
from three.terrain.
Ok, I finally got it working!! WOOHOO, here is my modified fragment shader to enable the shadow map:
`fragmentShader: [
'uniform vec3 diffuse;',
'uniform vec3 emissive;',
'uniform float opacity;',
'varying vec3 vLightFront;',
'#ifdef DOUBLE_SIDED',
' varying vec3 vLightBack;',
'#endif',
THREE.ShaderChunk.common,
THREE.ShaderChunk.packing,
THREE.ShaderChunk.lights_pars,
THREE.ShaderChunk.shadowmap_pars_fragment,
//THREE.ShaderChunk.color_pars_fragment,
//THREE.ShaderChunk.map_pars_fragment,
//THREE.ShaderChunk.alphamap_pars_fragment,
//THREE.ShaderChunk.lightmap_pars_fragment,
//THREE.ShaderChunk.envmap_pars_fragment,
//THREE.ShaderChunk.fog_pars_fragment,
//THREE.ShaderChunk.shadowmap_pars_fragment,
//THREE.ShaderChunk.specularmap_pars_fragment,
THREE.ShaderChunk.logdepthbuf_pars_fragment,
declare,
'varying vec2 MyvUv;',
'varying vec3 vPosition;',
'varying vec3 myNormal;',
'void main() {',
// TODO: The second vector here is the object's "up" vector. Ideally we'd just pass it in directly.
'float slope = acos(max(min(dot(myNormal, vec3(0.0, 0.0, 1.0)), 1.0), -1.0));',
' vec3 outgoingLight = vec3( 0.0 );', // outgoing light does not have an alpha; the surface does
' vec4 diffuseColor = vec4( diffuse, opacity );',
' vec4 color = texture2D( texture_0, MyvUv * vec2( ' + glslifyNumber(t0Repeat.x) + ', ' + glslifyNumber(t0Repeat.y) + ' ) + vec2( ' + glslifyNumber(t0Offset.x) + ', ' + glslifyNumber(t0Offset.y) + ' ) ); // base',
assign,
' diffuseColor = color;',
// ' gl_FragColor = color;',
THREE.ShaderChunk.logdepthbuf_fragment,
//THREE.ShaderChunk.map_fragment,
//THREE.ShaderChunk.color_fragment,
//THREE.ShaderChunk.alphamap_fragment,
//THREE.ShaderChunk.alphatest_fragment,
//THREE.ShaderChunk.specularmap_fragment,
' #ifdef DOUBLE_SIDED',
' if ( gl_FrontFacing )',
' outgoingLight += diffuseColor.rgb * vLightFront + emissive;',
' else',
' outgoingLight += diffuseColor.rgb * vLightBack + emissive;',
' #else',
' outgoingLight += diffuseColor.rgb * vLightFront + emissive;',
' #endif',
//THREE.ShaderChunk.lightmap_fragment,
//THREE.ShaderChunk.envmap_fragment,
//THREE.ShaderChunk.shadowmap_fragment,
//THREE.ShaderChunk.linear_to_gamma_fragment,
//THREE.ShaderChunk.fog_fragment,
'IncidentLight directLight;',
'DirectionalLight directionalLight;',
'float shadowValue = 1.0;',
'for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {',
'directionalLight = directionalLights[ i ];',
'shadowValue = getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] );',
'}',
//' gl_FragColor = vec4( outgoingLight, diffuseColor.a );', // This will probably change in future three.js releases
' gl_FragColor = vec4( outgoingLight*shadowValue, diffuseColor.a );', // This will probably change in future three.js releases
'}'
].join('\n')`
I hope it helps someone!
from three.terrain.
Nice work, thanks. I will have to find some time to review if anything else in the shader needs to be updated to keep up with the changes in Three.js and commit the shadow fix.
from three.terrain.
Related Issues (20)
- Texture Repeating HOT 1
- Typescript bindings? HOT 18
- Feature request: button to download geometry HOT 1
- Possible mismatch in randomness HOT 1
- Meaning of parameters of generateBlendedMaterial? HOT 2
- BlendedTerrain problem HOT 1
- Island with a hill, how? HOT 2
- Large memory consumption, why? HOT 2
- Support disabling rescaling in Clamp to avoid seams with repeating Perlin/Simplex terrains HOT 17
- generateBlendedMaterial to support normalMaps / StandardMeshMaterial. HOT 4
- physics support ? HOT 1
- I m facing error using your library HOT 2
- Edges Documentation HOT 1
- Calculating heights between segments (Interpolation) HOT 3
- Wrong variable name in scatter.js HOT 1
- Implement Optimizations HOT 1
- could it load real terrain? HOT 1
- Get heights from generated terrain HOT 1
- Noise Error HOT 1
- Update for newer THREE.js versions (ES6) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from three.terrain.