shiny
0.4
a shader and material management library for OGRE
|
These macros are automatically defined, depending on the shader language that has been set by the application using sh::Factory::setCurrentLanguage.
Example:
These macros are automatically defined, depending on the type of shader that is currently being compiled.
If you use the same source file for both vertex and fragment shader, then it is advised to use these macros for blending out the unused source. This will reduce your compile time.
In shader development, a common task is to pass variables from the vertex to the fragment shader. This is no problem if you have a deterministic shader source (i.e. no #ifdefs).
However, as soon as you begin to have lots of permutations of the same shader source, a problem arises. All current GPUs have a limit of 8 vertex to fragment passthroughs (with 4 components each, for example a float4).
A common optimization is to put several individual float values together in a float4 (so-called "Packing"). But if your shader has lots of permutations and the passthrough elements you actually need are not known beforehand, it can be very tedious to pack manually. With the following macros, packing can become easier.
Usage: @shAllocatePassthrough(num_components, name)
Example:
This is the first thing you should do before using any of the macros below.
Usage: @shPassthroughVertexOutputs
Use this in the inputs/outputs section of your vertex shader, in order to declare all the outputs that are needed for packing the variables that you want passed to the fragment.
Usage: @shPassthroughFragmentInputs
Use this in the inputs/outputs section of your fragment shader, in order to declare all the inputs that are needed for receiving the variables that you want passed to the fragment.
Usage: @shPassthroughAssign(name, value)
Use this in the vertex shader for assigning a value to the variable you want passed to the fragment.
Example:
Usage: @shPassthroughReceive(name)
Use this in the fragment shader to receive the passed value.
Example:
Usage: @shUseSampler(samplerName)
Requests the texture unit with name samplerName to be available for use in this pass.
Why is this necessary? If you have a derived material that does not use all of the texture units that its parent defines (for example, if an optional asset such as a normal map is not available), there would be no way to know which texture units are actually needed and which can be skipped in the creation process (those that are never referenced in the shader).
Usage: @shPropertyHasValue(property)
Gets replaced by 1 if the property's value is not empty, or 0 if it is empty. Useful for checking whether an optional texture is present or not.
Example:
Usage: @shUniformProperty<4f|3f|2f|1f|int> (uniformName, property)
Binds the value of property (from the shader_properties of the pass this shader belongs to) to the uniform with name uniformName.
The following variants are available, depending on the type of your uniform variable:
Example: @shUniformProperty1f (uFresnelScale, fresnelScale)
Retrieve a boolean property of the pass that this shader belongs to, gets replaced with either 0 or 1.
Usage: @shPropertyBool(propertyName)
Example:
Retrieve a string property of the pass that this shader belongs to
Usage: @shPropertyString(propertyName)
Check if the value of a property equals a specific value, gets replaced with either 0 or 1. This is useful because the preprocessor cannot compare strings, only numbers.
Usage: @shPropertyEqual(propertyName, value)
Example:
Retrieves the boolean value of a specific global setting, gets replaced with either 0 or 1. The value can be set using sh::Factory::setGlobalSetting.
Usage: @shGlobalSettingBool(settingName)
Check if the value of a global setting equals a specific value, gets replaced with either 0 or 1. This is useful because the preprocessor cannot compare strings, only numbers.
Usage: @shGlobalSettingEqual(settingName, value)
Gets replaced with the current value of a given global setting. The value can be set using sh::Factory::setGlobalSetting.
Usage: @shGlobalSettingString(settingName)
Allows you to bind a custom value to a uniform parameter.
Usage: @shSharedParameter(sharedParameterName)
Example: @shSharedParameter(pssmSplitPoints) - now the uniform parameter 'pssmSplitPoints' can be altered in all shaders that use it by executing sh::Factory::setSharedParameter("pssmSplitPoints", value)
Usage: @shAutoConstant(uniformName, autoConstantName, [extraData])
Example: @shAutoConstant(uModelViewMatrix, worldviewproj_matrix)
Example: @shAutoConstant(uLightPosition4, light_position, 4)
Binds auto constant with name autoConstantName to the uniform uniformName. Optionally, you may specify extra data (for example the light index), as required by some auto constants.
The auto constant names are the same as Ogre's. Read the section "3.1.9 Using Vertex/Geometry/Fragment Programs in a Pass" of the Ogre manual for a list of all auto constant names.
Usage: @shForeach(n)
Repeats the content of this foreach block n times. The end of the block is marked via @shEndForeach, and the current iteration number can be retrieved via @shIterator.
Example:
Optionally, you can pass a constant offset to @shIterator. Example:
Gets replaced after the preprocessing step with the number that equals the n-th occurence of counters of the same ID.
Usage: @shCounter(ID)
Example:
Gets replaced with: