Page 1 of 1

EntityCustomParameter() with camera support

Posted: Wed May 28, 2014 10:46 pm
by Samuel
EntityCustomParameter() is a great command, but it would be really handy if it could support cameras as well.

I ask because compositors are assigned to cameras not entities. So, we can't send any custom parameters to their material script.

This will be especially useful for compositors that effect screen settings.


EDIT:
Quick question does CompositorEffectParameter(#Effect, TechniqueID, PassID, EffectName$, DataType, *Data) work on the compositor's material script or does it only work with the compositor script?
If it will work on the compositor's material script then my request is invalid.


Also I found this on the Ogre forums which explains why I can't just reload the compositor's material script with new data.
Sinbad wrote: The reason is that the compositor clones the original materials provided, because each instance has to hook up the input textures differently.

You need to use a CompositorInstance::Listener. Demo_Compositor uses one precisely for the same reason, please refer to that. You can listen in on the original material getting created (notifyMaterialSetup), and also on the material getting rendered (notifyMaterialRender).
This code looks like it might be in the ballpark, but I'm going to do a little more research on CompositorInstance::Listener to double check.
Attach a CompositorInstance:Listener via CompositorInstance::addListener to your compostor instance in order to modify
material/shader parameters.

Code: Select all

class SomeListener : public Ogre::CompositorInstance::Listener
{
   public:
      void notifyMaterialSetup( uint32 pass_id, Ogre::MaterialPtr & mat )
      {
            // modify material here (wont alter the base material!) in the setup stage
      }

   void notifyMaterialSetup( uint32 pass_id, Ogre::MaterialPtr & mat )
   {
            // modify material here (wont alter the base material!), called for every drawn geometry instance (i.e. compositor render_quad)
   }
  
};


// Usage
Ogre::CompositorInstance * inst = Ogre::CompositorManager::getSingleton().addCompositor( ... );
inst->addListener( new SomeListener );

Re: EntityCustomParameter() with camera support

Posted: Thu May 29, 2014 9:35 am
by Comtois
Yes it seems that this function acts on the material script.
I can not help you in this area but g-rom had an example, here an extract

Code: Select all

Compositor = CreateCompositorEffect(#PB_Any,CameraID(camera),"GAUSSIAN_BLUR")
MyBlurSize.f = 0.019
CompositorEffectParameter(Compositor, 0, 0, "blurSize", #PB_Param_Float, @MyBlurSize)
With #PB_Param_Float = 0 (should be changed to use #PB_Float !!)


And material script

Code: Select all

material Blur/Horizontal
{
technique
	{

		pass
		{

			vertex_program_ref StdQuad
			{
			 param_named vTexCoord vec2 0.0 0.0
			}

			fragment_program_ref HorizontalBlur
			{
				param_named RTScene int 0
				param_named blurSize float 0.0019
			}

			texture_unit
			{
				texture RTScene
        tex_coord_set 0
				tex_address_mode clamp
				filtering linear linear linear
			}


		}
	}
}

Re: EntityCustomParameter() with camera support

Posted: Thu May 29, 2014 9:50 am
by Samuel
Thanks Comtois, I'll go give this a try right now.

Re: EntityCustomParameter() with camera support

Posted: Thu May 29, 2014 10:02 am
by Comtois
for color you can try this, dont know if it will work

Code: Select all

#PB_Param_Color = 7

Structure ColorValue
  r.f
  g.f
  b.f
  a.f
EndStructure

Define MyColor.ColorValue 
CompositorEffectParameter(Compositor, 0, 0, "MyColor", #PB_Param_Color, @MyColor)

Re: EntityCustomParameter() with camera support

Posted: Thu May 29, 2014 10:20 am
by Samuel
I can't seem to get the structured version to work. Instead I altered the shader a little and now we can send each color value individually and so far everything seems to work correctly.

Thank you again, Comtois. Your help was very much appreciated.

I suppose this topic should be moved as it's no longer a request.