I try to write an own compositor effect for a keyhole effect. But now I'm desperate. I always get the exception:
Code: Select all
Named constants have not been initialised, perhaps a compile error
Here, what I have done so far:
In Postprocessing/HLSL folder I created the file Keyhole_ps.hlsl:
Code: Select all
Texture2D Image : register(t0);
SamplerState samplerState : register(s0);
float4 main
(
float2 uv0 : TEXCOORD0,
uniform float frameShape : register(c0),
uniform float sin_time_0_X : register(c1)
) : SV_Target
{
// Define a frame shape
float2 pos = abs((uv0 - 0.5) * 2.0);
float f = (1 - pos.x * pos.x) * (1 - pos.y * pos.y);
float frame = saturate(pow(abs(f)), frameShape);
// Repeat a 1 - x^2 (0 < x < 1) curve and roll it with sinus.
float dst = frac(pos.y + sin_time_0_X);
dst *= (1 - dst);
// Make sure distortion is highest in the center of the image
dst /= 1 + abs(pos.y);
uv0.x += dst;
float4 image = Image.Sample(samplerState, uv0);
return frame + image;
}
Code: Select all
compositor_node "Keyhole"
{
in 0 rt_input
in 1 rt_output
custom_id Ogre/Postprocess
target rt_output
{
pass render_quad
{
material Postprocess/Keyhole
input 0 rt_input
}
}
out 0 rt_output
out 1 rt_input
}
Code: Select all
fragment_program Keyhole_ps_HLSL hlsl
{
source Keyhole_ps.hlsl
target ps_5_0 ps_4_0 ps_4_0_level_9_1 ps_4_0_level_9_3
entry_point main
}
fragment_program Keyhole_ps unified
{
delegate Keyhole_ps_HLSL
}
material Postprocess/Keyhole
{
technique
{
pass
{
depth_check off
depth_write off
cull_hardware none
vertex_program_ref Ogre/Compositor/Quad_vs
{
}
fragment_program_ref Keyhole_ps
{
param_named frameShape float 0.26
param_named_auto sin_time_0_X sintime_0_x 120
}
texture_unit
{
tex_coord_set 0
tex_address_mode clamp
filtering linear linear linear
}
}
}
}
Code: Select all
this->material = Ogre::MaterialManager::getSingletonPtr()->getByName("Postprocess/Keyhole");
Ogre::Material* material0 = this->material.getPointer();
this->pass = material0->getTechnique(0)->getPass(0);
this->pass->getFragmentProgramParameters()->setNamedConstant("frameShape", 0.0f); // Exception here
What could that be? I have really no idea...
Kudos reward to the one, that can help me out here
Best Regards
Lax