In my EGG file I have stored some data in named UV sets that I need to access in my shader. The problem is Panda is “optimizing” out the extra UVs because they are not used by any texture/texture stage.
I can access them if I insert dummy textures in the EGG file that use these UVs, for example:
I’ve written my own exporter, it definitely writes the UVs in the EGG file, and Panda loads them, but they are not available to the shader unless they are actually called for by a texture. It is a good optimization, but in this specific case I need a way to get them to the shader.
Actually, you can access any vertex data column in the shader, by using “floatN vtx_ANYTHING” syntax, but unfortunately the column name for non-default UV set is always “texcoord.XXXX”, so it’s impossible to get it this way because “float2 vtx_texcoord.XXXX” will generate floating point error. Not sure about the new shader system’s interface though.
The workaround is as you have tried, by binding a dummy texture to the 2nd UV, but you don’t have to insert it into the EGG.
You can add that dummy texture on the fly :
from pandac.PandaModules import *
import direct.directbase.DirectStart
tri = loader.loadModel('unused UV')
tri.reparentTo(aspect2d)
ts = TextureStage('')
ts.setTexcoordName('2nd')
ts.setSort(1) # <--- must be explicitly layed after the default
tri.setTexture(ts,Texture())
sha = loader.loadShader('unused UV.sha')
base.accept('enter', tri.setShader, [sha])
base.accept('delete', tri.setShaderOff)
run()
//Cg
void vshader(
in float4 vtx_position : POSITION,
in float2 vtx_texcoord1 : TEXCOORD1,
in uniform float4x4 mat_modelproj,
out float4 l_color0 : COLOR0,
out float4 l_position : POSITION,
out float2 l_texcoord1 : TEXCOORD1
)
{
l_position = mul(mat_modelproj, vtx_position);
l_texcoord1 = vtx_texcoord1;
}
void fshader(
in float2 l_texcoord1: TEXCOORD1,
in uniform sampler2D tex_0,
out float4 o_color : COLOR)
{
o_color = tex2D(tex_0, l_texcoord1);
}