Board index FlightGear Development Effects and shaders

Effects for models in 2.0.0

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

Effects for models in 2.0.0

Postby Thorsten » Wed Mar 03, 2010 7:42 am

I'm looking for the solution of the following problem:

If I load a model in 2.0.0, by default it gets the effects specified in Effects/model-default.eff - which doesn't work well for some models. I can suppress all effects at runtime from the View/Rendering Options menu deactivating 'Material Shaders' and that does the trick allright, but is an overkill as is removes the nice water appearance as well as the 3-d clouds. I can also modify Effects/model-default.eff to the desired effect - but that holds for all models.

I found that for any terrain cover specified in materials.xml the following tag

<effect>Effects/water</effect>

is used to load a specific effect. I tried the same syntax for models, but I could not texture a model with the water effect this way. So the syntax seems to be slightly different.

Does anyone know how I can specify an effect just for a single model, or just specify that that model should not get any effect?

(And while I'm on it - is there a XML or runtime switch to determine if an object is solid, i.e. if you can collide with it?)

Thanks for any help!
Thorsten
 
Posts: 10638
Joined: Mon Nov 02, 2009 8:33 am

Re: Effects for models in 2.0.0

Postby VicMar » Wed Mar 03, 2010 8:14 am

Hi Thorsten,

I am not sure what you mean in your first or second questions, because the v2.0.0 scenery hasn't been released yet. I guess you are trying to get your model to work in FG v2.0.0. I don't think I can help on those.

However, your third question I can answer:

This little bit of code stops my lighthouse beams (Head) being solid:
<animation>
<object-name>Head</object-name>
<enable-hot type="bool">
false</enable-hot>
</animation>


If I change the 'false' to 'true', any aircraft flying into the rotating beam will crash.

I think that is what you need.

Cheers,
Vic
Time flies like an arrow
Fruit flies like a banana
User avatar
VicMar
 
Posts: 2050
Joined: Sun Apr 06, 2008 5:53 pm
Location: Lancing. UK (EGKA)
Callsign: VicMar
Version: 2018.3.1
OS: OS X 10.12.6

Re: Effects for models in 2.0.0

Postby someguy » Wed Mar 03, 2010 5:22 pm

Wow, that sounds like the basis for a Laser Death Ray! :)
User avatar
someguy
 
Posts: 1653
Joined: Tue Nov 25, 2008 5:54 am
Location: USA
Version: 2016.2.1
OS: Mac OS X 10.11

Re: Effects for models in 2.0.0

Postby VicMar » Wed Mar 03, 2010 8:52 pm

Wow, that sounds like the basis for a Laser Death Ray! :)
Thats exactly the effect the lighthouse beams used to have until I was helped to solve it.
Vic
Time flies like an arrow
Fruit flies like a banana
User avatar
VicMar
 
Posts: 2050
Joined: Sun Apr 06, 2008 5:53 pm
Location: Lancing. UK (EGKA)
Callsign: VicMar
Version: 2018.3.1
OS: OS X 10.12.6

Re: Effects for models in 2.0.0

Postby Tuxklok » Wed Mar 03, 2010 9:02 pm

Thorsten wrote:Does anyone know how I can specify an effect just for a single model, or just specify that that model should not get any effect?

As far as I know this is not yet possible.
The Austria Scenery Project - more info
fg-scenery-tools - gitorious | videos
fgcomgui - Open source, cross platform, gui front end for fgcom. more info

More random musings and doings can be found on my personal site. (work in progress)
User avatar
Tuxklok
 
Posts: 1326
Joined: Tue Apr 21, 2009 6:04 pm
Location: Orlando, FL
Callsign: Tuxklok / N1292P
OS: GNU/Linux

Re: Effects for models in 2.0.0

Postby AndersG » Wed Mar 03, 2010 9:07 pm

Hi,

You can attach a custom effect to an object using this type of construction in the 3d model XML file:
Code: Select all
 <!-- Envelope -->
 <effect>
  <inherits-from>Aircraft/ZF_Navy_free_balloon/Models/Effects/balloon-envelope</inherits-from>
  <object-name>envelope_upper</object-name>
  <object-name>envelope_lower</object-name>
 </effect>


The effect file itself and its vertex and fragment shader programs are done like the examples in Effects/ and Shaders/.
(The one above is WIP and not yet available in CVS.)

Cheers,

Anders
Callsign: SE-AG
Aircraft (uhm...): Submarine Scout, Zeppelin NT, ZF Navy free balloon, Nordstern, Hindenburg, Short Empire flying-boat, ZNP-K, North Sea class, MTB T21 class, U.S.S. Monitor, MFI-9B, Type UB I submarine, Gokstad ship, Renault FT.
AndersG
 
