3

I'm trying to create a shader with a texture map on it from scratch. Looking at the other materials (shaders) and their sources, it seems like they all have a "uv" attribute passed to them. I'm having a hard time figuring out where that uv attribute is generated and assigned. Is it set on the geometry, the material, or both?

I'm using default THREE.Geometry objects, like THREE.SphereGeometry. I assumed those would already have attributes set on them, but when I inspect their meshes as scene children I don't see any attribute key/value set on them.

This is an example of the shader generated by a ShaderMaterial or other:

Vertex shader

attribute vec2 uv;
varying vec2 vUv;

void main()  {
    vUv = uv;

Fragment shader

varying vec2 vUv;
uniform sampler2D map;

void main()  {
    vec4 texel = texture2D( map, vUv );

However, when I attempt the above, my shader (with RawShaderMaterial) just goes blank and I get a "could not compile."

Is there some magic in THREE that sets up a relationship between shader, object and attributes?

I found a THREE.js generate UV coordinate question, but again, I'm guessing a THREE default object already has UV attributes set correctly?

I specifically want to use a RawShaderMaterial in this case. Can someone point me to the place in the THREE source where UVs are generated for objects / passed to shaders, or tell me how to properly set up UVs to use in the fragment / vertex at runtime?

Community
  • 1
  • 1
Andy Ray
  • 30,372
  • 14
  • 101
  • 138
  • It only says "could not compile"? Could you upload the test somewhere? – mrdoob Dec 02 '14 at 02:09
  • 1
    I made this http://jsfiddle.net/4wkFu/125/ which actually works, so I think I'm just doing something wrong in my setup. – Andy Ray Dec 02 '14 at 08:31

0 Answers0