Results 1 to 3 of 3

Thread: Array-shifting (sampling)

  1. #1
    Junior Member
    Join Date
    May 2011

    Array-shifting (sampling)

    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):

    Code :
    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:
    Code :
    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.

  2. #2
    Senior Member
    Join Date
    May 2010
    Toronto, Canada

    Re: Array-shifting (sampling)

    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.
    Disclaimer: Employee of Qualcomm Canada. Any opinions expressed here are personal and do not necessarily reflect the views of my employer. LinkedIn profile.

  3. #3
    Junior Member
    Join Date
    May 2011

    Re: Array-shifting (sampling)

    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).

Similar Threads

  1. a problem about PCM sampling rate in spec 1.0.1
    By yxyybbs in forum OpenSL ES - embedded audio acceleration
    Replies: 3
    Last Post: 09-08-2011, 08:38 AM
  2. Sampling an alpha texture with texture2D
    By TomCooksey in forum OpenGL ES general technical discussions
    Replies: 4
    Last Post: 04-17-2009, 12:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean