0

What I achieved:

I created a shader (based on this code with this plant asset) that takes a black and white reference image (like a height map) and places plants on a grid determined by the darkness/lightness-value of the respective pixel.

Black and white image to plants

Where I am stuck:

I am trying to get a more organic look (instead of looking like a tileset) so I used poisson-disc-sampling to get random-looking coordinates for where I want to place the plants. In "normal" code I'd just loop through the array of the generated coordinates and draw a sprite ... but I have no clue how to do that with a shader.

Approach using poisson-disc-sampling

Question:

Is it even possible to use a shader to place images at certain positions?
(I could obviously generate a static image but I am planning to adjust the shader to simulate wind going over the vegetation like this)

Thanks already in advance for any tip or help!

st_phan
  • 715
  • 9
  • 23
  • This is not possible *directly*, there might be a way but it would take multiple render passes, and I can't fully imagine it right now. Instead I'm going to suggest to use a particle system. – Theraot Dec 08 '22 at 15:37
  • @Theraot Thanks for your assessment and the recommendation regarding a particle system. Much appreciated! – st_phan Dec 09 '22 at 16:21
  • I'm not sure how you might do it using your poisson disc sampling approach. However, you could generate a random number between 0 and 1 and modify the line `vec2 source_uv = (floor(coord) + 0.5) * cell_scale;` in your shader code to be `vec2 source_uv = (floor(coord) + rand(vec2(TIME, 0.0)) * cell_scale;`. A random function like: ```float rand(vec2 co){ return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); }``` should do it. Obviously, modify it until you get what you want. – HumanWrites Dec 15 '22 at 02:20
  • @HumanWrites Thanks for the idea! As it seems that a shader might not be the correct approach for what I am trying to achieve, I also did some research and maybe "normal" drawing [with proper batching](https://docs.godotengine.org/en/stable/tutorials/performance/batching.html) might do the trick too. Haven't tested it yet, though. – st_phan Dec 18 '22 at 03:52

0 Answers0