deathcap / voxel-texture-shader

custom shader for texturing voxels in voxeljs (for three.js-based voxel-engine, no longer needed with voxel-engine-stackgl)
MIT License
8 stars 1 forks source link

Figure out how to set attributes/uniforms per-geometry (vs per-material) in three.js; remove use of faceVertexUvs? #3

Open deathcap opened 10 years ago

deathcap commented 10 years ago

voxel-texture-shader (ab)uses three.js faceVertexUvs to pass in the uv attribute, set to the vUv varying in the vertex shader so it can be passed to fragment shader for tile UV calculation.

This circuitous path is taken only because that's the only way I could find out how pass per-geometry data (as opposed to per-material) in three.js. An attribute is not actually needed, because the "texture UV" (really the top/left starting UV. note: not tile UV, which is calculated from vPosition=gl_Position and vNormal in the fragment shader) is the same for the entirety of the mesh.

A custom uniform (or attribute) would be sufficient if three.js would allow other data to be set in the geometry, and passed to the material, just like geometry.faceVertexUvs. Maybe it does, but all of the http://threejs.org/examples/ I've looked at change uniforms/attributes in the material and it applies to all meshes using said geometry and any material.