Skip to main content
gamedev.net
🔒 Locked

Directx virtual machine ???

Started by maya18222 4 replies 2.1k views
Original Post
maya18222
maya18222
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.
Quote:
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.
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

// 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;

};



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?
DieterVW
DieterVW
This is the texture shader and is available in effects for DX9.0 only. It uses the same VM as the preshader. See the following post for a bit more information.

http://www.gamedev.net/community/forums/topic.asp?topic_id=536157&whichpage=1�
maya18222
maya18222
So how would you go about doing the same sort of thing in Directx10?
DieterVW
DieterVW
Well, I think you're in luck because the shader you have here should be pretty easy to convert to use a real texture in D3D10. It looks like you can make a single component Texture1D in the runtime and load it with the 256 random values. Then your shader would just have an actual texture get bound.
sirob
sirob
The "Texture Shader" was only ever a convenience thing. It allowed you to fill a texture by writing "HLSL" code instead of filling the texture using your own code.
You could easily generate an array with the same values as this shader generates and create a new texture initialized to the array's values.

[EDIT] also, you could write code to do it once and save the texture to a .dds file, and then load that instead.
Sirob Yes.» - status: Work-O-Rama.
maya18222
maya18222
Thanks,

Yes ive had it working fine for a long time with creating the textures in Cpu code, but it just seemed more convenient to not have to set the noise texture each render frame, and have it set once in shader code.


But its not a problem,

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.