Changes between Version 3 and Version 4 of MaterialSystem


Ignore:
Timestamp:
Apr 15, 2012, 5:31:19 PM (12 years ago)
Author:
Philip Taylor
Comment:

effects

Legend:

Unmodified
Added
Removed
Modified
  • MaterialSystem

    v3 v4  
    3434Located in [source:ps/trunk/binaries/data/mods/public/art/materials art/materials/]. Example:
    3535{{{
     36#!xml
    3637<?xml version="1.0" encoding="utf-8"?>
    3738<material>
     
    8485 * `USE_TRANSPARENT` - `1` when the texture's alpha channel should be output by the fragment shader.
    8586 * `DISABLE_RECEIVE_SHADOWS` - `1` when shadows should not be cast onto this object.
     87
     88== Shader effects and techniques ==
     89
     90Located in [source:ps/trunk/binaries/data/mods/public/shaders/effects shaders/effects/]. Example:
     91
     92{{{
     93#!xml
     94<?xml version="1.0" encoding="utf-8"?>
     95<effect>
     96
     97    <technique>
     98        <require context="MODE_SHADOWCAST || MODE_SILHOUETTEOCCLUDER"/>
     99        <require shaders="arb"/>
     100        <pass shader="arb/model_solid"/>
     101    </technique>
     102
     103    <technique>
     104        <require context="MODE_SHADOWCAST || MODE_SILHOUETTEOCCLUDER"/>
     105        <require shaders="glsl"/>
     106        <pass shader="glsl/model_solid"/>
     107    </technique>
     108
     109    <technique>
     110        <require context="MODE_SHADOWCAST || MODE_SILHOUETTEOCCLUDER"/>
     111        <require shaders="fixed"/>
     112        <define name="USE_PLAYERCOLOR" value="0"/>
     113        <define name="USE_OBJECTCOLOR" value="0"/>
     114        <pass shader="fixed:model_solid"/>
     115    </technique>
     116
     117    ...
     118
     119    <technique>
     120        <require context="ALPHABLEND_PASS_BLEND"/>
     121        <require shaders="fixed"/>
     122        <sort_by_distance/>
     123        <pass shader="fixed:model">
     124            <define name="USE_TRANSPARENT" value="1"/>
     125            <alpha func="gequal" ref="0.05"/>
     126            <blend src="src_alpha" dst="one_minus_src_alpha"/>
     127            <depth func="less" mask="false"/>
     128        </pass>
     129    </technique>
     130
     131</effect>
     132}}}
     133
     134An `<effect>` contains one or more `<technique>`s. Each technique can have a set of requirements:
     135 * `<require context="..."/>` - an arbitrary conditional expression. (This can refer to defines that come from the material, or the current rendering mode, or the global rendering context.)
     136 * `<require shaders="glsl"/>` - requires that GLSL shaders are supported and enabled.
     137 * `<require shaders="arb"/>` - requires that ARB shaders are supported and enabled.
     138 * `<require shaders="fixed"/>` - requires that fixed-function (OpenGL 1.4ish) rendering is supported and enabled.
     139Whenever a material tries to use an effect, the most preferred technique whose requirements are satisfied will be used. There must always be at least one usable technique in each effect. Typically, techniques that are defined earliest in the XML file will be preferred over techniques defined later. The exception is if the `preferglsl` config option (or `renderer.preferGLSL` in the console) is true, techniques requiring GLSL will always be more preferred than others; if `preferglsl` is false (the default), then ones requiring GLSL will always be less preferred.
     140
     141`<technique>` can also contain:
     142 * (zero or more) `<define name="..." value="..."/>` - add a new define which may be used by the technique's shader programs.
     143 * (rarely used) `<sort_by_distance/>` - required if the technique includes a pass that uses non-commutative alpha-blending. (This causes the engine to sort models from furthest to nearest before rendering, to get correct alpha-blending behaviour.)
     144 * (one or more) `<pass shader="...">` - see below.
     145
     146A '''pass''' is a rendering of a collection of models with a single set of OpenGL state (shader, blending settings, etc). Most techniques only use a single pass, but it's possible to do multi-pass rendering (e.g. do one pass that just writes depth data, and a second pass that writes colour on top of it).
     147
     148Every pass is rendered with a shader program (via the `shader="..."` attribute). `<pass>` can also contain:
     149 * (zero or more) `<define name="..." value="..."/>` - add a new define which may be used by the pass's shader program.
     150 * `<alpha func="..." ref="..."/>` - equivalent to `glAlphaFunc(func, ref)`. `ref` is a float. `func` can be one of `never`, `always`, `less`, `lequal`, `equal`, `gequal`, `greater`, `notequal`.
     151 * `<blend src="..." dst="..."/>` - equivalent to `glBlendFunc(src, dst)`. `src` and `dst` can be one of `zero`, `one`, `(one_minus_)?(src|dst|constant)_(color|alpha)`, `src_alpha_saturate`.
     152 * `<depth func="..."/>` - equivalent to `glDepthFunc(func)`. `func` can be the same values as `<alpha func>`.
     153 * `<depth mask="..."/>` - equivalent to `glDepthMask(mask)`. `mask` can be `true` or `false`.