Posts: 2433
Joined: Wed Nov 29, 2006 9:20 am
Location: Göteborg, Sweden
Callsign: SE-AG
OS: Debian GNU Linux

Re: Effects for models in 2.0.0

Postby Tuxklok » Wed Mar 03, 2010 9:29 pm

I stand (happily) corrected. :)
The Austria Scenery Project - more info
fg-scenery-tools - gitorious | videos
fgcomgui - Open source, cross platform, gui front end for fgcom. more info

More random musings and doings can be found on my personal site. (work in progress)
User avatar
Tuxklok
 
Posts: 1326
Joined: Tue Apr 21, 2009 6:04 pm
Location: Orlando, FL
Callsign: Tuxklok / N1292P
OS: GNU/Linux

Re: Effects for models in 2.0.0

Postby Thorsten » Fri Mar 05, 2010 7:09 pm

The help is much appreciated, both xml-tags work fine for me.
Thorsten
 
Posts: 10638
Joined: Mon Nov 02, 2009 8:33 am

Re: Effects for models in 2.0.0

Postby Thorsten » Tue Mar 30, 2010 7:09 am

*reusing the thread...*

I wonder if it is possible to declare a parameter in the xml wrapper for the effect which gets passed on to the shader code. The only example I have seen where parameters are passed to the shader are the 3d clouds /Shaders/3dcloud.vert, but in this case the parameters do not come from an xml structure. Does anyone know if it can be done from xml and if so, what the syntax is?

Thanks!
Thorsten
 
Posts: 10638
Joined: Mon Nov 02, 2009 8:33 am

Re: Effects for models in 2.0.0

Postby i4dnf » Tue Mar 30, 2010 12:20 pm

hi, take a look here , now it depends if that parameter/attribute is available/supported by the shader code and renderer.
i4dnf
Retired
 
Posts: 745
Joined: Wed Sep 09, 2009 7:17 am
Location: LRBS
Callsign: YR-I4D
Version: GIT
OS: Gentoo Linux ~amd64

Re: Effects for models in 2.0.0

Postby Thorsten » Tue Mar 30, 2010 12:41 pm

Hm, as far as I can see not what I'm asking - I want to pass just a number to the shader code, not some supported property. In the cloud shader, the header of the shader contains:

Code: Select all
// -*-C++-*-
#version 120

varying float fogFactor;

attribute vec3 usrAttr3;
attribute vec3 usrAttr4;

float textureIndexX = usrAttr3.r;
float textureIndexY = usrAttr3.g;
float wScale = usrAttr3.b;
float hScale = usrAttr4.r;
float shade = usrAttr4.g;
float cloud_height = usrAttr4.b;


So here usrAttr3 and usrAttr4 are used to pass e.g. shade and cloud_height to the shader code, and I'm looking for a way to set these from the xml wrapper of the Model (not of the effect).
Thorsten
 
Posts: 10638
Joined: Mon Nov 02, 2009 8:33 am

Re: Effects for models in 2.0.0

Postby i4dnf » Tue Mar 30, 2010 2:20 pm

hmm, i guess it's something like this (not tested, just an idea):
Code: Select all
<effect>
  <inherits-from>Effects/cloud.eff</inherits-from>
    <object-name>your-object</object-name>
    <technique n="10">
    <pass n="0">
      <attribute>
        <your-attribute1 type="vec3">125 35 20</your-atttribute1>
        <value type="int">1</value>
      </attribute>
      <attribute>
        <your-attribute2 type="vec3">125 35 20</your-atttribute2>
        <value type="int">2</value>
      </attribute>
      <program>
        <attribute>
          <name>usrAttr3</name>
          <index>1</index>
        </attribute>
        <attribute>
          <name>usrAttr4</name>
          <index>2</index>
        </attribute>
      </program>
    </pass>
  </technique>
</effect>

the first <atribute> tags define your-attribute as a vec3 with those values and indxes them, then in the <program> you link your defined atributes to those in the shader. Being inherited from the cloud.eff it only overrides these parts of that effect deffinition.

BTW, didn't get a chance yet to tell you that i can't wait for the complete local-weather ;)
i4dnf
Retired
 
Posts: 745
Joined: Wed Sep 09, 2009 7:17 am
Location: LRBS
Callsign: YR-I4D
Version: GIT
OS: Gentoo Linux ~amd64

Re: Effects for models in 2.0.0

