Sophie

Sophie

distrib > Mandriva > 10.0 > i586 > media > contrib > by-pkgid > 06719cf03808e17ae6f0852ca1052dc2 > files > 3612

libogre1-devel-0.13.0-1mdk.i586.rpm

<HTML>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Created on , 21 2004 by texi2html 1.64 -->
<!-- 
Written by: Lionel Cons <Lionel.Cons@cern.ch> (original author)
            Karl Berry  <karl@freefriends.org>
            Olaf Bachmann <obachman@mathematik.uni-kl.de>
            and many others.
Maintained by: Olaf Bachmann <obachman@mathematik.uni-kl.de>
Send bugs and suggestions to <texi2html@mathematik.uni-kl.de>
 
-->
<HEAD>
<TITLE>OGRE Manual: Using Vertex and Fragment Programs in a Pass</TITLE>

<META NAME="description" CONTENT="OGRE Manual: Using Vertex and Fragment Programs in a Pass">
<META NAME="keywords" CONTENT="OGRE Manual: Using Vertex and Fragment Programs in a Pass">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<META NAME="Generator" CONTENT="texi2html 1.64">
<LINK TYPE="text/css" rel="stylesheet" href="../style.css"> 
</HEAD>

<BODY LANG="" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080" ALINK="#FF0000">

<A NAME="SEC76"></A>
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual_20.html#SEC72"> &lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual_16.html#SEC25"> Up </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual_22.html#SEC82"> &gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="index.html#SEC_Top">Top</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual_toc.html#SEC_Contents">Contents</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual_abt.html#SEC_About"> ? </A>]</TD>
</TR></TABLE>
<HR SIZE=1>
<H3> 3.1.5 Using Vertex and Fragment Programs in a Pass </H3>
<!--docid::SEC76::-->
<P>

Within a pass section of a material script, you can reference a vertex and / or a fragment program which is been defined in a .program script (See section <A HREF="manual_20.html#SEC72">3.1.4 Declaring Vertex and Fragment Programs</A>). The programs are defined separately from the usage of them in the pass, since the programs are very likely to be reused between many separate materials, probably across many different .material scripts, so this approach lets you define the program only once and use it many times.<BR><BR>
</P><P>

