本文介绍了如何使用three.js SSAO着色器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 SSAO 后处理着色器渲染场景.没有任何错误,但我看不出使用和不使用 SSAO 传递渲染的场景之间有任何区别.我像这样初始化渲染器:

I'm trying to render a scene with the SSAO post-processing shader. There aren't any errors but I can't see any difference between the scene rendered with and without the SSAO pass. I initialize the renderer like this:

// Create WebGL Renderer
var renderParameters = { antialias: false, alpha: false, clearColor: 0xFFFFFF };
renderer = new THREE.WebGLRenderer(renderParameters);
renderer.autoClear = false;
renderer.setSize(viewportWidth, viewportHeight);

// Create render targets
renderTargetParametersRGB = { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBFormat };
renderTargetParametersRGBA = { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBAFormat };
depthTarget = new THREE.WebGLRenderTarget(width, height, renderTargetParametersRGBA);
colorTarget = new THREE.WebGLRenderTarget(width, height, renderTargetParametersRGB);

// The shader pass to draw the scene
var renderScenePass = new THREE.RenderPass(scene, camera);

// Copy to screen render pass
var copyToScreenPass = new THREE.ShaderPass(THREE.CopyShader);
copyToScreenPass.renderToScreen = true;

// SSAO render pass
effectSSAO = new THREE.ShaderPass(THREE.SSAOShader);
effectSSAO.uniforms['tDepth'].texture = depthTarget;
effectSSAO.uniforms['size'].value.set(width, height);
effectSSAO.uniforms['cameraNear'].value = camera.near; // 1
effectSSAO.uniforms['cameraFar'].value = camera.far;  // 1000
//effectSSAO.uniforms.onlyAO.value = 1;

// Setup post processing chain
composer = new THREE.EffectComposer(renderer, colorTarget);
composer.addPass(effectSSAO);
composer.addPass(copyToScreenPass);

// Depth pass
depthPassPlugin = new THREE.DepthPassPlugin();
depthPassPlugin.renderTarget = depthTarget;
renderer.addPrePlugin(depthPassPlugin);

在渲染函数中,我这样渲染场景:

In the render function, I render the scene like this:

requestAnimationFrame(render);
depthPassPlugin.enabled = true;
renderer.render(scene, camera, composer.renderTarget2, true);
depthPassPlugin.enabled = false;
composer.render(0.1);

正如我之前所说,一切似乎都运行良好,但屏幕上看不到 AO 效果.也许我只是使用了错误的参数值?我已经确保通过将 depthTarget 渲染到场景来更新深度通道.如果我打开 effectSSAO.uniforms.onlyAO.value,我会得到一个非常平坦"的实际场景(包括纹理)的褐色渲染,但仍然没有 AO.有人可以给我建议下一步该尝试什么吗?

As I said before, everything seems to work fine, but there is no AO effect visible on the screen. Maybe I'm just using the wrong parameter values? I already made sure that the depth pass is updated by rendering the depthTarget to the sceen. If I turn effectSSAO.uniforms.onlyAO.value on, I get a pretty "flat" brownish rendering of the actual scene (including textures), but still no AO. Can somebody give me an advice what to try next?

推荐答案

https://twitter.com/mrdoob/status/300919764262477824

这是代码的直接链接:http://goo.gl/RzfwH

感谢 Altered Qualia 和 MrDoob 提供示例代码和three.js 库!

Thanks to Altered Qualia and MrDoob for the example code and the three.js library!

这篇关于如何使用three.js SSAO着色器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 00:18