1.9.4 and Vertex Colours

Return to Compiling or Editing the Panda Source

1.9.4 and Vertex Colours

Postby Thaumaturge » Wed Aug 23, 2017 1:26 pm

Given that I'm making my own build from the source, how easy would it be to back-port Panda3D 1.10's handling of vertex colours--specifically, that a model lacking vertex colours is treated as having white vertex colours in shaders that attempt to access them--into Panda3D 1.9.4? How involved would it be, and where should I look for the relevant code?
MWAHAHAHAHA!!!

I have a website now! It holds information and a dev-blog for my nascent video-game, A Door to the Mists.
User avatar
Thaumaturge
 
Posts: 1634
Joined: Sat Jun 07, 2008 6:34 pm
Location: Cape Town, South Africa

Re: 1.9.4 and Vertex Colours

Postby rdb » Tue Aug 29, 2017 4:36 am

Not particularly difficult. The file in question is panda/src/glstuff/glShaderContext_src.cxx although it has changed quite a bit, so the surrounding code will look different.

Here are the relevant commits:

https://github.com/panda3d/panda3d/comm ... ec00789a5a
https://github.com/panda3d/panda3d/comm ... 3fbf789e42
rdb
 
Posts: 11214
Joined: Mon Dec 04, 2006 5:58 am
Location: Netherlands

Re: 1.9.4 and Vertex Colours

Postby Thaumaturge » Tue Aug 29, 2017 11:29 am

Ah, excellent, and thank you! That does indeed look pretty straightforward. ^_^
MWAHAHAHAHA!!!

I have a website now! It holds information and a dev-blog for my nascent video-game, A Door to the Mists.
User avatar
Thaumaturge
 
Posts: 1634
Joined: Sat Jun 07, 2008 6:34 pm
Location: Cape Town, South Africa

Re: 1.9.4 and Vertex Colours

Postby Thaumaturge » Sat Sep 09, 2017 10:55 am

Hmm... I seem to have hit a snag:

I have a particular model that includes vertex colours. It worked as expected under the standard version of 1.9.4. Under my custom build, I seem to get white instead of the expected colours. Other objects seem to work as expected--although it's possible that I've missed one or more that don't.

