574
edits
(→Uniforms passed to shaders outside the xml effect framework: Some new info from Icecode) |
|||
(22 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 40: | Line 42: | ||
system. The parameters created are: | 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= | =Specifying Custom Effects= | ||
Line 54: | Line 55: | ||
In the terrain materials.xml, an "effect" property specifies the name | In the terrain materials.xml, an "effect" property specifies the name | ||
of the model to use. | of the model to use. | ||
Material animations will be implemented by creating a new effect | Material animations will be implemented by creating a new effect | ||
Line 62: | Line 61: | ||
=Examples= | =Examples= | ||
The Effects directory contains the effects definitions; look there for | The $FGDATA/Effects directory contains the effects definitions; look there for | ||
examples. Effects/crop.eff is a good example of a complex effect. | examples. Effects/crop.eff is a good example of a complex effect. | ||
Line 131: | 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 337: | ||
Children values: dst-alpha, dst-color, one, one-minus-dst-alpha, one-minus-dst-color, one-minus-src-alpha, one-minus-src-color, src-alpha, src-alpha-saturate, src-color, constant-color, one-minus-constant-color, constant-alpha, one-minus-constant-alpha, zero | Children values: dst-alpha, dst-color, one, one-minus-dst-alpha, one-minus-dst-color, one-minus-src-alpha, one-minus-src-color, src-alpha, src-alpha-saturate, src-color, constant-color, one-minus-constant-color, constant-alpha, one-minus-constant-alpha, zero | ||
Example: | |||
<syntaxhighlight lang="xml"> | |||
<blend> | |||
<active>true</active> | |||
<source>one-minus-dst-alpha</source> | |||
<destination>src-alpha-saturate</destination> | |||
</blend> | |||
</syntaxhighlight> | |||
====shade-model==== | ====shade-model==== | ||
Line 300: | Line 352: | ||
====cull-face==== | ====cull-face==== | ||
front, back, front-back, off | front, back, front-back, off | ||
====texture-unit==== | ====texture-unit==== | ||
Line 326: | Line 373: | ||
<function-a>product</function-a> | <function-a>product</function-a> | ||
</mitmap-control> | </mitmap-control> | ||
<environment> | |||
<mode>decal</mode> | |||
<color>0.0 0.1 0.6 1.0</color> | |||
</environment> | |||
<point-sprite>true</point-sprite> | |||
<texenv-combine>operand0-rgb</texenv-combine> | |||
<texgen> | |||
<mode>S</mode> | |||
<planes>0.075, 0.0, 0.0, 0.5</planes> | |||
</texgen> | |||
</texture-unit> | </texture-unit> | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 342: | Line 399: | ||
====uniform==== | ====uniform==== | ||
Data accessible by shaders. | Data accessible by shaders. | ||
name: the name | |||
bool, int, float, float-vec3, float-vec4, sampler-1d, sampler-2d, sampler-3d, sampler-1d-shadow, sampler-2d-shadow, sampler-cube | |||
type: bool, int, float, float-vec3, float-vec4, sampler-1d, sampler-2d, sampler-3d, sampler-1d-shadow, sampler-2d-shadow, sampler-cube | |||
====alpha-test==== | ====alpha-test==== | ||
active: true, false | |||
true, false | |||
comparison: never, less, equal, lequal, greater, notequal, gequal, always | |||
never, less, equal, lequal, greater, notequal, gequal, always | |||
reference: 0 to 1 | |||
====render-bin==== | ====render-bin==== | ||
Sent to OSG. | Sent to OSG. | ||
==== | bin-number: This is an integer defining the order stuff will be rendered in, it can be negative also. | ||
bin-name: RenderBin, DepthSortedBin | |||
====rendering-hint==== | |||
Sent to OSG. | |||
default, opaque, transparent | |||
This basically just sets Renderbin: | |||
opaque = bin 10, depthsortedbin | |||
transparent = bin 0, renderbin | |||
default = inherit renderbin details from parent node | |||
====program==== | ====program==== | ||
Line 375: | Line 441: | ||
* geometry-output-type - points, line-strip, triangle-strip | * geometry-output-type - points, line-strip, triangle-strip | ||
example: | |||
<syntaxhighlight lang="xml"> | <syntaxhighlight lang="xml"> | ||
<program> | |||
<vertex-shader n="0">Shaders/lcd.vert</vertex-shader> | |||
<fragment-shader n="0">Shaders/lcd.frag</fragment-shader> | |||
<fragment-shader n="1">Shaders/noise.frag</fragment-shader> | |||
<fragment-shader n="2">Shaders/filters-ALS.frag</fragment-shader> | |||
</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 428: | 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 | |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 | |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 | |In fullscreen pass only, projection matrix inverse | ||
|- | |- | ||
|<tt>fg_CameraPositionCart</tt> | |<tt>fg_CameraPositionCart</tt> | ||
Line 448: | 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 492: | 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]] |
edits