[2.2+] Own Compositor Named constants have not been initialised, perhaps a compile error

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


Lax
Gnoll
Posts: 644
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 59

[2.2+] Own Compositor Named constants have not been initialised, perhaps a compile error

Post by Lax »

Hi,

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
When I try to set a material shader constant.

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;
}
In the CompositorEffects.compositor I declare the compositor:

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
}
And I created the proper material file Keyhole.material:

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
			}
		}
	}
}
Now in c++ I try to set the constant frameShape:

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
Note: All other compositor effects like old tv etc. do work. And I orientated at those compositor effects.

What could that be? I have really no idea...
Kudos reward to the one, that can help me out here :)

Best Regards
Lax

http://www.lukas-kalinowski.com/Homepage/?page_id=1631
Please support Second Earth Technic Base built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd1 ... b97b79be62

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5436
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1343

Re: [2.2+] Own Compositor Named constants have not been initialised, perhaps a compile error

Post by dark_sylinc »

  1. Drop the c0, c1 registers from your uniforms. They're not needed in modern HLSL
  2. Remember to load the material:

    Code: Select all

    Ogre::Material* material0 = this->material.getPointer();
    material0->load(); // <---- THIS
    this->pass = material0->getTechnique(0)->getPass(0);
    this->pass->getFragmentProgramParameters()->setNamedConstant("frameShape", 0.0f);
Cheers
Matias
Lax
Gnoll
Posts: 644
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 59

Re: [2.2+] Own Compositor Named constants have not been initialised, perhaps a compile error

Post by Lax »

I did call the load() function, but exception is still the same. The other compositors also did not required to load the material. It must be something else...

http://www.lukas-kalinowski.com/Homepage/?page_id=1631
Please support Second Earth Technic Base built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd1 ... b97b79be62