Original Post
Hello, Ive been reading the following Gpu Gems 2 Articles on Perlin Noise, in which the author mentions using the Directx Virtual Machine to procedurally create texures. How exactly is this working, does it just get called once, when the shader is first compiled? Other than not being to change the texture on the fly, does it have any other drawbacks? What else cant the Virtual Machine do?
Quote:Does anybody know what he means by this? Ive been googling and cant find any documentation or tutorials on it. In the shader code he has the following
One of the most useful features of the Microsoft Direct 3D Effects and CgFX runtimes is a virtual machine that can be used to procedurally generate textures from functions. We use this feature to build the permutation and gradient textures from the same data given in the reference implementation. If you are using another shading language, such as the OpenGL Shading Language, it should be trivial to include this code in your application instead.
// permutation table
static int permutation[] = {
151, /* 254 values elided . . . */, 180
};
// Generate permutation and gradient textures using CPU runtime
texture permTexture
<
string texturetype = "2D";
string format = "l8";
string function = "GeneratePermTexture";
int width = 256, height = 1;
>;
float4 GeneratePermTexture(float p : POSITION) : COLOR
{
return permutation[p * 256] / 255.0;
}
sampler permSampler = sampler_state
{
texture = <permTexture>;
AddressU = Wrap;
AddressV = Clamp;
MAGFILTER = POINT;
MINFILTER = POINT;
MIPFILTER = NONE;
};