-
Notifications
You must be signed in to change notification settings - Fork 124
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
Sprite Material support #101
Comments
I'm not deeply familiar with Three's At first glance, though, it appears pretty specific to That's something that could be generically useful. I may take a swing at it at some point but no guarantees. There may be something already existing out there though. |
Hey there thanks for your reply - actually I think https://threejs.org/docs/#api/en/objects/Sprite |
Right, I was able to make a quick proof-of-concept shader that does that. Here's the relevant code from the vertex shader: vec4 mvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );
mvPosition.xyz += position;
gl_Position = projectionMatrix * mvPosition; Basically it uses the modelViewMatrix to find the object's origin, and then does a direct addition of the vertex With that code in a ShaderMaterial, I was able to assign it to Text instances and it worked as expected. I may try to bundle that up as a reusable material for any mesh (nothing Text-specific here), but like I said before no guarantees. ;) |
Added maintaining the scale: vec4 mvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );
vec3 scale = vec3( length(modelViewMatrix[0].xyz), length(modelViewMatrix[1].xyz), length(modelViewMatrix[2].xyz) );
mvPosition.xyz += position * scale;
gl_Position = projectionMatrix * mvPosition; |
Here's an example in action, using createDerivedMaterial from troika-three-utils. You should be able to use that directly. I do think I'll formalize this, with some fixes to normals so lighting works as expected. It's a very flexible approach -- any material can be used as the base, and it can be applied to any mesh. Keep in mind though that it does have drawbacks, like not being raycastable. |
Ah hah! Yes this is excellent! I really enjoy using your implementation, there are not many text libraries with SDF that work well or are as flexible. Adding support for this use case is really helpful. Thanks so much for your time in putting together an example and look forward to seeing this in your library in the future. |
Hello, this is really great. |
I've updated the CodeSandbox example to the latest libraries. |
Imagine a RPG style game where each player has a nameplate. For example ( https://i.imgur.com/KxgTpuu.jpg ).
Working with
MeshBasicMaterial
orMeshPhongMaterial
we would need to use anonBeforeRender handler that adjusts the whole group's world matrix based on camera frustum on each frame
as you've suggested here.A Sprite Material has these optimizations baked in to handle this exact scenario. It feels like following your suggestion will lead to rolling our own Sprite Material, which is likely going to have much worse performance and usability than Three's.
It will also really complicate solutions. Imagine all the other use cases in the scene that need a Sprite's behavior but belong to different object groups with different object hierarchy's. There would never be a one size fits all in the same way a Three's Sprite behaves.
Would really appreciate support for Sprite Material as it would both improve performance of our implementation along with developer usability of your library.
The text was updated successfully, but these errors were encountered: