Non-separable shader system

2011-07-11

Non-separable shader system

Permalink 03:56:00 pm, Categories: glsl  

As mentioned in the previous post, the main problem was that Cg allows to specify vertex/fragment shaders independently whilst GLSL does not. In fact as I explained last time, GLSL shaders require a linking process that binds the vertex and the fragment shader together. The linking process makes a GL object called a "program" which represent an entire pipeline itself. Shader parameters and other stuff are acting on this object. The shader plugin system of Crystal Space wasn't much designed this way, however layers on top of the plugin system are considering a shader as a pair of vertex and fragment shader, which simplified the work.

Basically, Crystal Space wraps vertex and fragment shaders (csShaderProgram, which implements iShaderProgram) into a single csXMLShaderTech class that is used for rendering. The shaders are specified in the corresponding XML shader file. The basic idea was "iShaderProgram should represent an entire pipeline (so a set of shaders) instead of a single shader". To ensure backward compatibility, this was achieved by adding a simple wrapper class, csXMLShaderWrapper, that holds a vertex and a fragment shader from the old Cg or ASM plugins.

The new GLSL plugin doesn't need to use this wrapper since the shader object provided already contains an entire pipeline, ready to use. A new XML syntax has been setup for shaders that don't need wrapping. You were currently specifing shaders like this:


<pass>
<vp plugin="glcg">
<cgvp>
<program>
<![CDATA[ /* code... */ ]]>
</program>
</cgvp>
</vp>
<fp plugin="glcg">
<cgfp>
<program>
<![CDATA[ /* code... */ ]]>
</program>
</cgfp>
</fp>
</pass>

As you can see, plugins are specified independently; a GLSL plugin could hardly fit this design. The following syntax has been defined for the new plugin:


<pass>
<shader plugin="glsl">
<vp>
<program>
<![CDATA[ /* code ... */ ]]>
</program>
</vp>
<fp>
<program>
<![CDATA[ /* code ... */ ]]>
</program>
</fp>
</shader>
</pass>

The "unification" is made more explicit and the code is lighter.

Trackback address for this post:

This is a captcha-picture. It is used to prevent mass-access by robots.
Please enter the characters from the image above. (case insensitive)

Comments, Trackbacks, Pingbacks:

No Comments/Trackbacks/Pingbacks for this post yet...

This post has 16 feedbacks awaiting moderation...

Comments are not allowed from anonymous visitors.

July 2014
Sun Mon Tue Wed Thu Fri Sat
 << <   > >>
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    

Search

Categories

Archives

Misc

XML Feeds

What is this?

powered by
b2evolution