Effect framework: Difference between revisions

Jump to navigation Jump to search
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{forum|47|Effects & Shaders}}
{{Rendering}}
The effect framework as per version 2019.1
The effect framework as per version 2019.1


Line 128: Line 130:


Note that parameters can use the <use> tags to enable properties to specify the values.
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==
==Technique==
Line 294: Line 340:
Example:
Example:
<syntaxhighlight lang="xml">
<syntaxhighlight lang="xml">
                 <texture-unit>
                 <blend>
                         <active>true</active>
                         <active>true</active>
                         <source>one-minus-dst-alpha</source>
                         <source>one-minus-dst-alpha</source>
<destination>src-alpha-saturate</destination>
<destination>src-alpha-saturate</destination>
</texture-unit>
</blend>
</syntaxhighlight>
</syntaxhighlight>


Line 405: Line 451:
</program>
</program>
</syntaxhighlight>
</syntaxhighlight>
See this page for more about shaders: [[Howto:Shader programming in FlightGear]]


=Uniforms passed to shaders outside the xml effect framework=
=Uniforms passed to shaders outside the xml effect framework=
Line 415: Line 463:
|<tt>fg_ViewMatrix</tt>
|<tt>fg_ViewMatrix</tt>
|<tt>mat4</tt>
|<tt>mat4</tt>
|In fullscreen pass only, view matrix used to transform the screen position to view direction
|In fullscreen pass only, view matrix used to transform from world to view space. Same as osg_ViewMatrix, but for fullscreen pass.
|-
|-
|<tt>fg_ViewMatrixInverse</tt>
|<tt>fg_ViewMatrixInverse</tt>
|<tt>mat4</tt>
|<tt>mat4</tt>
|In fullscreen pass only, view matrix inverse used to transform the screen position to view direction
|In fullscreen pass only, view matrix inverse used to transform from view to world space. Same as osg_ViewMatrixInverse but for fullscreen pass.
|-
|-
|<tt>fg_ProjectionMatrixInverse</tt>
|<tt>fg_ProjectionMatrixInverse</tt>
|<tt>mat4</tt>
|<tt>mat4</tt>
|In fullscreen pass only, projection matrix inverse used to transform the screen position to view direction
|In fullscreen pass only, projection matrix inverse
|-
|-
|<tt>fg_CameraPositionCart</tt>
|<tt>fg_CameraPositionCart</tt>
Line 435: Line 483:
|<tt>fg_SunAmbientColor</tt>
|<tt>fg_SunAmbientColor</tt>
|<tt>vec4</tt>
|<tt>vec4</tt>
|
|For fullscreen pass only, sun information as lightsource[0] is not available in fullscreen pass.
|-
|-
|<tt>fg_SunDiffuseColor</tt>
|<tt>fg_SunDiffuseColor</tt>
|<tt>vec4</tt>
|<tt>vec4</tt>
|
|For fullscreen pass only, sun information as lightsource[0] is not available in fullscreen pass.
|-
|-
|<tt>fg_SunSpecularColor</tt>
|<tt>fg_SunSpecularColor</tt>
|<tt>vec4</tt>
|<tt>vec4</tt>
|
|For fullscreen pass only, sun information as lightsource[0] is not available in fullscreen pass.
|-
|-
|<tt>fg_SunDirection</tt>
|<tt>fg_SunDirection</tt>
|<tt>vec3</tt>
|<tt>vec3</tt>
|
|For fullscreen pass only, sun information as lightsource[0] is not available in fullscreen pass.
|-
|-
|<tt>fg_FogColor</tt>
|<tt>fg_FogColor</tt>
Line 479: Line 527:
|<tt>osg_ViewMatrix</tt>
|<tt>osg_ViewMatrix</tt>
|<tt>mat4</tt>
|<tt>mat4</tt>
|Defined by OSG, used only when working on actual geometry
|Defined by OSG, used only when working on actual geometry. Transforms from world to view space.
|-
|-
|<tt>osg_ViewMatrixInverse</tt>
|<tt>osg_ViewMatrixInverse</tt>
|<tt>mat4</tt>
|<tt>mat4</tt>
|Defined by OSG, used only when working on actual geometry
|Defined by OSG, used only when working on actual geometry. Transforms from view to world space.
|-
|-
|<tt>osg_SimulationTime</tt>
|<tt>osg_SimulationTime</tt>
|<tt>float</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
|Defined by OSG
|}
|}


[[Category:Shader development]]
[[Category:Shader development]]
574

edits

Navigation menu