【发布时间】:2015-05-11 06:45:38
【问题描述】:
我正在创建一家销售钻石首饰的在线商店,我们的主要目标是让这些钻石看起来非常吸引眼球。不幸的是,我不知道如何在 WebGL 中实现反射和折射。
我的第一次尝试是制作一个圆形钻石,然后通过在 3dsmax 和 vray 中将相机放置在钻石内来渲染天空盒。这给了我一个漂亮的天空盒(充满了多面扭曲,就像钻石一样),但一旦应用于 Three.js 中的折射/反射朗伯材料,它看起来并不有趣。
所以我开始研究自定义着色器,我偶然发现了这个链接 https://www.shadertoy.com/view/4sSGDc
现在我的问题是我找不到让three.js 编译着色器的方法。跟随这里的其他线程,我发现了如何设置一些制服:(例如,Texture2D)但这样的错误不断出现:
THREE.WebGLShader: gl.getShaderInfoLog() ERROR: 0:163: 'textureCube' : no matching overloaded function found
ERROR: 0:163: 'assign' : cannot convert from 'const float' to 'highp 4-component vector of float'
ERROR: 0:168: 'textureCube' : no matching overloaded function found
ERROR: 0:168: 'r' : field selection requires structure, vector, or matrix on left hand side
ERROR: 0:169: 'textureCube' : no matching overloaded function found
ERROR: 0:169: 'g' : field selection requires structure, vector, or matrix on left hand side
ERROR: 0:170: 'textureCube' : no matching overloaded function found
ERROR: 0:170: 'b' : field selection requires structure, vector, or matrix on left hand side
ERROR: 0:185: 'textureCube' : no matching overloaded function found
ERROR: 0:185: 'assign' : cannot convert from 'const float' to 'highp 4-component vector of float'
ERROR: 0:196: 'fragCoord' : undeclared identifier
ERROR: 0:196: 'x' : field selection requires structure, vector, or matrix on left hand side
ERROR: 0:196: 'y' : field selection requires structure, vector, or matrix on left hand side
ERROR: 0:210: 'fragColor' : undeclared identifier
ERROR: 0:210: 'assign' : cannot convert from 'highp 4-component vector of float' to 'float'
我不希望有人为我解决这个问题,但我要求一些线索来了解首先查看的位置,或者是否有一些转换此着色器的捷径。这是该项目非常重要的一部分,因此我将非常感谢任何帮助! 谢谢!
【问题讨论】:
-
您不能只复制着色器。着色器是小程序。它们需要大量自定义输入(属性、纹理、制服)。复制着色器不会带来运行所需的所有其他基础设施和数据。没有简单的解决方案。您必须阅读着色器,了解它在做什么以及它需要什么数据,然后提供该数据。 shadertoy r 上的着色器通常是光线投射着色器,这意味着它们速度慢且数学密集。 See this Q&A for pointers in that direction.