Scale UV within Shader

Hi,

Here’s how the problem is currently set-up:
I have a NodePath called m_image.
m_image has a custom shader attached to it.

I utilize m_image.set_tex_scale() to change the uv texture scaling.
However, due to the custom shader, the texture scaling isn’t applied.

I’d like to know what cg variable could be added? to vshader or fshader so that the shader may utilize the 4x4 texture scaling transform matrix.

I’ve researched other possible values, and the best one so far is maybe k_scale?

The goal is to avoid using this:
shaderAttrib->set_shader_input()

Which is an incredibly slow operation.

The texture UV will be scaled and translated in realtime, on a per frame basis, so I think the most optimal way will be to somehow automatically provide the tex_scale_mat to the shader.

Thank you!

Just multiply the uv in the shader by 4 ( usualy named something like vtx_texcoord0 in the vshader or l_texcoord0 in the fshader). If it’s always 4x4 then you can skipp the shader input and hardcode it like that into the shader.

By 4x4 I meant using a float4x4 myUVScale = nodePath.get_tex_transform

Or possibly using

float4 myUVScale = nodePath.get_tex_scale()
float4 myPos = nodePath.get_tex_pos()

with myUVScale and myPos being function arguments within fshader and/or vshader.

Ok I found the solution.

Buried deep within shaderGenerator.cxx, I found where the generated shader gets the tex scale matrix.
It uses “texmat_x” where x is the index of the texture.

This is contained within synthesize_shader on line 846.
panda3d.org/reference/1.8.1/ … php#l00846

This value is verified and used in the shader on line 937.
panda3d.org/reference/1.8.1/ … php#l00937

So to use it in the shader use:
in uniform float4x4 texmat_0,