Hi, this time my shader problems aren´t related to texture, but it is the oposite, vertex colors. First take a look at the following code:
float4 vtx_position : POSITION,
float3 vtx_normal : NORMAL,
float4 vtx_color : COLOR,
out float4 l_position : POSITION,
out float4 l_light : TEXCOORD0,
out float4 l_color : COLOR,
uniform float4 mspos_plight,
uniform float4x4 mat_modelproj
l_position = mul(mat_modelproj, vtx_position);
float3 N = normalize(vtx_normal);
float3 lightVector = normalize(mspos_plight - vtx_position);
l_light = max(dot(N,lightVector), 0);
l_color = vtx_color;
float4 l_light : TEXCOORD0,
float4 l_color : COLOR,
out float4 o_color : COLOR0
if (l_light.x<0.5) l_light=0.8;
result = l_color;
result *= l_light;
o_color = result;
i got this code from advanced cartoon shader sample. Why vertex colored models(no materials) rendered with this shader have a white color? All vertices in the egg file I made with blender have rgba(0,0,0,1), which is the color which should show, black. The lighting is working, it´s just the color which is an issue.
Thanks for any help
This may be due to an optimization that Panda automatically performs: if all of the vertices of a particular Geom have the exact same color, then instead of storing the color as a per-vertex attribute, it stores it as a scene graph attribute instead, thus saving the bandwidth of storing all those redundant color attributes on the vertices.
You can test this: what happens if you hand-edit the egg file so that one of your vertices has a color other than black?
If this is indeed what is happening, you can avoid it by coding your shader to check the scene graph color instead. Unfortunately, there’s not a config variable to tell Panda not to perform this optimization, though there probably ought to be.
Edit: I’ve committed a fix that adds egg-flat-colors. If you pick up the next buildbot release, you can (a) clear your Panda cache directory, and (b) put “egg-flat-colors 0” in your Config.prc file. This will force all subsequently-loaded egg files to always use vertex color instead of allowing the scene graph optimization.
Hi drwr! I would have not thought of that, I passed days trying to see where I have made a mistake. I made the test with the egg file and this is exactly what is happening, changing a single vertex color made the vertex shader work properly.
Have you any thread/page showing how to pass this scene graph color to the shader? I think optimization is good, I just need an override I think for this specific shader, which I use only for some models.
Also you have any info about where do I find this buildbot releases, how to install it(if the package isn´t .deb) and how do I clear this panda cache?
I´m more artist than programmer, any more detail would be great, thanks again.
Actually, I’m not sure if the shader can automatically query the scene-graph state. But you can pass in the desired color with the setShaderInput() method, the same way you pass in any fixed properties. Or, if it is only one object that is going to have this property, you could just hardcode the color value in the shader itself.
You can download the buildbot release from the “Snapshot Builds” link under the “Download” tab. It is provided in the appropriate form for each platform.
How do I get in panda3d python side the flat color of a model?
I tried to getColor(), but the result was white, which isn´t the real color of the vertex(says something about no color set present). I have been reading also which I might be able to use makeVertex() to have vertex colors(no flat colors) in colorAtrrib, but I did not understood how to use this
This is just what I need for this particular problem, after getting the color I can send it with setshaderinput() as you said.
thanks for your help
EDIT: I found a workaround, In shader I used as color atrrib_color. Not vertex color nor shaderinput parameter.