Three.js 三个是相关的。什么导致GPU过载?有很多空闲时间,但帧速率很低
您好,我目前正在为我的公司开发一个模型查看器,我们查看的模型可能非常庞大(元素的数量可能高达6-7位数,并且它们来自不同的机构,因此我们无法控制模型)。几何图形来自多个小json文件。在每个文件中,我都尝试将多个元素合并到一个BufferGeometry中,共享相同几何体的元素将使用InstancedBufferGeometry创建 当我在threejs中加载模型时,在合并和实例化之后,大约有15000个几何体(合并和实例化)。当我试图移动相机时,帧速率非常低。我检查了性能配置文件,发现主堆栈之间有很多空闲时间,但空闲时间被GPU填满,最终导致低帧速率。(我还无法添加图片,因为我是堆栈溢出的新手:() 起初我认为这可能是我的笔记本电脑硬件问题,但我曾尝试将相同型号的笔记本电脑加载到不同的现有平台上,例如BIM360,该平台也使用ThreeJS,但它似乎没有太多使用GPU,而且在那里的运行非常平稳。因此,我不确定我的实现中使用GPU会有什么问题这么长时间导致帧速率下降 我真的是新手,所以如果有人能解释一下GPU过载到导致前端性能下降的原因,我将不胜感激 其他信息 我已根据需要对着色器进行了一些更改(对合并几何体和实例化几何体使用MeshLambertMaterial):Three.js 三个是相关的。什么导致GPU过载?有很多空闲时间,但帧速率很低,three.js,gpu,Three.js,Gpu,您好,我目前正在为我的公司开发一个模型查看器,我们查看的模型可能非常庞大(元素的数量可能高达6-7位数,并且它们来自不同的机构,因此我们无法控制模型)。几何图形来自多个小json文件。在每个文件中,我都尝试将多个元素合并到一个BufferGeometry中,共享相同几何体的元素将使用InstancedBufferGeometry创建 当我在threejs中加载模型时,在合并和实例化之后,大约有15000个几何体(合并和实例化)。当我试图移动相机时,帧速率非常低。我检查了性能配置文件,发现主堆栈之
const replaceDefaultShaders=shader=>{
shader.vertexShader=shader.vertexShader.replace(
`void main(){`,
`属性外生能力;
属性浮动显示;
可变浮动vAlpha;
可变浮动vShow;
void main(){
vAlpha=垂直外产能;
vShow=显示`
);
shader.fragmentShader=shader.fragmentShader.replace(
`vec4 diffuseColor=vec4(漫反射,不透明度);`,
`vec4漫反射颜色=vec4(漫反射,vAlpha);
如果(vShow==0.0)放弃;
如果(vAlpha==0.0),则丢弃`
);
shader.fragmentShader=shader.fragmentShader.replace(
`均匀vec3漫反射;`,
`均匀vec3扩散;
可变浮动vAlpha;
可变浮动vShow`
);
};
const replaceSharedDefaultShaders=着色器=>{
shader.vertexShader=`
属性向量4 aInstanceMatrix0;
属性向量4 ainstancematrix 1;
属性向量4 ainstancematrix 2;
属性向量4 ainstancematrix 3;
属性向量3;标准颜色;
属性浮动能力;
属性浮动ainstateshow;
可变vec3乙烯色;
可变浮子容量;
不同的浮法葡萄酒展示;
${shader.vertexShader}
`;
shader.vertexShader=shader.vertexShader.replace(
"包括",,
`
mat4 aInstanceMatrix=mat4(
AINStanceMatrix,
AINStanceMatrix 1,
aInstanceMatrix2,
AINStanceMatrix 3
);
vec3转换=(aInstanceMatrix*vec4(位置,1.)).xyz;
vInstanceColor=aInstanceColor;
乙烯产能=乙烯产能;
vInstanceShow=aInstanceShow;
`
);
shader.vertexShader=shader.vertexShader.replace(
"包括",,
`
mat4 _aInstanceMatrix=mat4(
AINStanceMatrix,
AINStanceMatrix 1,
aInstanceMatrix2,
AINStanceMatrix 3
);
vec3 objectNormal=(_aInstanceMatrix*vec4(normal,0.)).xyz;
`
);
shader.fragmentShader=`
可变vec3乙烯色;
可变浮子容量;
不同的浮法葡萄酒展示;
${shader.fragmentShader}
`;
shader.fragmentShader=shader.fragmentShader.replace(
'vec4 diffuseColor=vec4(漫反射,不透明度);',
`
vec4 diffuseColor=vec4(乙烯色、乙烯容量);
如果(乙烯产能==0.0)丢弃;
如果(vInstanceShow==0.0)丢弃;
`
);
};
const replaceDefaultShaders = shader => {
shader.vertexShader = shader.vertexShader.replace(
`void main() {`,
`attribute float vertexOpacity;
attribute float show;
varying float vAlpha;
varying float vShow;
void main() {
vAlpha = vertexOpacity;
vShow = show;`
);
shader.fragmentShader = shader.fragmentShader.replace(
`vec4 diffuseColor = vec4( diffuse, opacity );`,
`vec4 diffuseColor = vec4( diffuse, vAlpha );
if (vShow == 0.0) discard;
if (vAlpha == 0.0) discard;`
);
shader.fragmentShader = shader.fragmentShader.replace(
`uniform vec3 diffuse;`,
`uniform vec3 diffuse;
varying float vAlpha;
varying float vShow;`
);
};
const replaceSharedDefaultShaders = shader => {
shader.vertexShader = `
attribute vec4 aInstanceMatrix0;
attribute vec4 aInstanceMatrix1;
attribute vec4 aInstanceMatrix2;
attribute vec4 aInstanceMatrix3;
attribute vec3 aInstanceColor;
attribute float aInstanceOpacity;
attribute float aInstanceShow;
varying vec3 vInstanceColor;
varying float vInstanceOpacity;
varying float vInstanceShow;
${shader.vertexShader}
`;
shader.vertexShader = shader.vertexShader.replace(
'#include <begin_vertex>',
`
mat4 aInstanceMatrix = mat4(
aInstanceMatrix0,
aInstanceMatrix1,
aInstanceMatrix2,
aInstanceMatrix3
);
vec3 transformed = ( aInstanceMatrix * vec4( position, 1. ) ).xyz;
vInstanceColor = aInstanceColor;
vInstanceOpacity = aInstanceOpacity;
vInstanceShow = aInstanceShow;
`
);
shader.vertexShader = shader.vertexShader.replace(
'#include <beginnormal_vertex>',
`
mat4 _aInstanceMatrix = mat4(
aInstanceMatrix0,
aInstanceMatrix1,
aInstanceMatrix2,
aInstanceMatrix3
);
vec3 objectNormal = ( _aInstanceMatrix * vec4( normal, 0. ) ).xyz;
`
);
shader.fragmentShader = `
varying vec3 vInstanceColor;
varying float vInstanceOpacity;
varying float vInstanceShow;
${shader.fragmentShader}
`;
shader.fragmentShader = shader.fragmentShader.replace(
'vec4 diffuseColor = vec4( diffuse, opacity );',
`
vec4 diffuseColor = vec4( vInstanceColor, vInstanceOpacity );
if (vInstanceOpacity == 0.0) discard;
if (vInstanceShow == 0.0) discard;
`
);
};