2

拿到制服,例如

uniforms: {

    "time":  { type: "f", value: 0.0 }

},

例如在哪里

属性浮动自定义频率;属性 vec3 customColor; 去?tia(只是添加了我要转换的代码)

<script type="x-shader/x-vertex" id="vertexshader">
uniform float time;
attribute float customFrequency;
attribute vec3 customColor;
varying vec3 vColor;
void main()
{
    vColor = customColor;
    vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
    gl_PointSize = size;
    gl_Position = projectionMatrix * mvPosition;
}
</script>
<script type="x-shader/x-fragment" id="fragmentshader">
varying vec3 vColor; 
void main()
{
    gl_FragColor = vec4( vColor, 1.0 );
    gl_FragColor = gl_FragColor * texture2D( texture, gl_PointCoord );
}
</script>

很抱歉没有很好地提出问题 - 想从上面的脚本中创建threejs着色器,形式为

THREE.BasicShader = {
    uniforms: {},
vertexShader: [
        "void main() {",
        "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
    "}"
    ].join("\n"),
    fragmentShader: [
        "void main() {",
        "gl_FragColor = vec4( 1.0, 0.0, 0.0, 0.5 );",
    "}"
    ].join("\n")
};

并且找不到使用顶点属性的示例。蒂亚

4

2 回答 2

0

这个问题不是很清楚,但我相信你对基本概念有点困惑。

着色器不应该被转换为 javascript。它们是用 GLSL 语言编写的,浏览器也能理解并传递给显示驱动程序。

Uniforms 是您在 Javascript 代码和 GLSL 着色器之间传递变量的方式。所以你只需要关心 Javascript 端的制服。着色器脚本中的其他代码是着色器 GLSL 代码的一部分,不能与 javascript 共享或转换为 javascript,如果要对其进行更改,则需要修改着色器本身。

于 2013-07-11T12:12:15.573 回答
0

Lee Stemkoski 好心地提供了这个答案:

THREE.BasicShader = {

uniforms: {},

vertexShader: [
"uniform float time;", 
"attribute float customFrequency;",
"attribute vec3 customColor;",
"varying vec3 vColor;",
"void main()",
"{",
"vColor = customColor;",
"vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
"gl_PointSize = (1.0 + sin( customFrequency * time )) * 8.0 * ( 300.0 / length(    mvPosition.xyz ) );",
"gl_Position = projectionMatrix * mvPosition;",
"}"
].join("\n"),

fragmentShader: 
[

  ((similar to above))

].join("\n")

};
于 2013-07-25T19:46:46.827 回答