Compile shader fragments offline

Started by
4 comments, last by bjone 17 years, 5 months ago
Hello, I would like to compile a bunch of shader fragments offline (written in HLSL), to store it in a binary format (for obfuscation & performance purposes). like you could compile an effect or (vertex/pixel) shader with the fxc/psa/vsa tools.... I tried a lot of different synthaxes with FragmentLinker.fx (from the SDK), but I failed. (I tried to use the shader fragment name or the function name as entry point but it keeps saying "no no") What I am doing wrong ?
Advertisement
I would recommend you post more details, including, perhaps, a small reproduction case of what you're trying to attempt.
Unfortunately, the D3DX fragment linker is pretty defunct. It has been pretty much abandoned in past years. Considering that it usually struggles to work correctly with normal usage, I bet it's not going to be too cooperative with what you want [wink]

You can try writing your own fragment linker (it's really not hard - and you can make a much more specialized and useful version for yourself) with this offline compilation in mind. If you don't want to do that, you could always just try encrypting your files (for the obfuscation part).
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
What I want is simple: I don't want to have my shader fragments in HLSL format in my games ressources files, but in pcode (d3d asm) format.

Like you could compile a full ID3DXEffect with fxc.exe, I just want to have my shader fragments in binary formats (for release).

Encrypting HLSL code in the games's ressources could be practicable, but since you only have to trap D3DX calls to grab the HLSL code, means 0 obfuscation. But it's not the first motivation.

My approach is since you can do an offline compilation of ID3DXEffect using HLSL shaders, I was supposing that offering the same possiblities for shader fragments was natural.

But if you can't offline compile shader fragments and load them at runtime in their binary format :/
Quote:Original post by bjone
But if you can't offline compile shader fragments and load them at runtime in their binary format :/

Yea, unfortunately, it doesn't seem to be possible. What you could do is write your own fragment linker, generate all possible permutations of your shaders as a pre-process step, compile all of them, and then load them at run-time as necessary.

I suppose you could also use the Fragment-Linker itself to do this, since it gives you back a pixel or vertex shader interface, which you can then use to get the linked code (IDirect3D[Pixel|Vertex]Shader::GetFunction()). Grab that code, save it to a file, and then re-load it at runtime.
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
Ok, so I will code a Uber-shader with a lot of uniforms, and design my own shader-bank system.

This topic is closed to new replies.

Advertisement