Game Development Reference
In-Depth Information
point, to associate meta-information with the data. We can use this feature to
enhance our deserialization by making sure that the data responds to the correct
interface we intend to map it to (Listing 20.7).
20.4.3 A DirectX Effects-like File Format for OpenGL
Finally, we introduce the last element of YAML's syntax: aliases. Aliases are
analogous to C pointers, the & character creates a named anchor and the * character
points to this anchor. This process is entirely transparent for the configuration
parser: the aliased nodes look like they have been duplicated.
This kind of behavior is useful for cases where data structures can be reused
multiple times in order to avoid redundancy and reduce errors. We illustrate this
scenario with a very simple metashader file format, similar to DirectX's Effects files,
where multiple shaders can be combined into sequential passes to form techniques
(Listing 20.8).
Of course, other creative uses of YAML's scalars, containers, tags, and aliases
can be thought of to answer the many problems encountered in game development.
We leave these as an exercise for the reader.
phong_vs: &phongvs
varying vec3 N, v;
void main()
{
v = vec3(gl_ModelViewMatrix * gl_Vertex);
N = normalize(gl_NormalMatrix * gl_Normal);
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
phong_fs: &phongfs
varying vec3 N, v;
void main()
{
vec3 L = normalize(gl_LightSource[0].position.xyz - v);
vec4 Idiff = gl_FrontLightProduct[0].diffuse *
max(dot(N, L), 0.0);
gl_FragColor = clamp(Idiff, 0.0, 1.0);
}
techniques
- name: PhongShading
passes:
- name: PhongPass0
vertex_shader: *phongvs
fragment_shader: *phongfs
Listing 20.8. DirectX effects-like definition of a simple Phong lighting shader.
Search WWH ::




Custom Search