Simple kernel.cu 822 B

1234567891011121314151617181920212223242526
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //! Simple kernel to modify vertex positions in sine wave pattern
  3. //! @param data data in global memory'
  4. ////////////////////////////////////////////////////////////////////////////////
  5. __global__ void kernel(
  6. float4* pos,
  7. unsigned int width,
  8. unsigned int height,
  9. float time)
  10. {
  11. unsigned int x = blockIdx.x*blockDim.x + threadIdx.x;
  12. unsigned int y = blockIdx.y*blockDim.y + threadIdx.y;
  13. // calculate uv coordinates
  14. float u = x / (float) width;
  15. float v = y / (float) height;
  16. u = u*2.0f - 1.0f;
  17. v = v*2.0f - 1.0f;
  18. // calculate simple sine wave pattern
  19. float freq = 4.0f;
  20. float w = sinf(u*freq + time) * cosf(v*freq + time) * 0.5f;
  21. // write output vertex
  22. pos[y*width+x] = make_float4(u, w, v, 1.0f);
  23. }