monopolar
18-05-2007 20:56:47
I'm presently using the newly bound Compositor support in Python-Ogre (1.0 RC1) to post process rendering for a specialized display. So far I have been successful with regard to writing my own Cg programs and invoking them within my code. I've even been able to add static textures via the material script.
My question is, how do I send a simple integer argument to a Cg fragment shader program? My present approach has been to use the GpuProgramParameters.setNamedConstant( ) method in the same fashion that it is applied to materials. While I am aware that the functions that accept lists have not been bound yet, I'm just passing an integer value (a frame count) at this point.
I've setup the cg fragment shader program (the value passed is frameNum and is presently just generating some vertical black lines for debug):
The corresponding .material file:
And the corresponding code snippet in Examples.compositor
Works like a charm with the constant value of frameNum
Then I try to increment the value of frameNum within my frame listener (self.cmsOn is a flag which makes sure that the compositor has been invoked and is on):
It's presently bombing on the final line with a runtime error of "unidentifiable C++ exception"
My question is, how do I send a simple integer argument to a Cg fragment shader program? My present approach has been to use the GpuProgramParameters.setNamedConstant( ) method in the same fashion that it is applied to materials. While I am aware that the functions that accept lists have not been bound yet, I'm just passing an integer value (a frame count) at this point.
I've setup the cg fragment shader program (the value passed is frameNum and is presently just generating some vertical black lines for debug):
sampler RT : register(s0);
sampler Rand: register(s1);
sampler Lines: register(s2);
float4 GrayScale_ps(float2 pos: TEXCOORD1,
float2 iTexCoord : TEXCOORD0,
uniform int frameNum: register(c2)) : COLOR
{
float3 truncval=tex2D(RT, iTexCoord).rgb;
float3 thresh=tex2D(Rand, iTexCoord).rgb;
int posx=int((pos.x+1)*512);
int posy=int((pos.y+1)*512);
truncval=((frameNum+posx)%32!=0)?truncval:float3(0,0,0);
truncval=truncval+thresh;
truncval=truncval*(4,8,8);
truncval=floor(truncval);
truncval=truncval/float3(4,8,8);
float3 grayscale=dot(truncval,float3(16,8,1))/16;
return float4(truncval, 1.0);
}
The corresponding .material file:
fragment_program Ogre/Compositor/ArrDither cg
{
source ArrDither.cg
entry_point GrayScale_ps
profiles ps_2_0 fp30 arbfp1
}
material Ogre/Compositor/ArrDither
{
technique
{
pass
{
depth_check off
vertex_program_ref Ogre/Compositor/StdQuad_Tex2a_vp
{
}
fragment_program_ref Ogre/Compositor/ArrDither
{
param_named_auto frameNum frameNum 0
}
texture_unit 0
{
tex_coord_set 0
tex_address_mode clamp
filtering linear linear linear
}
texture_unit 1
{
texture threshtex2.tga 2d
tex_coord_set 1
tex_address_mode wrap
filtering linear linear linear
}
texture_unit 2
{
texture linetex.tga 2d
tex_coord_set 1
tex_address_mode wrap
filtering linear linear linear
}
}
}
}
And the corresponding code snippet in Examples.compositor
compositor ArrDither
{
technique
{
texture rt0 target_width target_height PF_R8G8B8
// render scene to a texture
target rt0 { input previous }
target_output
{
// Start with clear output
input none
pass render_quad
{
material Ogre/Compositor/ArrDither
input 0 rt0
}
}
}
}
Works like a charm with the constant value of frameNum
Then I try to increment the value of frameNum within my frame listener (self.cmsOn is a flag which makes sure that the compositor has been invoked and is on):
if self.cmsOn:
mat=(ogre.MaterialManager.getSingleton().getByName('Ogre/Compositor/ArrDither'))
_pass=mat.getTechnique(0).getPass(0)
params =_pass.getFragmentProgramParameters()
params.setNamedConstant("frameNum", self.frameCount)
It's presently bombing on the final line with a runtime error of "unidentifiable C++ exception"