View Full Version : Array-shifting (sampling)

05-23-2011, 03:09 AM
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.

05-23-2011, 06:42 AM
While this is not what you want to hear, it is what you need to hear: learn C first, and only after you are comfortable with it, try OpenCL.

Nobody jumps directly from crawling to running. We all had to learn how to walk first.

05-23-2011, 05:31 PM
Ok, fair enough. Perhaps it would be an interesting exercise to actually develop the front-end to it in C++ as a learning project, rather than using C#/Luminal (openCL wrapper).