Thanks everyone,
I am starting to get a handle on this, but just haven't got it working yet. I am trying to pass an image into a camera effect as input and output the result to an image. For my test case I am trying to generate a simplified perlin noise on the GPU and return it as an image in DBPro. I think there is something fundamental I don't understand about passing an image in.
The DBPro code is shown below and seems okay. You can see I pass in a random seed and the starting size for the image and I use memblock commands to precompute some random noise in an image which is then passed into the the camera shader as the last parameter of the load camera effect command. This code exports and image but it is entirely black and the same size as the screen:
Function makePerlinWithGPU(seed, startingRes, totalOctaves, sampling)
Randomize Seed
Local color as Dword
//Generate a single noise function at the highest resolution
memblockID = memperlin
if bitmap exist(1) then delete bitmap 1
create bitmap 1, startingres, startingres
make memblock from bitmap memblockID, 1
for x = 0 to startingres-1
for y = 0 to startingres-1
r=rnd(255)
color = rgb(r,r,r)
Write Memblock Dword memblockID, 12+(x + y*startingres)*4, color
next
next
make image from memblock memperlin, memblockID
save image "perlinnoiseIN.bmp", memperlin
//Create camera effect using shader and export to image
make camera 1
if camera effect exist(2) then delete camera effect 2
load camera effect "shaders\perlinnoisePS.fx", 2, memperlin
set camera effect 1, 2, memperlin+1
sync camera 1
remove camera effect 2
delete camera 1
save image "perlinnoiseOUT.bmp", memperlin+1
ENDFUNCTION
The shader I am using is shown below. I suspect the issue is that I don't understand how to specify the image specified in the load camera effect command within the shader. I've tried changing the pixel shader to specify the pixel colour and yet strangely it always exports a black image.
//Generates Perlin Noise
texture inputTexture : RENDERCOLORTARGET
<
string ResourceName = "";
float2 ViewportRatio = { 1.0, 1.0 };
>;
sampler2D inputTextureSample = sampler_state {
Texture = < inputTexture >;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};
struct inputData
{
float4 Position : POSITION;
float2 TextureCoords : TEXCOORD0;
};
struct outputData
{
float4 Position : POSITION;
float2 TextureCoords : TEXCOORD0;
};
//Vertex Shader passes on data to pixel shader
outputData PerlinVS(inputData IN)
{
outputData OUT;
OUT.Position = IN.Position;
OUT.TextureCoords = IN.TextureCoords;
return OUT;
}
//Pixel Shader combines weighted and scaled interpolated (smoothed) versions of texture
float4 PerlinPS(outputData IN, uniform sampler2D srcTex): COLOR
{
float4 perlin = tex2D(srcTex, (IN.TextureCoords))/2;
perlin += tex2D(srcTex, (IN.TextureCoords)*2)/4;
perlin += tex2D(srcTex, (IN.TextureCoords)*4)/8;
perlin += tex2D(srcTex, (IN.TextureCoords)*8)/16;
perlin += tex2D(srcTex, (IN.TextureCoords)*16)/32;
perlin += tex2D(srcTex, (IN.TextureCoords)*32)/32;
return perlin;
}
technique PerlinNoise
<
//specify the starting image where the original scene will be drawn
string RenderColorTarget = "inputTexture";
>
{
//Out texture creatured by pass
pass Pass0 <
//blank target indicates this is the final pass and should be drawn to the final results image
string RenderColorTarget = "";
>
{
// Setup render states
ZWriteEnable = FALSE;
ZEnable = FALSE;
AlphaBlendEnable = FALSE;
VertexShader = compile vs_2_0 PerlinVS();
PixelShader = compile ps_2_0 PerlinPS( inputTextureSample );
}
}
Any suggestions are welcome.
GrumpyOne - the natural state of the programmer