Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

got the uniforms in e.g

uniforms: {

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

},

where does e.g.

attribute float customFrequency; attribute vec3 customColor; go? tia (just added code I am trying to convert)

<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>

apologies for not formulating the question very well - want to create threejs shader from above script in the form of

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")
};

and cannot find an example using vertex attributes. tia

share|improve this question
    
There is no question here. – gaitat Jul 11 '13 at 10:26

2 Answers 2

The question is not very clear, but I believe you are a little bit confused on the basic concepts.

Shaders are not supposed to be converted to javascript. They are written in GLSL language which the browser also understands and passes over to the display driver.

Uniforms are the way you pass variables between Javascript code and GLSL shaders. So you only need to care about uniforms on the Javascript side. The other code in the shader scripts are part of the shader GLSL code, can't be shared with or converted to javascript, and if you want to make changes to them, you need to modify the shader itself.

share|improve this answer
    
ah apologies for not taking the time to formulate the question properly :-( need to convert the above shader script to format: – Mic C Jul 11 '13 at 19:16
    
oops - return key != new line :-( – Mic C Jul 11 '13 at 19:27
up vote 0 down vote accepted

Lee Stemkoski kindly supplied the answer to this:

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")

};
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.