Comments (9)
Ahh yes, instanceMatrix is not available if not used with InstancedMesh. Glad itβs solved π
from three-customshadermaterial.
csm_PositionRaw
is the same as gl_Position
thus, to use it with InstancedMesh, you need to multiply the position with the instanceMatrix
before projection
csm_PositionRaw = projectionMatrix * modelViewMatrix * instanceMatrix * vec4(position, 1.0);
Let me know if this fixes your issue
csm_Position
is the prefered way to override vertex position as you dont need to project or multiply the instanceMatrix
to it, it is done for you.
from three-customshadermaterial.
@FarazzShaikh thanks for reply π
It's very strange, but I get an error:
ERROR: 0:472: 'instanceMatrix' : undeclared identifier
instanceMatrix it should be because I tried to declare attribute mat4 instanceMatrix;
it and got an error
ERROR: 0:394: 'instanceMatrix' : redefinition
csm_Position is the prefered way to override vertex position as you dont need to project or multiply the instanceMatrix to it, it is done for you.
I'm working with csm_PositionRaw because I need to convert the vertex position to world coordinates, and csm_Position needs to be passed to local coordinates.
from three-customshadermaterial.
What is your baseMaterial? Can you make a Sandbox (https://codesandbox.io/)? I will debug
from three-customshadermaterial.
Here: https://codesandbox.io/s/wizardly-neco-hczrcn?file=/src/App.tsx:869-976
It seems to work just fine. In my sandbox. Toggling "instanceMesh" in the controls will toggle the multiplication of the matrix.
from three-customshadermaterial.
@FarazzShaikh yeah, sorry for delay, I never used the sandbox)
My sandbox is working fine... strange.
https://codesandbox.io/s/kind-vaughan-thjnch?file=/src/index.js
ok, I will search and fix the error in my project.
Thank you so much for support.
Please do not close the Issue, later I will answer what the problem was π
from three-customshadermaterial.
Found the cause of the problem, I was used the material not only in InstancedMesh π€¦ββοΈ
from three-customshadermaterial.
What was the solution?
from three-customshadermaterial.
What was the solution?
Use USE_INSTANCING
preprocessor directive.
#ifdef USE_INSTANCING
vec4 vertexWorldPosition = modelViewMatrix * instanceMatrix * vec4(position, 1.0);
#else
vec4 vertexWorldPosition = modelViewMatrix * vec4(position, 1.0);
#endif
from three-customshadermaterial.
Related Issues (20)
- Shaders not working HOT 2
- ERROR: 0:645: 'csm_Normal' undeclared identifier HOT 1
- Override fragment normals? HOT 6
- Is it possible to output a normal from a fragment shader? HOT 2
- "Multiple instances of Three.js being imported" issue HOT 3
- Can you disable projection in the vertex shader? HOT 3
- CustomShaderMaterial error HOT 6
- Add csm_Bump? HOT 5
- If the base material has a map, a CSM from it throws an error on three >= 0.151.0 HOT 1
- Shader compilation failure if csm_Feature used is not compatible with base material HOT 2
- Warning: Function copy already exists on CSM, renaming to base_copy HOT 2
- Support macro defines like THREE.ShaderMaterial HOT 1
- Waves example seems to be broken HOT 3
- Extended meshBasicMaterial does not have access to cameraPosition uniform HOT 3
- TresJs implementation HOT 2
- How to change the opacity of extended material ? HOT 3
- Couldn't extend `<MeshReflectorMaterial/>` from `drei` HOT 1
- Feature request addition of transmision and thickness maps HOT 1
- Cannot use both csm_DiffuseColor and csm_FragColor in if/else HOT 3
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-customshadermaterial.