-
-
Notifications
You must be signed in to change notification settings - Fork 36.1k
Refactor instancing lambert example using onBeforeCompile
#14098
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
Refactor instancing lambert example using onBeforeCompile
#14098
Conversation
mrdoob#10750 Allows for adding stuff to commons chunk for example.
This reverts commit e73c718.
onBeforeCompile
|
Actually, I am not in favor of the approach used in this PR (using injections and string substitutions) because the shader code is obfuscated; the modified shader is not readable. In the current listing it is. Users learn from these examples. |
|
I stand somewhere in the middle on this. I referred to what you're describing as "academic value" - very basic series of atomic steps needed to create an effect or illustrate an algorithm. But per a water-cooler conversation i had with @mrdoob it sounded like he might be in favor of showing how to "properly" use the api. My understanding was that, if there already exists an example of how to use templates, then why not give visibility to The extra 100 lines may make the example daunting, and harder to follow. With comments and proper documentation, a user would know where to look for templates and possible have a better understanding of how they work. As is, i think the example could use more comments, perhaps explaining the following:
|
|
Maybe this is not the best example to add |
|
Sorry about that! |
|
Could you elaborate more? The shader code here is not even glsl, it’s just an ordered list of these include statements. |
|
Ideally, this example should just look something like this: var geometry = new THREE.TorusBufferGeometry( 2, 0.5, 8, 128 );
var material = new THREE.MeshLamberMaterial();
var meshes = new THREE.InstancedMesh( geometry, material );
var positions = new THREE.Curves.TorusKnot( 10 ).getSpacedPoints( 256 );
meshes.setPositions( positions );
scene.add( meshes ); |
|
@mrdoob there are two different things outlined in the example IMHO:
If you remove this example altogether in favor of the suggested API, then this example was a waste of resources. I would still use this for an example for tldr;
You're talking about One is an example of how to use tldr2; We probably don't want: We want:
I'm confused, i'm not sure what they're supposed to learn. If this example should look like @mrdoob described, then it seems like users would learn something completely different. |
|
I think this example was just to show how to use built-in materials with instancing with the current code.
Please, be mindful with your wording. People don't like to be told that they're wasting their time. As per the |
|
Sorry i didn't mean it like that but i feel that i am making a valid point. This is an example of how to do something that involves GLSL, what you are suggesting is an example of how to use a javascript class thats part of three.js. What i meant by wasted time: With yes - not a waste of time With your suggestion, i see absolutely no reason for this to stay. Why would anyone do instancing like this, if it's 3 lines of code with what you presented. If however this is re-purposed to show how to extend materials, with something useful, then this example could stay despite the availability of
No, it never had any issues and worked fine since day one. It had some open questions as to how far the automagic should go (should you be able to change roughness across instances for example). It's downloaded roughly a 100 times a month off of npm. People seem to use it fine, and surprisingly, are not asking for any features. I just like to think of the next steps when i code or design something, (i'm a chess player).
If you have an environment set, you can get this up and running in 1 minute: fun fact: today marks the anniversary of this npm module going live and just... working :) |
No. But until then, it's useful. |
|
Well, I suggest reconsidering this. For learning purposes it would make sense to keep an example like this, and introduce others. I see little reason to have an example for lambert alone, especially if |
|
It's really hard to pinpoint what you guys want :)
It feels odd to modify a global object such as |
|
@pailhead We are all trying to work through this. We are considering a variety of techniques to see what the pitfalls are. Your contributions and experiments have been very illuminating. It is not always clear what approach is 'best'. Often that is a subjective decision. All you and I can do is voice an opinion. I have learned to simply state my opinion and avoid protracted debates. @mrdoob will make a decision and we will move on. I don't take it personally if the decision is not my preference. I think that is good advice for anyone to follow. Be patient, we will get there! :) |
|
But how do we figure out what's best without debates :D |
|
We have some debates, but in general, you and I don't decide what's 'best'. @mrdoob makes that judgment call. |
|
But @mrdoob doesn't have the time to even scratch the surface on these debates. When i got some of his precious times, it sounded like he was really in favor of this PR, i think your dismissal influenced his decision, a lot if not completely :) I would really appreciate a brief discussion here with you, you seemed to have liked this way back in the day:
Seems like you were in favor of this PR in two other places, but dismissed it? Would an alternative example of instancing (not just lambert) with Also what mrdoob mentions above is basically the api from https://www.npmjs.com/package/three-instanced-mesh and #10750. Not to offend anyone but i think apples and oranges are somewhat mixed here. I made the npm module to R&D and see what's needed to not have this coupled with the core. I suggested |
@mrdoob
Per our conversation i submit this PR. It shows how to use material glsl injection to reduce some of the boilerplate with alternate approaches.
Still i'd suggest using a dictionary to store the stuff in a known format (uniforms, attributes, functions, chunks).
This will be the first usage of
onBeforeCompileoutside the example. I'm not super comfortable about that because i think there should be an alternative way to do, so i left a comment pointing to another PR.ping @WestLangley
Btw how can i squash all these commits that i dont even understand where are they coming from. Why is stuff before
6b34d6fshowing up?