As well as naming the program in question, you can also provide parameters to it. Here's a simple example:
<TABLE><tr><td>&nbsp;</td><td class=example><pre>vertex_program_ref myVertexProgram
{
	param_indexed_auto 0 worldviewproj_matrix
	param_indexed      4 float4  10.0 0 0 0
}
</pre></td></tr></table>In this example, we bind a vertex program called 'myVertexProgram' (which will be defined elsewhere) to the pass, and give it 2 parameters, one is an 'auto' parameter, meaning we do not have to supply a value as such, just a recognised code (in this case it's the world/view/projection matrix which is kept up to date automatically by Ogre). The second parameter is a manually specified parameter, a 4-element float. The indexes are described later.<BR><BR>
</P><P>

The syntax of the link to a vertex program and a fragment program are identical, the only difference is that 'fragment_program_ref' is used instead of 'vertex_program_ref'.
</P><P>

<A NAME="SEC77"></A>
<H3> Parameter specification </H3>
<!--docid::SEC77::-->
Parameters can be specified using one of 4 commands:
<UL>
<LI><A HREF="manual_21.html#SEC78">param_indexed</A>
<LI><A HREF="manual_21.html#SEC79">param_indexed_auto</A>
<LI><A HREF="manual_21.html#SEC80">param_named</A>
<LI><A HREF="manual_21.html#SEC81">param_named_auto</A>
</UL>
<P>

<A NAME="param_indexed"></A>
<A NAME="SEC78"></A>
<H3> param_indexed </H3>
<!--docid::SEC78::-->
This command sets the value of an indexed parameter. <BR><BR>
<P>

format: param_indexed &#60;index&#62; &#60;type&#62; &#60;value&#62;<BR><BR>
example: param_indexed 0 float4 10.0 0 0 0<BR><BR>
</P><P>

The 'index' is simply a number representing the position in the parameter list which the value should be written, and you should derive this from your program definition. The index is relative to the way constants are stored on the card, which is in 4-element blocks. For example if you defined a float4 parameter at index 0, the next index would be 1. If you defined a matrix4x4 at index 0, the next usable index would be 4, since a 4x4 matrix takes up 4 indexes.<BR><BR>
</P><P>

The value of 'type' can be float4, matrix4x4, float&#60;n&#62; (where &#60;n&#62; is a multiple of 4), int4, int&#60;n&#62; (where &#60;n&#62; is a mutiple of 4 again). Note that 'int' parameters are only available on some more advanced program syntaxes, check the D3D or GL vertex / fragment program documentation for full details. Typically the most useful ones will be float4 and matrix4x4. <BR><BR>
</P><P>

'value' is simply a space or tab-delimited list of values which can be converted into the type you have specified.
</P><P>

<A NAME="param_indexed_auto"></A>
<A NAME="SEC79"></A>
<H3> param_indexed_auto </H3>
<!--docid::SEC79::-->
<P>

This command tells Ogre to automatically update a given parameter with a derived value. This frees you from writing code to update program parameters every frame when they are always changing.<BR><BR>
</P><P>

format: param_indexed_auto &#60;index&#62; &#60;value_code&#62; &#60;extra_params&#62;<BR><BR>
example: param_indexed_auto 0 WORLDVIEWPROJ_MATRIX<BR><BR>
</P><P>

'index' has the same meaning as <A HREF="manual_21.html#SEC78">param_indexed</A>; note this time you do not have to specify the size of the parameter because the engine knows this already. In the example, the world/view/projection matrix is being used so this is implicitly a matrix4x4.<BR><BR>
</P><P>

'value_code' is one of a list of recognised values:<BR>
<DL COMPACT>
<DT>world_matrix
<DD>The current world matrix.
<DT>view_matrix
<DD>The current view matrix.
<DT>projection_matrix
<DD>The current projection matrix.
<DT>worldview_matrix
<DD>The current world and view matrices concatenated.
<DT>worldviewproj_matrix
<DD>The current world, view and projection matrices concatenated.
<DT>inverse_world_matrix
<DD>The inverse of the current world matrix.
<DT>inverse_worldview_matrix
<DD>The inverse of the current concatenated world and view matrices.
<DT>light_diffuse_colour
<DD>The diffuse colour of a given light; this requires an index in the 'extra_params' field, and relates to the 'nth' closest light which could affect this object (ie 0 refers to the closest light). NB if there are no lights this close, then the parameter will be set to black.
<DT>light_specular_colour
<DD>The specular colour of a given light; this requires an index in the 'extra_params' field, and relates to the 'nth' closest light which could affect this object (ie 0 refers to the closest light). NB if there are no lights this close, then the parameter will be set to black.
<DT>light_attenuation
<DD>A float4 containing the 4 light attenuation variables for a given light. This requires an index in the 'extra_params' field, and relates to the 'nth' closest light which could affect this object (ie 0 refers to the closest light). NB if there are no lights this close, then the parameter will be set to all zeroes. The order of the parameters is range, constant attenuation, linear attenuation, quadric attenuation.
<DT>light_position_object_space
<DD>The position of a given light in object space (ie when the object is at (0,0,0)). This requires an index in the 'extra_params' field, and relates to the 'nth' closest light which could affect this object (ie 0 refers to the closest light). NB if there are no lights this close, then the parameter will be set to all zeroes.
<DT>light_direction_object_space
<DD>The direction of a given light in object space (ie when the object is at (0,0,0)). This requires an index in the 'extra_params' field, and relates to the 'nth' closest light which could affect this object (ie 0 refers to the closest light). NB if there are no lights this close, then the parameter will be set to all zeroes.
<DT>ambient_light_colour
<DD>The colour of the ambient light currently set in the scene.
<DT>camera_position_object_space
<DD>The current cameras position in object space (ie when the object is at (0,0,0)).
<DT>time
<DD>The current time, factored by the optional parameter (or 1.0f if not supplied).
</DL>
<P>

<A NAME="param_named"></A>
<A NAME="SEC80"></A>
<H3> param_named </H3>
<!--docid::SEC80::-->
This is the same as param_indexed, but uses a named parameter instead of an index. This can only be used with high-level programs which include parameter names; if you're using an assembler program then you have no choice but to use indexes. Note that you can use indexed parameters for high-level programs too, but it is less portable since if you reorder your parameters in the high-level program the indexes will change.<BR><BR>
format: param_named &#60;name&#62; &#60;type&#62; &#60;value&#62;<BR><BR>
example: param_named shininess float4 10.0 0 0 0<BR><BR>
The type is required because the program is not compiled and loaded when the material script is parsed, so at this stage we have no idea what types the parameters are. Programs are only loaded and compiled when they are used, to save memory.
<P>

<A NAME="param_named_auto"></A>
<A NAME="SEC81"></A>
<H3> param_named_auto </H3>
<!--docid::SEC81::-->
<P>

This is the named equivalent of param_indexed_auto, for use with high-level programs.<BR><BR>
Format: param_named_auto &#60;name&#62; &#60;value_code&#62; &#60;extra_params&#62;<BR><BR>
Example: param_named_auto worldViewProj WORLDVIEWPROJ_MATRIX<BR><BR>
</P><P>

The allowed value codes and the meaning of extra_params are detailed in <A HREF="manual_21.html#SEC79">param_indexed_auto</A>.
</P><P>

<A NAME="Particle Scripts"></A>
<HR SIZE=1>
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual_20.html#SEC72"> &lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual_16.html#SEC25"> Up </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual_22.html#SEC82"> &gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="index.html#SEC_Top">Top</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual_toc.html#SEC_Contents">Contents</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual_abt.html#SEC_About"> ? </A>]</TD>
</TR></TABLE>
<BR>  
<FONT SIZE="-1">
This document was generated
by <I>Steve Streeting</I> on <I>, 21 2004</I>
using <A HREF="http://www.mathematik.uni-kl.de/~obachman/Texi2html
"><I>texi2html</I></A>

</BODY>
</HTML>