574
edits
(→blend) |
(→Uniforms passed to shaders outside the xml effect framework: Some new info from Icecode) |
||
(11 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 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 297: | Line 340: | ||
Example: | Example: | ||
<syntaxhighlight lang="xml"> | <syntaxhighlight lang="xml"> | ||
< | <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> | ||
</ | </blend> | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 356: | 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 | |||
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. | |||
RenderBin, DepthSortedBin | |||
bin-name: RenderBin, DepthSortedBin | |||
====rendering-hint==== | ====rendering-hint==== | ||
Line 413: | Line 452: | ||
</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 466: | 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 486: | 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 530: | 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