-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
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
Light texture #7060
Light texture #7060
Conversation
Here is an online version of the PR: http://exocortex.github.io/three.js/pr7060/examples Seems very performance on my desktop. |
Errors on Nexus 5:
The current version up on threejs.org works well though, so I think these are specific to the lightTexture. I'm using Remote Debugging in Chrome to get the above data. |
@@ -66,6 +66,7 @@ THREE.UniformsLib = { | |||
|
|||
lights: { | |||
|
|||
"lightTexture" : { type: "t", value: new THREE.DataTexture( new Float32Array( 128 * 4 * 4 ), 4, 128, THREE.RGBAFormat, THREE.FloatType ) }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the data texture should be nearest for filtering and no anisotropy.
Thus something like:
new THREE.DataTexture( new Float32Array( 128 * 4 * 4 ), 4, 128,
THREE.RGBAFormat, THREE.FloatType,
undefined, undefined,
THREE.NearestFilter, THREE.NearestFilter, 0 )
I wonder why DataTextures do not default to nearest,
if they are data then interpolating doesn't make much sense.
Errors on Nexus 5 should be fixed now because it returns to using unforms when there are no float textures. I also improved the constructor of the texture with what you suggested. |
@gero3, the Nexus 5 has float texture support. Here are the extensions I had: One issue was with the DataTexture doing linear interpolation which requires the WEBGL_texture_float_linear extension which my Nexus 5 doesn't have. It may also have required a power of 2 texture -- not sure about that. |
@bhouston a few questions:
|
I think that uniforms are likely faster than data textures -- conjecture but I think it is probably right. Thus we likely want to use uniforms when we can. Thus we could automatically turn on data textyres for lights once we hit a light limit. We could calculate the number of lights we think can reasonably fix into a shader and once we exceed that we switch to a light data texture approach? We could actually hard code this limit to something reasonable to avoid having to do the tricky math of fixing out when it will switch over. I think this is fairly cost free because we already recompile shaders when the number of lights change. We could also have a flag that you can set somehow that forces a light data texture even if it isn't technically needed - which would be useful for testing. |
I guess we could support this by having a renderer flag that disables light textures no matter how many? There are actually different limits to the number of uniforms for vertex and fragment , and the limit is usually higher on vertex. Thus data textures are not as useful for lambert because the limit is so high. I guess I would prefer to not have to do both light textures and light uniforms. But if we needed to have both, one could write a function called, isLightDataTextureNeeded() and isLightUniformsNeeded() and you could have some logic that determines if they are -- based on what is in the scene (# of lights and existance of a lambert material.) (For maximum generality, you could have booleans on a material that state on what type of lighting it supports and that forces behavior on the part of the renderer, but that seems complex.) For both light texture and light unfiroms one could have a shader define if they are present, and it is up to the shader itself to figure out if both defines are present, which it prefers to use - thus you can have lambert using uniforms and other fragment shaders using the data texture. |
BTW in Clara.io we do not support Lambert shading and if we did, we would fake it with a fragment shader doing the lighting on a per pixel basis. It just isn't worth it for us to spend the time to support a vertex based lighting scheme -- too many special case exceptions for low quality results. |
Indeed, Lambert is actually not that important here since 256 vertex uniforms are the minimum. That is close to 60 lights normally. |
Did you forget to switch off "Personal computers" when viewing webglstats.com? It appears that more and more phones only have 128 MAX_VERTEX_UNIFORM_VECTORS. With several matrices, maybe animation, plus some occupied by the implementation for its own use, it's not that plenty - just less of a catastrophic situation than in the fragment shader...
A "Lambertian reflector" describes a material that does not produce specular highlights. Lambert would be pleased and probably call it less of a fake than the Three.js implementation using Gouraud shading :-). |
Familiar point:
#5784 (comment)
|
The examples of this pullrequest are now built and visible in threejsworker. To view them, go to the following link: |
1 similar comment
The examples of this pullrequest are now built and visible in threejsworker. To view them, go to the following link: |
Would you mind re-implementing this with the new/refactored lights code? |
This adds a texture to upload the lights to the gpu instead of using just uniforms as proposed in #7037.
Things that don't work correctly right now: