pex-gl / pex-renderer

Physically based renderer (PBR) and scene graph for PEX.
https://pex-gl.github.io/pex-renderer/examples/index.html
MIT License
237 stars 16 forks source link

Replace colors with tint and vertexColors with colors #42

Closed vorg closed 1 year ago

vorg commented 6 years ago

It would make it more clear what's happening as instanced color is multiplied by base color. I call it tint in glsl anyway https://github.com/pex-gl/pex-renderer/blob/master/glsl/PBR.frag#L1411

vorg commented 6 years ago

currently we have

renderer.geometry({
  positions: [],
  normals: [],
  vertexColors: []
  offsets:  { data: [], divisor: 1 },
  colors: { data: [], divisor: 1 }
})
renderer.geometry({
  positions: [],
  normals: [],
  colors: []
  offsets:  { data: [], divisor: 1 },
  tints: { data: [], divisor: 1 }
})
vorg commented 6 years ago

Another reason to use colors not vertexColors is glTF vertex color attribute is named COLOR_0 https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#meshes

vorg commented 5 years ago

Added this to 3.0.0 milestone as it's breaking and we change it now or never..

Still undecided on the tints name though. Probably better than instanceColors though.

dmnsgn commented 5 years ago

Yes, that's probably going to be formalised in glTF 3.0. Meanwhile I am also undecided. instanceColors is more explicit but that means than anything that is instanced should follow the convention.

vorg commented 5 years ago

@dmnsgn any updates on that? e.g. progress of gltf discussion or maybe we should do research how babylon or three.js are naming things

vorg commented 5 years ago

ThreeJS is actually vertexColors and instanced colors and offsets https://github.com/mrdoob/three.js/blob/master/examples/webgl_buffergeometry_instancing.html#L153

BabylonJS seem not to have instanced color support? https://doc.babylonjs.com/how_to/how_to_use_instances

vorg commented 5 years ago

I would propose that unless we are willing to use instance* prefix we should close those issue and wait for GLTF to clarify.

geometry.set({
   positions: [],
   normals: [],
   vertexColors: [],
   offsets: [],
   scales: [],
   rotations: [],
   colors: []
})

vs 

geometry.set({
   positions: [],
   normals: [],
   colors: [],
   instanceOffsets: [],
   instanceScales: [],
   instanceRotations: [],
   instanceColors: []
})
dmnsgn commented 5 years ago

I agree. What's your gut feeling about instance* prefix? I am leaning toward this option as it makes it really explicit.

vorg commented 5 years ago

One thing about instance* prefix is that it would make it clear what's supported and what's instanced. We could then drop the requirement for { divisor: 1 } as it would be redundant.

The question is though: do we want to support custom (instanced or not) attributes as we have custom shaders? There are generally 3 options:

Writing this here just for reference because I think we should strive to do minimum work and not implement any of the above yet.

vorg commented 5 years ago

@dmnsgn @simonharrisco if we go ahead with this:

geometry.set({
   positions: [],
   normals: [],
   colors: [],
   instanceOffsets: [],
   instanceScales: [],
   instanceRotations: [],
   instanceColors: []
})

Then is it still this:

geometry.set({
 instanceOffsets: { data: [], divisor: 1 }
})

or is this now also (or only) valid:

geometry.set({
 instanceOffsets: [] // divisor is assumed as this is instanced attribute and defaults to 1
})

https://github.com/pex-gl/pex-renderer/blob/master/geometry.js#L106

this is similar to allowing both:

geometry.set({
 positions: { buffer: {}, offset: N, string: M }
})
geometry.set({
 positions: []
})
vorg commented 5 years ago

Good thing is all old examples will throw "unknown attribute" if we try to set e.g. offset https://github.com/pex-gl/pex-renderer/blob/master/geometry.js#L111

That will be easy to spot and fix instead of silent errors.

simonharrisco commented 5 years ago
geometry.set({
 instanceOffsets: [] // divisor is assumed as this is instanced attribute and defaults to 1
})

Seems more user friendly and feels nice with the other properties

vorg commented 3 years ago

To complicate things glTF uses TRANSLATION, ROTATION, and SCALE in EXT_mesh_gpu_instancing and doesn't support color or material properties as of today.

vorg commented 1 year ago

Note: one benefit of aInstanceColor and instanceColors would be automatic instanced attribute detection and auto divisor: 1 insert.

I would not change anything for now to avoid breaking all existing code.