Examination of the code and a quick experiment seem to indicate that the problem lies with the the first part of the "if"-statement below, from glShaderContext_src.cxx:
Code: Select all
int num_elements, element_stride, divisor;
      bool normalized;
      if ((p != _color_attrib_index || color_attrib->get_color_type() == ColorAttrib::T_vertex) &&
          _glgsg->_data_reader->get_array_info(name, array_reader,
                                               num_values, numeric_type,
                                               normalized, start, stride, divisor,
num_elements, element_stride)) {


That is, if I remove "(p != _color_attrib_index || color_attrib->get_color_type() == ColorAttrib::T_vertex) &&" from the above, I seem to get vertex colours as expected.

Given this, where do you think that the problem lies? Am I perhaps missing some other piece of code that would set something in that "if"-statement correctly?

I note that the problematic section doesn't seem to have been present in baseline 1.9.4; would it be safe to simply omit it in my build, do you think?
MWAHAHAHAHA!!!

I have a website now! It holds information and a dev-blog for my nascent video-game, A Door to the Mists.
User avatar
Thaumaturge
 
Posts: 1634
Joined: Sat Jun 07, 2008 6:34 pm
Location: Cape Town, South Africa

Re: 1.9.4 and Vertex Colours

Postby rdb » Thu Sep 14, 2017 3:38 pm

Is this issue not there if you properly set ColorAttrib.make_vertex() ?

The point of the new vertex color handling is that the value of the color vertex attribute is now dependent on the ColorAttrib state.
rdb
 
Posts: 11214
Joined: Mon Dec 04, 2006 5:58 am
Location: Netherlands

Re: 1.9.4 and Vertex Colours

Postby Thaumaturge » Fri Sep 15, 2017 9:04 am

This particular model doesn't use programmatically-assigned vertex colours, I believe--it's just a model, loaded from an egg file, that happens to have such colours. Unless I should be calling "make_vertex()" for such models, too?

Could some other piece of code--such as activating transparency on the object, hiding it from a camera, or assigning a shader to it--be adding or changing a ColorAttrib in such a way that the code is tripping over those conditions?
MWAHAHAHAHA!!!

I have a website now! It holds information and a dev-blog for my nascent video-game, A Door to the Mists.
User avatar
Thaumaturge
 
Posts: 1634
Joined: Sat Jun 07, 2008 6:34 pm
Location: Cape Town, South Africa

Re: 1.9.4 and Vertex Colours

Postby rdb » Thu Sep 21, 2017 3:28 am

The egg loader automatically uses make_vertex() on any model that has vertex colors applied, unless all vertices have the same colour, in which case it uses a fixed color for the whole model using nodepath.set_color(). This shouldn't make a difference in 1.10.

I don't think any of the things you mentioned should modify the ColorAttrib. But you should be able to see this by inspecting the scene graph with ls().
rdb
 
Posts: 11214
Joined: Mon Dec 04, 2006 5:58 am
Location: Netherlands

Re: 1.9.4 and Vertex Colours

Postby Thaumaturge » Fri Sep 22, 2017 9:53 am

Here's the output of "ls()", called from within the game:

Code: Select all
ModelRoot brassBowl.egg S:(ColorAttrib)
  GeomNode Circle.001 (1 geoms: S:(ColorAttrib CullBinAttrib MaterialAttrib TextureAttrib)) [noShadows shader transparency] S:(ColorBlendAttrib ShaderAttrib TransparencyAttrib) (per-camera hidden)
  GeomNode Circle (1 geoms: S:(MaterialAttrib TextureAttrib))


The first GeomNode, "Circle.001" is the one that's showing the problem, I believe. I note that it reports a "ColorAttrib" (as does the parent node), although why this is so I'm not sure.

Oddly, while calling "getAttrib(ColorAttrib)" on the model-node returns a "ColorAttrib" (with the colour (1, 1, 1, 1)), doing so on either of its children returns None. o_0
MWAHAHAHAHA!!!

I have a website now! It holds information and a dev-blog for my nascent video-game, A Door to the Mists.
User avatar
Thaumaturge
 
Posts: 1634
Joined: Sat Jun 07, 2008 6:34 pm
Location: Cape Town, South Africa

Re: 1.9.4 and Vertex Colours

Postby Thaumaturge » Tue Oct 10, 2017 1:35 pm

Thus far, omitting the above-mentioned condition seems to produce the expected results. Is there any reason that anyone sees to put it back? Might it impact performance, for example?
MWAHAHAHAHA!!!

I have a website now! It holds information and a dev-blog for my nascent video-game, A Door to the Mists.
User avatar
Thaumaturge
 
Posts: 1634
Joined: Sat Jun 07, 2008 6:34 pm
Location: Cape Town, South Africa

Re: 1.9.4 and Vertex Colours

Postby rdb » Tue Oct 10, 2017 3:59 pm

Did you at all call setColor on the node, or something like that? If you do, a ColorAttrib with a flat color gets assigned (as you are noticing), which may be overriding the ColorAttrib.make_vertex() and causing the vertex colors to get overridden by the constant color.

getAttrib() by default returns the attribute set on that node; use getNetState().getAttrib() to get the effective ColorAttrib on that node including the effects of any ColorAttrib assigned to higher nodes.
rdb
 
Posts: 11214
Joined: Mon Dec 04, 2006 5:58 am
Location: Netherlands

Re: 1.9.4 and Vertex Colours

Postby Thaumaturge » Tue Oct 10, 2017 7:44 pm

Ah, you're right! While my initial searching of the code didn't turn up anything, a more careful hunt revealed that I had a forgotten method that was assigning a colour to the actor! A little more testing suggests that I'm not actually using this functionality in the game as it stands, so I've removed it.

I feel silly for having missed that--thank you for prompting me to check again! ^^;

I've rebuilt the SDK with the condition back in place, and it does indeed seem that removing the above function solves the problem. Thank you very much for your help! ^_^
MWAHAHAHAHA!!!

I have a website now! It holds information and a dev-blog for my nascent video-game, A Door to the Mists.
User avatar
Thaumaturge
 
Posts: 1634
Joined: Sat Jun 07, 2008 6:34 pm
Location: Cape Town, South Africa


Return to Compiling or Editing the Panda Source

Who is online

Users browsing this forum: No registered users and 2 guests