2 回答

TA贡献1776条经验 获得超12个赞
你只有单身 sampler2D
这意味着您只有一个纹理可供您使用
不管你绑定了多少。
如果您确实需要将数据作为单个块传递
那么你应该为你得到的每个纹理添加采样器
不确定你有多少对象/纹理
但是通过这种数据传递方式,您受到纹理单元的 gfx hw 限制
您还需要在数据中添加另一个值,告诉哪个图元使用哪个纹理单元
然后在片段内部选择正确的纹理采样器......
你应该添加这样的东西:
// vertex
in int usedtexture;
out int txr;
void main()
{
txr=usedtexture;
}
// fragment
uniform sampler2D myTextureSampler0;
uniform sampler2D myTextureSampler1;
uniform sampler2D myTextureSampler2;
uniform sampler2D myTextureSampler3;
in vec2 UV;
in int txr;
out vec4 color;
void main
{
if (txr==0) color = texture2D( myTextureSampler0, UV ).rgba;
else if (txr==1) color = texture2D( myTextureSampler1, UV ).rgba;
else if (txr==2) color = texture2D( myTextureSampler2, UV ).rgba;
else if (txr==3) color = texture2D( myTextureSampler3, UV ).rgba;
else color=vec4(0.0,0.0,0.0,0.0);
}
由于以下原因,这种传递方式并不好:
使用的纹理数量仅限于硬件纹理单元限制
如果您的渲染需要额外的纹理,如法线/光泽度/光照贴图
那么每个对象类型需要超过 1 个纹理,并且您的限制突然除以 2,3,4 ...
您需要
if/switch
片段内的语句,这会大大减慢速度是的,您可以少吃早午餐,但是您需要一直访问所有纹理,从而无缘无故地增加 gfx 的热应力...
这种传球适合
单个图像中的所有纹理(正如你提到的纹理图集)
对于具有少量对象类型(或材料)但对象数量较多的场景,这种方式可以更快并且合理......
添加回答
举报