Postby Thorsten » Wed Mar 31, 2010 6:52 am

Hm, doesn't work. First I tried to insert the code directly into the xml of the model - that gave a crash. Then I tried inserting the code for test purposes into the effect xml file (since the code in the model is supposed to overwrite that).

The part enclosed by <program> </program> works just fine and I get a message on the console Program's vertex attrib binding 1, usrAttr3 - which looks like working. But the part

Code: Select all
 <attribute>
        <your-attribute1 type="vec3">125 35 20</your-atttribute1>
        <value type="int">1</value>
      </attribute>


isn't parsed - it leads to the error

Code: Select all
error reading "/usr/share/FlightGear-2.0.0/Effects/test.eff": mismatched tag
 at /usr/share/FlightGear-2.0.0/Effects/test.eff,
line 21, column 46
can't find base effect Effects/test


so I take this to mean that the xml file is malformed and cannot be parsed, hence no effect is available. Maybe the syntax is different?
Thorsten
 
Posts: 10638
Joined: Mon Nov 02, 2009 8:33 am

Re: Effects for models in 2.0.0

Postby i4dnf » Wed Mar 31, 2010 7:23 am

most likely you've got a typo in the xml, a tag isn't closed properly. Could you post the entire file here, or via pm ?
as to why it crashes if you insert it in the model xml, i have no idea :( .
i4dnf
Retired
 
Posts: 745
Joined: Wed Sep 09, 2009 7:17 am
Location: LRBS
Callsign: YR-I4D
Version: GIT
OS: Gentoo Linux ~amd64

Re: Effects for models in 2.0.0

Postby Thorsten » Wed Mar 31, 2010 8:03 am

Here's the whole file:

Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<PropertyList>
  <name>Effects/test</name>
  <parameters>
    <texture n ="0">
    </texture>
  </parameters>
  <technique n="10">
    <predicate>
      <and>
        <property>/sim/rendering/shader-effects</property>
        <less-equal>
          <value type="float">1.0</value>
          <shader-language/>
        </less-equal>
      </and>
    </predicate>
    <pass n="0">
      <!-- This is apparently not used, so maybe we'll blow it way soon. -->
      <lighting>true</lighting>
      <material>
        <ambient type="vec4d">0.5 0.5 0.5 1.0</ambient>
        <diffuse type="vec4d">0.5 0.5 0.5 1.0</diffuse>
        <color-mode>off</color-mode>
      </material>
      <alpha-test>
        <comparison>greater</comparison>
        <reference type="float">0.01</reference>
      </alpha-test>
      <shade-model>smooth</shade-model>
      <blend>
        <source>src-alpha</source>
        <destination>one-minus-src-alpha</destination>
      </blend>
      <depth>
        <write-mask>false</write-mask>
      </depth>
      <render-bin>
        <bin-number>10</bin-number>
        <bin-name>DepthSortedBin</bin-name>
      </render-bin>
      <texture-unit>
        <unit>0</unit>
   <type><use>texture[0]/type</use></type>
        <image><use>texture[0]/image</use></image>
        <filter><use>texture[0]/filter</use></filter>
        <wrap-s><use>texture[0]/wrap-s</use></wrap-s>
        <wrap-t><use>texture[0]/wrap-t</use></wrap-t>
        <!--<wrap-s>clamp</wrap-s>
        <wrap-t>clamp</wrap-t>-->
      </texture-unit>
      <attribute>
        <mypars type="vec3">5 200 5</mypars>
        <value type="int">1</value>
      </attribute>
      <program>
        <vertex-shader>Shaders/test.vert</vertex-shader>
        <fragment-shader>Shaders/test.frag</fragment-shader>
        <attribute>
          <name>usrAttr3</name>
          <index>1</index>
        </attribute>
        <!--<attribute>
          <name>usrAttr4</name>
          <index>11</index>
        </attribute>-->
      </program>
      <uniform>
        <name>baseTexture</name>
        <type>sampler-2d</type>
        <value type="int">0</value>
      </uniform>
      <vertex-program-two-side>true</vertex-program-two-side>
    </pass>
  </technique>
</PropertyList>


Apparently I 'fixed' something... now it crashes Flightgear consistently with the message

Code: Select all
Uncaught Exception: you should see a meaningful error message
here, but your GLUT (or SDL) library was apparently compiled
and/or linked without exception support. Please complain to
its provider!


which really isn't very helpful.
Thorsten
 
Posts: 10638
Joined: Mon Nov 02, 2009 8:33 am

Next

Return to Effects and shaders

Who is online

Users browsing this forum: No registered users and 1 guest

cron