Shaders + Texture Wrapping

So ive been messing around with the glowShader from on of the samples and i made it togglable. Before i toggle the glowshader on all my texture are wrapped in the repeat way, but when i toggle the shader on it clears the material and sets the texture wrapping to the default where it just stretches it over the geometry. So when i toggle it on i also try to reapply the texture and reset the wrapping to tiled, but when i do nothing changes. is it because the shader is not allowing it? (I have only basic understanding of how shaders work and verry little knowledge of what all shaders control) here is my Code

def enableFilters(self, player, level):
        #self.filters.setBloom(mintrigger=.35)
        self.filters.setBloom(blend=(1, 0, .2, 1), desat=-1, intensity=3, size="small")
        self.filters.setCartoonInk(separation=-.5)
        self.filters.setAmbientOcclusion(numsamples = 16, radius = 0.05, amount = 10, strength = 0.01, falloff = 0.000002)
        player.setShader(self.glowShader)
        level.setShader(self.glowShader)

        self.tex = loader.loadTexture("./textures/platform.png")
        self.tex.setWrapU(Texture.WMRepeat)
        self.tex.setWrapV(Texture.WMRepeat)

        for i in range(len(level.getChildren())):
        	print(level.getChild(i))
        	child = level.getChild(i)
        	print(child.getChild(0))
        	if level.getChild(i) == "render/renderDummy/Box":
        		self.tex = loader.loadTexture("./textures/platform.png")
        		self.tex.setWrapU(Texture.WMRepeat)
        		self.tex.setWrapV(Texture.WMRepeat)

        		print("wtf")

        		child.getChild(0).clearTexture()

        		child.getChild(0).setTexture(self.tex)
        		child.getChild(0).setTexScale(TextureStage.getDefault(), 10, 10)

        	#level.getChild(i).getChild(0).getTexture().setWrapU(Texture.WMRepeat)
        	#level.getChild(i).getChild(0).getTexture().setWrapU(Texture.WMRepeat)
        	child.setTexture(self.tex)
        	self.tex.setWrapU(Texture.WMRepeat)
        	self.tex.setWrapV(Texture.WMRepeat)
        	 #render.setShader(self.glowShader)

and here is the shader code

//Cg
//

void vshader(float4 vtx_position : POSITION, 
             float2 vtx_texcoord0 : TEXCOORD0,
             uniform float4x4 mat_modelproj,
	     out float4 l_position : POSITION,
	     out float2 l_texcoord0 : TEXCOORD0)
{
	l_position=mul(mat_modelproj, vtx_position);
	l_texcoord0=vtx_texcoord0;
}

void fshader(float2 l_texcoord0 : TEXCOORD0,
       	     uniform sampler2D tex_0 : TEXUNIT0,
	     out float4 o_color : COLOR)
{
	float4 texColor=tex2D(tex_0, l_texcoord0);
	o_color=texColor*2*(texColor.w - 0.5);
}

The shader is now applying the texture to the geometry.

tex_0 is the first texture of your object.

float4 texColor=tex2D(tex_0, l_texcoord0);
//in this line the shader takes the texture and its coords and gets the color which it sets ea fragment to.

