Image Input Projection
This is an example of a kernel which uses an image input to project onto the particle system, coloring particles according to their position. The image is assumed to lie on the XZ plane and two knobs are provided to set the top-left and bottom-right corners of the image in that plane.
|
|
kernel ParticleImageProjectKernel : ImageComputationKernel<ePixelWise> { Image<eRead,eAccessRandom,eEdgeClamped> image_texture; Image<eReadWrite> p_position; Image<eReadWrite> p_color; param: float _amount; float _dt; float2 _imageTL; float2 _imageBR; local: float2 _imageSize; void define() { defineParam(_imageTL, "pa_imageTL", float2(0.0f)); defineParam(_imageBR, "pa_imageBR", float2(1.0f)); defineParam(_dt, "_dt", 1.0f); } void init() { _imageSize = float2(image_texture.bounds.width(), image_texture.bounds.height()); } void process() { float3 p = p_position(); float2 xz = float2(p.x, p.z); float2 uv = xz = (xz-_imageTL)/(_imageBR-_imageTL); float2 st = uv*_imageSize; float4 c = bilinear(image_texture, st.x, st.y); p_color() = float4(c.x, c.y, c.z, 1.0f); } }; |