使用three.js在片段着色器中手动选择多图谱 [英] Manual selection lod of mipmaps in a fragment shader using three.js

查看:154
本文介绍了使用three.js在片段着色器中手动选择多图谱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Three.js中使用glsl es编写基于物理的着色器.对于镜面全局照明的添加,我使用了内部带有mipmap链的cubemap dds纹理(使用CubeMapGen进行了预先计算,因为它的解释

I'm writing a physically based shader using glsl es in three.js. For the addition of specular global illumination I use a cubemap dds texture with mipmap chain inside (precalculate with CubeMapGen as it's explained here). I need to access this texture in fragment shader and I would like to select manually the index of mipmap. The correct function for doing this is

vec4 textureCubeLod(samplerCube sampler, vec3 coord, float lod)

,但仅在顶点着色器中可用.在我的片段着色器中,我正在使用类似的功能

but it's available only in vertex shader. In my fragment shader I'm using the similar function

vec4 textureCube(samplerCube sampler, vec3 coord, float bias)

,但是效果不佳,因为bias参数只是添加到了自动计算的细节级别中.因此,当我放大或缩小场景时,mipmap的LOD会发生变化,但对于我的着色器,它必须是相同的(如上面的链接所述,它必须仅取决于粗糙参数).

but it doesn't work well, because the bias parameter is just added to the automatically calculated level of detail. So, when I zoom in or zoom out on the scene the LOD of mipmap change, but for my shader it must be the same (it must depends only on the rough parameter, as explained in the link above).

我想手动选择片段着色器中的mipmap的级别仅取决于材质的粗糙度(例如,使用公式mipMapIndex = roughness*numMipMap),因此它必须随距离变大,并且缩放时不会自动更改.我该如何解决?

I would like to select manually the level of mipmap in fragment shader only depends on the roughness of the material (for example using the formula mipMapIndex = roughness*numMipMap), so it must be costant with the distance and no automatically changed when zooming. How can I solve this?

推荐答案

它不适用于webGL atm,因为不支持此功能.尽管可以使用最近构建的chrome canary进行TextureLOD扩展的试验,但是仍然需要进行一些调整.看看标志,寻找它:

It wont work with webGL atm, because there is no support for this feature. You can experiment with textureLOD extensions though with recent builds of chrome canary, but it still needs some tweaking. Go about flags and look for this:

启用WebGL草案扩展

Enable WebGL Draft Extensions

WebGL textureCube偏斜会导致接缝

这篇关于使用three.js在片段着色器中手动选择多图谱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