Comments (4)
IMO, the use cases which require a manual bias
parameter are very limited. A typical one in the past was #20522 which is about adding a LOD bias for alpha maps.
But because of the specific character of LOD bias, I don't think it's appropriate to introduce a new texture (or material) property. With a naive implementation we would end up with more uniforms that are not required most of the time. To prevent this, we would have to implement additional branches in JS and the GLSL chunks which increases complexity and maintainability.
A global setting seems problematic as well since a texture LOD bias is usually not something that is equal for all textures in an app.
Do you mind describing in more detail why you need control over what mipmap is going to be sampled? Is this control restricted to specific type of textures (like alpha maps)?
from three.js.
Sure, I need it for SSAA (implementation similar to three's SSAARenderPass).
Rendering SSAA in this manner with 2^n samples should be equivalent to rendering into a render target scaled by a factor of 2^sqrt(n) and then down scaling that render target to the original size with a linear filter.
When rendering a mesh into a render target that's scaled by a factor of 2^sqrt(n) the UV derivatives at a given pixel would be scaled by 2^-sqrt(n). The mipmap selection bias compared to rendering without scaling would then be the log of the exponent: log2(-sqrt(n))=-log2(n)/2.
So, in order to achieve the same effect as rendering into a larger render target I'd like to introduce this texture lod bias of -log2(n)/2 when rendering individual samples in SSAA.
Hopefully my explanation is clear enough
from three.js.
Thanks for the additional details.
I do not yet understand why you need a new texture property though. Do you modify built-in shaders for your SSAA implementation?
from three.js.
SSAA doesn't use any custom shader. It just renders the scene 2^n times with a slight camera view offset each time and averages the results. If I wanted to incorporate the load bias I'd have to modify a lot of internal shaders (pretty much every material texture sample).
The (very loose) pseudo code would be something like this:
scene.setGlobalTextureLodBias(-Math.log2(viewOffsets.length) / 2); // This is the thing I'd like to be able to do but can't currently
const viewOffsets = [...];
for (const viewOffset of viewOffsets) {
camera.setViewOffset(viewOffset);
webglRenderer.setRenderTarget(sceneRt);
webglRenderer.clear();
webglRenderer.render(scene, camera);
// ...copy sceneRt into an accumulationRt with AdditiveBlending and opacity of 1.0 / viewOffsets.length
}
A way this could work is by replacing all texture2D
calls in material shaders with something like:
vec4 textureSample(in sampler2D sampler, in vec2 uv) {
return texture2D(sampler, uv, TEXTURE_LOD_BIAS);
}
Where TEXTURE_LOD_BIAS is a define that defaults to 0. Scene.setGlobalTextureLodBias
would set this to the specified value.
If WebGL2 supported the TEXTURE_LOD_BIAS sampler parameter this would be much simpler to do as the property could be set on sampler objects and shaders wouldn't have to be touched. But alas it doesn't, and there are no extensions for it. WebGPU also douesn't support it.
from three.js.
Related Issues (20)
- glTF asset not correctly view frustum culled. HOT 7
- Editor: Open editor directly without navigating to its directory. HOT 1
- FileLoader.js fetch(…).then(…).catch(…).finally(...) finally is not a function. in some android devices. HOT 1
- Support for BlockBench Models (JSON) HOT 6
- Suggestion: Public the `WebGLAnimation.isAnimating` variable in `WebGLRenderer` HOT 3
- Customizable cache implementation HOT 9
- AR session origin seems to jump after placement HOT 3
- directional light halo flickers in mobile devices (possibly Adreno gpus) HOT 23
- make Color accept strings that are numbers HOT 2
- improve `morphAttributes` perfomance HOT 16
- Blue channel of anisotropyTexture causing odd behavior HOT 8
- Close Path doesn't return `this` HOT 1
- Classes not extendable HOT 3
- Exception when loading files with lights in the editor HOT 3
- Editor: `#Viewport` should not be change when move the mouse after click `.Select` element. HOT 2
- "When transmission is non-zero, opacity should be set to 0." Is that really true? HOT 5
- Editor: Serialization support for environment dropdown "MODELVIEWER" option HOT 1
- GLTFLoader: Some clearcoat materials are imported as MeshStandardMaterial HOT 2
- Custom shader support for WebGPURenderer HOT 6
- ColorManagement: Document which three.js colors are intended to be in linear and sRGB space HOT 2
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.js.