我想要一种不现实的特殊效果。
渲染网格时,我不希望渲染在Y轴上受到影响。这意味着对于特定的列,透视图必须相同。因此,透视图仅受(x,z)位置影响。
您认为有可能吗?
答案 0 :(得分:0)
作为POC,我很快做了一个快速修改,就是要更改three.js中的一行。
我替换了这一行:
var project_vertex = `"vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );\ngl_Position = (projectionMatrix * mvPosition);";`
作者:
var project_vertex = "vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );\ngl_Position = (projectionMatrix * mvPosition);\ngl_Position.y = gl_Position.y*gl_Position.w;";
这个答案How to draw ortho axes for object in perspective projection using modern OpenGL?解释说,将坐标乘以最后一个分量w可以删除透视图。
现在,我必须找到一种正确的方法来将其与three.js正确集成,并且可以在我们要禁用透视图的任何轴上使用。
更新
一种无需修改three.js的方法:
//As stated here : https://stackoverflow.com/questions/49918798/how-to-draw-ortho-axes-for-object-in-perspective-projection-using-modern-opengl
// In order to remove the perspective in one axis, you have to muliply by the 4th component of gl_position (w)
var project_vertex_custom = "vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );\ngl_Position = (projectionMatrix * mvPosition);"
if (disablePerspectiveAxis.indexOf("x") >= 0)
project_vertex_custom += "\ngl_Position.x = gl_Position.x*gl_Position.w;";
if(disablePerspectiveAxis.indexOf("y") >= 0)
project_vertex_custom += "\ngl_Position.y = gl_Position.y*gl_Position.w;";
//Update the glsl code in three.js
THREE.ShaderChunk.project_vertex = project_vertex_custom;