3DStreet / 3dstreet

🚲🚶🚌 Web-based 3D visualization of streets using A-Frame
https://3dstreet.app
Other
256 stars 33 forks source link

discussion: set renderer settings using javascript at instantiation? #872

Open kfarr opened 1 week ago

kfarr commented 1 week ago

@vincentfretin for discussion, curious to get your thoughts -- both logdepthbuffer and preservedrawbuffer are settings that we want to set in some cases, but maybe not in others.

For example logdepth doesn't work with gaussian splat scenes at the moment, and in theory preserveddrawbuffer may result in undesirable performance on lower power devices (not proven).

One approach is to be able to set these renderer settings when it is instantiated but instead of as attributes on the a-scene, instead to use javascript logic -- either from a querystring, hash, or a database lookup.

vincentfretin commented 1 week ago

With the current aframe code, logarithmicDepthBuffer can only be set initially in the html, see https://github.com/aframevr/aframe/blob/daf507ec1022380787f218bc71bc96d4a7d6a9d0/src/core/scene/a-scene.js#L636

In my project I'm generating the a-scene from solidjs

<a-scene
        attr:renderer={`anisotropy:4;stencil:true;physicallyCorrectLights:true;colorManagement:true;logarithmicDepthBuffer:${
          searchParams.logarithmicDepthBuffer === "true"
        }`}
>

so I can use ?logarithmicDepthBuffer=true in the url.

The aframe code doesn't really allow to recreate the WebGLRenderer with a different config, and I don't think you can change logarithmicDepthBuffer after it's created. You would need to change the aframe code to check for a query string in the url, that would be the simpler change.

kfarr commented 1 week ago

The aframe code doesn't really allow to recreate the WebGLRenderer with a different config, and I don't think you can change logarithmicDepthBuffer after it's created.

@vincentfretin thanks yes that's the point of my question here. It does seems like you are doing exactly what I'm suggesting via solidjs -- is that not possible with 3dstreet because of index.html structure hardcoding the values -- and the only way to do that is to inject the a-scene dynamically such that we can control the attribute values of renderer like you are doing with solidjs? Or is it possible to set the attribute value of renderer prior to the scene being instantiated?

Here's a not good, crazy idea but just brainstorming another way:

vincentfretin commented 1 week ago

Oh actually it should now be possible to wait before initializing aframe in aframe 1.6.0/master with https://github.com/aframevr/aframe/pull/5481