Adding Shaders to objects

I’ve managed to play with the glow shader in the tron example and apply that code to some example code I’m working on for learning. The tron example seems to apply the shader to a camera which in turn seems to apply the glow filter to all objects in the scene.

two quick questions:

  • If you added a second tron character and you wanted one character to be “glowing” and the other not, is this difficult?

  • is it much more efficient to apply a shader to a camera then to apply a shader to each object individually?

This example screenshot that I saw on the panda3d site seems to be doing what I’m talking about:

Thanks,

C

you just define a shader variable like “glow” and set it to Vec3(1,0,0) for glow or Vec3(0,0,0) for now glow and then set it via shader input. Then in the shader file you check weather k_glow.x is 0 or 1.

So to clarify, your saying that each object in the scene would have a variable like “glow”, and the shader that is connected to the camera will only glow objects where their glow variable is set to Vec3(0,0,0). ? ie, you wouldn’t need to connect a shader to each object?

well yes and no. Every shader needs to be a aware of the glow state. If glow is on then do glow if glow is off dont do glow this is is importain for rendering to the 2 buffers you have. How blur works:

buffer1: render normal (glow = off )
buffer2: render glow (glow = on) (other buffers are used to blur but that is not important)
combine buffer1 and buffer2 to form the final rendering

now each buffer will have glow state on and glow state off but indeviduals also can use this glow state to set their relative glow on and glow off via the setShaderInput(“glow”,Vec3(0,0,0)) which is k_glow in the shader.
Its simple one it clicks.

ColShag :

it would be :

render.setShaderInput('glow',Vec4(0,0,0,0))
self.tron.setShaderInput('glow',Vec4(1,0,0,0),1)

and the resulting glow :

o_color=texColor*texColor.w*k_glow.x;

Thanks guys, I’ll be sure to try this out.

Hey Guys,

I’ve tried to get this working and I thought the instructions provided would be enough to figure out this task. Unfortunately I’ve had some trouble after several attempts. So I’m going to detail what changes I made to the standard Tron Example and hopefully someone can point out my error(s):

So First I Changed that last line in glowShader.sha

//Cg
//
//Cg profile arbvp1 arbfp1

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*texColor.w*k_glow.x;
}

Then in Tut-Flow-Filter.py I did the following including adding another tron guy and setting the shader inputs:

        # set the shader input for the render
        render.setShaderInput('glow',Vec4(0,0,0,0))

        # load our model
        self.tron=Actor()
        self.tron.loadModel("models/tron")
        self.tron.loadAnims({"running":"models/tron_anim"})
        self.tron.reparentTo(render)
        self.interval = self.tron.hprInterval(60,Point3(360,0,0))
        self.interval.loop()
        self.isRunning=False
        self.tron.setShaderInput('glow',Vec4(1,0,0,0),1)
        
        # load another model
        self.tron2=Actor()
        self.tron2.loadModel("models/tron")
        self.tron2.reparentTo(render)
        self.tron2.setPos(Point3(self.tron.getX()+10, self.tron.getZ(),  self.tron.getY()))
        self.tron2.setShaderInput('glow',Vec4(1,0,0,0),0)

The program runs, but both models are using the glow effect, as a side effect both models seem to glow all textures on the model now instead of just the blue glow texture. Any ideas?

Thanks,

C

Look at the console, there must be this error :

You didn’t accept the glow in the fragment shader.

void fshader(float2 l_texcoord0 : TEXCOORD0,
             uniform sampler2D tex_0 : TEXUNIT0,
             uniform float4 k_glow,
             out float4 o_color : COLOR)

Ah, I see!

I tried it out and it worked!

Thanks so much ynjh,

Hello everyone,

I’m reviving this old thread because I have a problem with the Glow Effect.

I’m trying to do a glow effect based on this thread, where u can select which “Tron” to glow. So far, it hasn’t worked.

I’m attaching my code, if anyone wants to test it.

Here’s the link: http://sites.google.com/site/dornad/Home/glow.zip?attredirects=0

Thanks!

[/url]