Home Forums Games202-高质量实时渲染 作业资料 & 代码勘误 Reply To: 作业资料 & 代码勘误

#8324 Score: 1
YunHsiao
Participant
19 pts

## 作业 2

* prt 框架,CMake 生成的 MSVC 项目默认对代码中的中文内容支持有问题(会吞换行符),导致编译报 lambda 没有返回值的错,解决方案是在 prt/CMakeLists.txt 112 行添加:
`cmake
target_compile_options(nori PUBLIC /utf-8) # MSVC unicode support
`
* WebGL 框架,每帧每个模型都在创建和上传相同的 vertex buffer,因而导致这回作业框架的性能相对很低,而且静置一段时间后页面还会随机崩溃。解决办法是提前 cache 这块内存,每帧只需要绑定,不需要创建和上传。
`js
// renderers/MeshRender.js insert to the back of constructor
if (material.attribs.some((a) => a === ‘aPrecomputeLT’)) {
this.#precomputeLTBuffer = gl.createBuffer();
this.#currentEnvmap = -1;
}

// replace renderers/MeshRender.js:204-211
// Bind attribute mat3 – LT
if (this.#precomputeLTBuffer) {
gl.bindBuffer(gl.ARRAY_BUFFER, this.#precomputeLTBuffer);

if (this.#currentEnvmap !== guiParams.envmapId) {
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(precomputeLT[guiParams.envmapId]), gl.STATIC_DRAW);
this.#currentEnvmap = guiParams.envmapId;
}

for (var ii = 0; ii < 3; ++ii) {
gl.enableVertexAttribArray(this.shader.program.attribs[‘aPrecomputeLT’] + ii);
gl.vertexAttribPointer(this.shader.program.attribs[‘aPrecomputeLT’] + ii, 3, gl.FLOAT, false, 36, ii * 12);
}
}
`
* WebGL 框架,不管 shader 里是否实际用到了 mesh 里的 attribute,统一会执行 vertexAttribPoint 等操作,这在比如 shader 里没用使用 aNormalPosition 时,由于反射没取到 location 信息,接下来每帧都会产生 index out of range 报错。不影响运行效果,但可能对作业调试产生干扰。
* 作业描述中的效果截图都没有考虑伽马校正和积分系数 pi 的问题,所以效果其实是不正确的。可以不参考这个截图。

This post has received 1 vote up.