Coming from C# background, i’m almost completely unfamiliar with pointers and other unmanaged stuff, which i’m sure what’s tripping me up. I’m doing libnoise type stuff in OpenCL. Simplex was easy, but now I want to do a multi sampled thing including converting a heightmap to a normalmap. Here’s some HLSL that does just that (from a DICE paper):
float3 filterNormal(float2 uv, float texelSize, float texelAspect)
{
float4 h;
h[0] = heightmap.Sample(bilinearSampler, uv + texelSize*float2( 0,-1)).r * texelAspect;
h[1] = heightmap.Sample(bilinearSampler, uv + texelSize*float2(-1, 0)).r * texelAspect;
h[2] = heightmap.Sample(bilinearSampler, uv + texelSize*float2( 1, 0)).r * texelAspect;
h[3] = heightmap.Sample(bilinearSampler, uv + texelSize*float2( 0, 1)).r * texelAspect;
float3 n;
n.z = h[0] - h[3];
n.x = h[1] - h[2];
n.y = 2;
return normalize(n);
}
Here’s what I have for in my .cl:
float4 getNormal(float input, int width, int height, int offset)
{
float destination;
int x = get_global_id(0);
int y = get_global_id(1);
if((x < width) && (y < height))
{
int index = y * width + x;
destination[index] = input[index];
}
return (float4)destination;
}
First, I can’t write to destination because apparently it’s not an array, and second, if I put the asterisk thinger in there (and thus can write to it), I can’t return destination as a non-asterisky float array.