FragmentLinker ?

Started by
0 comments, last by Namethatnobodyelsetook 18 years, 11 months ago
Hi! I've been learning some about hlsl and written a couple simple vertex/pixel shaders. But I can't get the grip of how to use the FragmentLinker - or rather what purpose it has? Does the FragmentLinker enable similar code to interfaces with CG shaders? Would appreciate an example of how a simple shader would look in use with the FragmentLinker :) Thank you!
Advertisement
The fragment linker sample shows it can be used, though it's a bit unclear as it assigns fragment pointers to controls in one section of code, then extracts those pointers and links them somewhere else, however being told that's what's going on, the sample should be pretty clear.

What's it do?

Instead of assigning a specific vertex and/or pixel shader in your effect, you can leave it open for you to determine at runtime. You can use the fragment linker to select function to use as your shader, or even mix bits of shader code to form a full shader.

Lets use an example (and get carried away at the end of it)

Lets say we want to light our mesh. In the non-linker way, we could make a shader that did a directional light. If you want a second light, you make a second technique that does two directional lights. Want a third, okay another technique. Wait. One of them is a point light. Oh, and I want fog. Or not. And my mesh just plain world transformed. No, wait, it's skinned with 1 bone per vertex, no make that 4... or 3. 3 is good.

The problem is the number of combinations.

(0,1,2,3,4 bones) = 5 combos.
Lets say we support upto 4 lights of two types
(0 lights) = 1 combo
(1 light) = 2 combos
(2 lights) = 4 combos
(3 lights) = 8 combos
(4 lights) = 16 combos, so 31 lighting combos.
(no fog, depth fog, height fog, dual fog) = 4 combos
(no texture transform, 1 transform, etc. etc..) = n combos.

That results in 5*31*4*n*... combinations of shaders. It's getting ridiculous.

Enter the fragment linker. A fragment is a function call that can either just access globals, or access a result calculated in another fragment.

Make 5 geometry transform fragments (0,1,2,3,4) bones.
Make 4 fog fragments.
Make 31 light fragments (just one function, called with different arguments 31 times).

Now you've got 5+4+31 bits of reusable code instead of 5*4*31 bits of specific code.

When you GatherFragments() it takes and compiles each section of code.
You can then pass it your 3 fragment pointers, and say, Link() and get your shader that does exactly what you need. You shader can now depend on context of the game. You don't need to duplicate your lighting system because some meshes have bones. You take the individual sections and stick them together.

You may even be able to use less lighting fragments, and give several repeating fragments. I'm not sure if you can get at the constant data you need if you do this, but it's worth looking into.

This topic is closed to new replies.

Advertisement