Board index FlightGear Development Effects and shaders

Creating a new uniform in C++

An exciting "new" option in FlightGear, that includes reflections, lightmaps, the particle system etc.. A lot is yet to be discovered/implemented!

Creating a new uniform in C++

Postby Flying toaster » Wed Jan 18, 2017 5:46 pm

Hello,
I am trying to set a uniform from the C++ code but somehow get something very wrong. Here is the piece of code I am toying with:
Code: Select all
 
_aircraft_model_matrix_uniform = new osg::Uniform(osg::Uniform::FLOAT,"aircraft_model_matrix");
     std::vector<osg::Camera*> cameras;
   globals->get_renderer()->getViewer()->getCameras(cameras);
    printf ("Number of cameras : %i\n", cameras.size());
    _aircraft_model_matrix_uniform->set(10.0f);
    osg::StateSet* current_state_set = cameras[0]->getStateSet();
    if (current_state_set)
    {
      current_state_set->addUniform (_aircraft_model_matrix_uniform);   
   }

To answer some obvious questions, the number of cameras is 3 and the code fails to deliver anything but 0 as an output no matter what camera index is used in the line
Code: Select all
  osg::StateSet* current_state_set = cameras[0]->getStateSet();

Any indication of how to do this properly would be welcome.

Thanks

Enrique
Flying toaster
 
Posts: 348
Joined: Wed Nov 29, 2006 6:25 am
Location: Toulouse France

Re: Creating a new uniform in C++

Postby zakalawe » Tue Jan 24, 2017 5:12 pm

I would suggest brining this question to the developer list, because there's quite a few potential problems here, unfortunately.
zakalawe
 
Posts: 1149
Joined: Sat Jul 19, 2008 4:48 pm
Location: Edinburgh, Scotland
Callsign: G-ZKLW
Version: next
OS: Mac

Re: Creating a new uniform in C++

Postby Hooray » Wed Jan 25, 2017 4:54 pm

I am not much of a graphics coder, but I have previously succeeded doing this by referring to the photoscenery patches that are to be found in the wiki: http://wiki.flightgear.org/Photoscenery ... otoscenery

I used that code as a template to come up with effects/shader support for Canvas textures:

http://wiki.flightgear.org/Canvas_Devel ... 2F_Shaders
Image

These days, I believe it would be more appropriate to skip this step and directly integrate the Canvas system with the SGMaterial infrastructure - but I didn't realize that back then. If done properly, any Canvas would become available as a material, and any material can use effects and shaders - i.e. you could have nested chains of materials using one Canvas as the input, and another as the output - ultimately, approaching what Tim Moore and Stuart originally discussed on the devel list a while ago:

http://www.mail-archive.com/flightgear- ... 37873.html
Tim Moore wrote:It would be nice if the Effects framework had a way to load arbitrary textures and make them available to effects.I don't know if there is a better way to create your texture offline than write C++ code in simgear. OSG will read a TIFF file with 32bits per component as a floating point texture... assuming you can create such a thing


In general, this is one of the more commonly requested features:
https://sourceforge.net/p/flightgear/ma ... /32072598/
James Turner wrote:If you want to pass substantial amounts of data, I’d suggest to use a texture (with filtering disabled, probably) to pass the info. Since we don’t have much chance of using the ‘correct’ solution (UBOs) in the near future.

If you need help generating a suitable texture on the CPU side, let me know.


Thus, if/when the Canvas system is sufficiently integrated with the effects/shader system, any camera (MFD/scenery, offscreen or not) can trivially make use of this functionality without requiring tons of custom code - at the mere cost of adding the corresponding Canvas Elements to the Canvas::Group registry, which would also work for slave-cameras (or those using OSG CompositeViewer):


http://wiki.flightgear.org/Canvas_Sandbox#CanvasCamera
http://wiki.flightgear.org/CompositeViewer_Support
Image


This would also provide an excellent extension mechanism for alternate scenery/terrain schemes like psadro_gm's work or the osgearth work created by poweroftwo.

As usual, most of the functionality is already there, it's just not very well integrated (yet), because many features were/are being developed independently (so far).
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11119
Joined: Tue Mar 25, 2008 8:40 am


Return to Effects and shaders

Who is online

Users browsing this forum: No registered users and 2 guests