Page 1 of 1

[resolved] go public: CompositorInstance::getSourceForTex()

Posted: Fri Oct 21, 2011 1:12 am
by cyrfer
This is no longer needed because I had overlooked the public function, CompositorInstance::getTextureInstanceName(...)

Hi,
I had to make the following function public for my "render_custom" compositor pass:
CompositorInstance::getSourceForTex(...)

Can this be public in the next release? Thank you.

[edit] Patch submitted here [/edit]

[edit #2]
Public access to CompositorInstance::getSourceForTex() was useful as I implemented my own version of the 'render_quad' compositor pass because I wanted to extend the behavior of 'render_quad' but also keep some of its features. This function is used by the code that initializes 'render_quad' passes so that the compositor framework can supply the texture slot when the pass is rendered, so my custom render pass needed to be initialized using it as well. The need for public access to this function would have already been obvious if the render pass classes (e.g. render_quad) had their initialization code in their constructors (or their factories), but the initialization code is currently within the CompositorInstance class. My custom compositor pass did not have the luxury of being setup where 'render_quad' is setup (I would have to edit Ogre for this), so my factory did the setup, and needed (public) access to CompositorInstance::getSourceForTex() to have the same features as 'render_quad'.

If people are interested, I have created a custom compositor pass leveraging public access to CompositorInstance::getSourceForTex(), providing access to the scene's camera and light information in the pixel shader. If it is desired, I can submit my custom compositor pass. It is nearly the same as the 'render_quad', but it has the benefit of allowing the scene's camera and light information to be provided to the material pass. 'render_quad' disables camera and light info from being passed, making it impossible to execute deferred shading passes with the 'render_quad' command. My pass, currently named 'render_custom smartquad' does NOT make the view matrix = Identity and does NOT disable passing the LightList to the material, thus enabling per-light render-quad passes. If adopted by Ogre, the pass name could be changed to something better, maybe "render_quad_deferred". Here is the material I am able to use to perform deferred shading because of the features added by my custom render pass:

Code: Select all

material deferredShadingMaterial
{
  // forces a pass for each light, thus allowing for deferred shading
  iteration once_per_light

  // does NOT apply the MVP matrix because we want to use the IDENTITY matrix so that the quad covers the entire viewport,
  // which means we can just assume the vertex positions are already in viewport-space (or screen-space)...
  vertex_program_ref assume_ScreenSpace_vp
  {
  }

  // this is what my custom render pass allows for. It would be nice if 'render_quad' had attributes that allowed for this usage.
  // using auto-constants for:
  // - light info (e.g. light_position_viewspace, light_direction_viewspace)
  // - camera info (e.g. inverse_view_matrix)
  fragment_program_ref deferred_shading_fp
  {
    // this would be IDENTITY if using 'render_quad'
    // useful for tranforming a view-space position back into world-space, and eventually light-space for the (deferred) lighting calculations.
    param_named_auto Mv_inv inverse_view_matrix

    // these are NOT currently updated when using 'render_quad'
    param_named_auto light_position_vs light_position_view_space 0
    param_named_auto light_attenuation light_attenuation 0
    param_named_auto light_diffuse light_diffuse_colour 0
    param_named_auto light_specular light_specular_colour 0
  }

  // the compositor will supply this
  // THIS IS WHAT MY PATCH ALLOWS FOR IN CUSTOM RENDER PASSES (e.g.: render_custom smartquad)
  texture_unit MRT0
  {
  }

  // the compositor will supply this
  // THIS IS WHAT MY PATCH ALLOWS FOR IN CUSTOM RENDER PASSES (e.g.: render_custom smartquad)
  texture_unit MRT1
  {
  }

  // the compositor will supply this
  // THIS IS WHAT MY PATCH ALLOWS FOR IN CUSTOM RENDER PASSES (e.g.: render_custom smartquad)
  texture_unit MRT2
  {
  }
}
I still advocate the need for public access to CompositorInstance::getSourceForTex(). However, if the render_quad pass could given some new attributes, it would eliminate the need for my custom render pass class. Again, my custom pass is the same as 'render_quad', but it allows the camera and light info to be provided when rendering. The new attributes could be customized like this:

Code: Select all

pass render_quad
{
  // specify a material, as usual
  material deferredShadingMaterial

  // specify the inputs, as usual
  // THIS IS WHAT MY PATCH ALLOWS FOR IN CUSTOM RENDER PASSES (e.g.: render_custom smartquad)
  input 0 MRT 0
  input 1 MRT 1
  input 2 MRT 2

  // NEW ATTRIBUTE
  // specify if scene-camera info should be passed
  // if 'false', material must use a vertex program, and the VP must apply the Identity matrix itself so the quad covers the screen...
  // meaning the vertex program assumes the input vertex position is already provided in viewport-space, and simply assigns the input to the output position.
  useIdentity false  // current behavior in Ogre is true

  // NEW ATTRIBUTE
  // specify if light info should be passed
  // To enable this, I attach a MovableObject::Listener which supplies the LightList when the SimpleRenderable is rendered
  useLighting true // current behavior in Ogre is false (not sure why)
}
[/edit]