我无法设法使用ssao和three.js。 我试图按照webgl_postprocessing_dof.html例如: 这里是initPostprocessingThree.js和ssao
function initPostprocessing() {
postprocessing.scene = new THREE.Scene();
postprocessing.camera = new THREE.OrthographicCamera(window.innerWidth/- 2, window.innerWidth/2, window.innerHeight/2, window.innerHeight/- 2, -10000, 10000);
postprocessing.camera.position.z = 100;
postprocessing.scene.add(postprocessing.camera);
var pars = { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBFormat };
postprocessing.rtTextureDepth = new THREE.WebGLRenderTarget(window.innerWidth, height, pars); //modifier 500
postprocessing.rtTextureColor = new THREE.WebGLRenderTarget(window.innerWidth, height, pars);
var ssao_shader = new THREE.ShaderMaterial(THREE.ShaderExtras[ "ssao" ]); //modification
postprocessing.ssao_uniforms = THREE.UniformsUtils.clone(ssao_shader.uniforms);
postprocessing.ssao_uniforms[ "tDepth" ].value=1;
postprocessing.ssao_uniforms[ "tDiffuse" ].value=1;
postprocessing.ssao_uniforms[ "fogEnabled" ].value=1;
postprocessing.ssao_uniforms[ "fogFar" ].value=100;
postprocessing.ssao_uniforms[ "fogNear" ].value=0;
postprocessing.ssao_uniforms[ "onlyAO" ].value=0;
postprocessing.ssao_uniforms[ "aoClamp" ].value=0.1;
postprocessing.ssao_uniforms[ "lumInfluence" ].value=0.1;
postprocessing.materialSSAO = new THREE.ShaderMaterial({
uniforms: postprocessing.ssao_uniforms,
vertexShader: ssao_shader.vertexShader,
fragmentShader: ssao_shader.fragmentShader
});
}
功能和渲染功能:
function render() {
renderer.clear();
// Render depth into texture
scene.overrideMaterial=material_depth;
renderer.render(scene, camera, postprocessing.rtTextureDepth, true);
// Render color into texture
scene.overrideMaterial = null;
renderer.render(scene, camera, postprocessing.rtTextureColor);
//
postprocessing.materialSSAO.uniforms[ "tDepth" ].texture=postprocessing.rtTextureDepth;
postprocessing.materialSSAO.uniforms[ "tDiffuse" ].texture=postprocessing.rtTextureColor;
postprocessing.scene.overrideMaterial = postprocessing.materialSSAO;
renderer.render(postprocessing.scene, postprocessing.camera);
}
也许我误解的东西。
你有没有看一下这个例子吗? http://alteredqualia.com/three/examples/webgl_postprocessing_ssao.html – mrdoob
是的,但我不想使用本例中使用的“DepthPassPlugin” – user1482030