changing it to
float4 texColor=tex2D(tex_0, l_texcoord0*float2(2,2);
will make the coords larger and repeat the texture more.

awesome that works :smiley: but im stuck again lol. So i apply textures and tile them according to the size of the node like this

model.setTexScale(TextureStage.getDefault(), w/2, l/2, h/2)

how can i go about doing the same thing except with the shader i posted above?

Ok.
adding a variable to the fragment shader

uniform float2 scale;

pass this value to the shader by using

nodepath.setShaderInput("scale",x,y)

multipy scale by the texcoords and your done.And now you can set tex scales for all objects lol.
[/code]

so i think im close

for i in range(len(level.getChildren())):
        	child = level.getChild(i)
        	print(child)
        	child.setShader(self.glowShader)
        	bounds = child.getTightBounds()
        	print("bounds" + str(bounds))
        	size = bounds[1] - bounds[0]
        	print("size" + str(size))
        	l = size[0]
        	w = size [1]
        	h = size[2]
        	child.setShaderInput("scale",l,w)
//Cg
//

void vshader(float4 vtx_position : POSITION, 
             float2 vtx_texcoord0 : TEXCOORD0,
             uniform float4x4 mat_modelproj,
	     out float4 l_position : POSITION,
	     out float2 l_texcoord0 : TEXCOORD0)
{
	l_position=mul(mat_modelproj, vtx_position);
	l_texcoord0=vtx_texcoord0;
}

void fshader(float2 l_texcoord0 : TEXCOORD0,
       	     uniform sampler2D tex_0 : TEXUNIT0,
	     out float4 o_color : COLOR)
{
	uniform float2 scale;
	float4 texColor=tex2D(tex_0, l_texcoord0*scale);
	o_color=texColor*2*(texColor.w - 0.5);
}

i get no errors, but the shader doesnt seem to be working, im only assuming its not working because im not getting the glow effect and my materials werent removed.

so i am gettting errors with the shader

//Cg
//

void vshader(float4 vtx_position : POSITION, 
             float2 vtx_texcoord0 : TEXCOORD0,
             uniform float4x4 mat_modelproj,
	     out float4 l_position : POSITION,
	     out float2 l_texcoord0 : TEXCOORD0)
{
	l_position=mul(mat_modelproj, vtx_position);
	l_texcoord0=vtx_texcoord0;
}

void fshader(float2 l_texcoord0 : TEXCOORD0,
       	     uniform sampler2D tex_0 : TEXUNIT0,
       	     uniform float2 k_scale,
	     out float4 o_color : COLOR,)
{
	float4 texColor=tex2D(tex_0, l_texcoord0*k_scale);
	o_color=texColor*2*(texColor.w - 0.5);
}

yields this error: gobj(error): /c/Panda3D-1.9.0/direct/filter/filter-ssao.sha: <invalid atom 65535>(40) : error C6013: Only arrays of texcoords may be indexed in this profile, and only with a loop index variable
:gobj(error): Shader encountered an error.
:gobj(error): /c/Users/flaps/Documents/Jutsu’s/VoxelDash/shaders/glowShader.sha: <invalid atom 65535>(17) : error C0000: syntax error, unexpected ‘)’, expecting “::” at token “)”: ive also been studying these 2 links 1) panda3d.org/manual/index.ph … ial_Part_6 and 2)https://www.panda3d.org/manual/index.php/List_of_Possible_Shader_Inputs but i feel just as lost as before. Am i sending data to the shader wrong or is the shader just not handling the data correctly?

EDIT: i finally found that misplaced comma in my vshader lol, so now i have this code:

//Cg
//

void vshader(float4 vtx_position : POSITION, 
             float2 vtx_texcoord0 : TEXCOORD0,
             uniform float4x4 mat_modelproj,
	     out float4 l_position : POSITION,
	     out float2 l_texcoord0 : TEXCOORD0)
{
	l_position=mul(mat_modelproj, vtx_position);
	l_texcoord0=vtx_texcoord0;
}

void fshader(float2 l_texcoord0 : TEXCOORD0,
       	     uniform sampler2D tex_0 : TEXUNIT0,
       	     uniform float2 k_scale,
	     out float4 o_color : COLOR)
{
	float2 scale = k_scale;
	float4 texColor=tex2D(tex_0, l_texcoord0*scale);
	o_color=texColor*2*(texColor.w - 0.5);
}

i also removed the float2 scale = k_scale; and changed it to texcoord0*k_scale to no avail. i get this error now

Assertion failed: Shader input scale is not present.

making me believe i’ve either named the input variable in the shader wrong or im passing data to the shader wrong.

So its saying you have not supplied the shader input for an object which the shader is applied to.

if you havent perhaps:

render.setShaderInput("scale",1,1)

because i think you might not be setting the input on other objects which use the shader.

yea that seems to work, so its an issue with my loop

edit: player.setShader(self.glowShader) i never gave this node the scale input, after i did all works wonderfully. Thanks for your patience with me :smiley: