EntityCustomParameter() with camera support

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Samuel
Enthusiast
Enthusiast
Posts: 755
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

EntityCustomParameter() with camera support

Post 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 );
User avatar
Comtois
Addict
Addict
Posts: 1431
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Re: EntityCustomParameter() with camera support

Post 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
			}


		}
	}
}
Please correct my english
http://purebasic.developpez.com/
User avatar
Samuel
Enthusiast
Enthusiast
Posts: 755
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

Re: EntityCustomParameter() with camera support

Post by Samuel »

Thanks Comtois, I'll go give this a try right now.
User avatar
Comtois
Addict
Addict
Posts: 1431
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Re: EntityCustomParameter() with camera support

Post 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)
Please correct my english
http://purebasic.developpez.com/
User avatar
Samuel
Enthusiast
Enthusiast
Posts: 755
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

Re: EntityCustomParameter() with camera support

Post 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.
Post Reply