Hi fellow wiki editors!

To help newly registered users get more familiar with the wiki (and maybe older users too) there is now a {{Welcome to the wiki}} template. Have a look at it and feel free to add it to new users discussion pages (and perhaps your own).

I have tried to keep the template short, but meaningful. /Johan G

Changes

Jump to: navigation, search

Effect Framework

702 bytes added, 02:25, 8 September 2019
Uniforms passed to shaders outside the xml effect framework: Some new info from Icecode
{{forum|47|Effects & Shaders}}
{{Rendering}}
The effect framework as per version 2019.1
system. The parameters created are:
* material active, ambient, diffuse, specular, emissive, shininess, color mode * # blend active, source, destination * # shade-model * # cull-face * rendering-hint * texture type, image, filter, wrap-s, wrap-t
=Specifying Custom Effects=
In the terrain materials.xml, an "effect" property specifies the name
of the model to use.
 
In model .xml files, A richer syntax is supported. [TO BE DETERMINED]
Material animations will be implemented by creating a new effect
Note that parameters can use the <use> tags to enable properties to specify the values.
 
==Generate==
 
Often shader effects need tangent vectors to work properly. These
tangent vectors, usually called tangent and binormal, are computed
on the CPU and given to the shader as vertex attributes. These
vectors are computed on demand on the geometry using the effect if
the 'generate' clause is present in the effect file. Exemple :
 
<syntaxhighlight lang="xml">
<generate>
<tangent type="int">6</tangent>
<binormal type="int">7</binormal>
<normal type="int">8</normal>
</generate>
</syntaxhighlight>
 
Valid subnodes of 'generate' are 'tangent', 'binormal' or 'normal'.
The integer value of these subnode is the index of the attribute
that will hold the value of the vec3 vector.
 
The generate clause is located under PropertyList in the xml file.
 
In order to be available for the vertex shader, these data should
be bound to an attribute in the program clause, like this :
 
<syntaxhighlight lang="xml">
<program>
<vertex-shader>my_vertex_shader</vertex-shader>
<attribute>
<name>my_tangent_attribute</name>
<index>6</index>
</attribute>
<attribute>
<name>my_binormal_attribute</name>
<index>7</index>
</attribute>
</program>
</syntaxhighlight>
 
attribute names are whatever the shader use. The index is the one
declared in the 'generate' clause. So because generate/tangent has
value 6 and my_tangent_attribute has index 6, my_tangent_attribute
holds the tangent value for the vertex.
==Technique==
Example:
<syntaxhighlight lang="xml">
<texture-unitblend>
<active>true</active>
<source>one-minus-dst-alpha</source>
<destination>src-alpha-saturate</destination>
</texture-unitblend>
</syntaxhighlight>
====uniform====
Data accessible by shaders.
=====name=====
=====type=====name: the name type: bool, int, float, float-vec3, float-vec4, sampler-1d, sampler-2d, sampler-3d, sampler-1d-shadow, sampler-2d-shadow, sampler-cube
====alpha-test====
=====active=====: true, false
=====comparison=====: never, less, equal, lequal, greater, notequal, gequal, always
=====reference=====: 0 to 1
====render-bin====
Sent to OSG.
=====bin-number=====
This is an integer defining the order stuff will be rendered in, it can be negative also.
=====bin-name=====number: This is an integer defining the order stuff will be rendered in, it can be negative also. bin-name: RenderBin, DepthSortedBin
====rendering-hint====
</syntaxhighlight>
===Generate=== Often shader effects need tangent vectors to work properly. These tangent vectors, usually called tangent and binormal, are computed on the CPU and given to the shader as vertex attributes. These vectors are computed on demand on the geometry using the effect if the 'generate' clause is present in the effect file. Exemple : <syntaxhighlight lang="xml"> <generate> <tangent type="int">6</tangent> <binormal type="int">7</binormal> <normal type="int">8</normal> </generate></syntaxhighlight> Valid subnodes of 'generate' are 'tangent', 'binormal' or 'normal'.The integer value of these subnode is the index of the attribute that will hold the value of the vec3 vector. The generate clause is located under PropertyList in the xml file. In order to be available See this page for the vertex shader, these data should be bound to an attribute in the program clause, like this more about shaders<syntaxhighlight lang="xml"> <program> <vertex-shader>my_vertex_shader</vertex-shader> <attribute> <name>my_tangent_attribute</name> <index>6</index> </attribute> <attribute> <name>my_binormal_attribute</name> <index>7</index> </attribute> </program></syntaxhighlight> attribute names are whatever the shader use. The index is the one declared [[Howto:Shader programming in the 'generate' clause. So because generate/tangent has value 6 and my_tangent_attribute has index 6, my_tangent_attribute holds the tangent value for the vertex.FlightGear]]
=Uniforms passed to shaders outside the xml effect framework=
|<tt>fg_ViewMatrix</tt>
|<tt>mat4</tt>
|In fullscreen pass only, view matrix used to transform the screen position from world to view directionspace. Same as osg_ViewMatrix, but for fullscreen pass.
|-
|<tt>fg_ViewMatrixInverse</tt>
|<tt>mat4</tt>
|In fullscreen pass only, view matrix inverse used to transform the screen position to from view directionto world space. Same as osg_ViewMatrixInverse but for fullscreen pass.
|-
|<tt>fg_ProjectionMatrixInverse</tt>
|<tt>mat4</tt>
|In fullscreen pass only, projection matrix inverse used to transform the screen position to view direction
|-
|<tt>fg_CameraPositionCart</tt>
|<tt>fg_SunAmbientColor</tt>
|<tt>vec4</tt>
|For fullscreen pass only, sun information as lightsource[0] is not available in fullscreen pass.
|-
|<tt>fg_SunDiffuseColor</tt>
|<tt>vec4</tt>
|For fullscreen pass only, sun information as lightsource[0] is not available in fullscreen pass.
|-
|<tt>fg_SunSpecularColor</tt>
|<tt>vec4</tt>
|For fullscreen pass only, sun information as lightsource[0] is not available in fullscreen pass.
|-
|<tt>fg_SunDirection</tt>
|<tt>vec3</tt>
|For fullscreen pass only, sun information as lightsource[0] is not available in fullscreen pass.
|-
|<tt>fg_FogColor</tt>
|<tt>osg_ViewMatrix</tt>
|<tt>mat4</tt>
|Defined by OSG, used only when working on actual geometry. Transforms from world to view space.
|-
|<tt>osg_ViewMatrixInverse</tt>
|<tt>mat4</tt>
|Defined by OSG, used only when working on actual geometry. Transforms from view to world space.
|-
|<tt>osg_SimulationTime</tt>
|<tt>float</tt>
|Defined by OSG
|-
|<tt>osg_FrameTime</tt>
|<tt>float</tt>
|Defined by OSG
|-
|<tt>osg_DeltaFrameTime</tt>
|<tt>float</tt>
|Defined by OSG
|-
|<tt>osg_FrameTime</tt>
|<tt>float</tt>
|Defined by OSG
|-
|<tt>osg_FrameNumber</tt>
|<tt>int</tt>
|Defined by OSG
|}
[[Category:Shader development]]
493
edits

Navigation menu