World Position per instance Grass?

Trying to use a Noise texture to get different color Grass Foliage but can’t figure per instance? …
Screenshot 2023-05-03 175404

Hi espr3ss0,

We might need a bit more information - what are you wanting the per instance for? Using World Position will make that part work globally…

1 Like

Want to make each Grass object different, I was using “Per Instance Random” but found it too specific for each instance so instead using a Noise and want that to be a solid color.

Can you show us your whole blueprint? you should be able to pin the output from the Lerp3Color straight into the BaseColor to test…

The first image I posted is the outcome.

I mean the entire Blueprint - the 2nd image is just a small section of it…

I take it that to get the result you shared the snapshot of, you replaced the 3 yellows with different colors?
Are you wanting just 3 values rather than a graduated outcome?

Yes I used different colors in the instance, it doesn’t matter how many.

You can do something like this to get solid color variation - if you wanted 4 colors, you’d add another “If”, and make the comparisons with .75, .5 and .25 instead of .6 and .3:
If you make your scale large enough, you may get some grass around the edges have multiple colors but you won’t really notice - most will be your single colors.

You can use the “instance world position” parameter in the shader. Calculate the x/y position modulo 5000 and divide by 5000 to get a U/V value in 0…1 range.
Then sample the cyan/green/gray map with that UV coordinate in the shader.
However, if you just do that, then the texture will be sampled at the coarsest MIP level, which smears all the colors together. You’ll need to use a sampler with MIP mapping turned off and/or fix the MIP level in the sampler node in the material to whatever your appropriate level is (something like 10.)

1 Like

Certainly is one way thanks.

Can’t find “Instance World Position”.

Here’s it using Object Position which is what I think jwatte is meaning:


2 Likes

You can also use Absolute World Position or use a vertex interpolator to forward the value as UV. They’re all good methods with slightly different outcomes :slight_smile: Experiment and see what works best.

1 Like

Badically what jwatte suggests.

Your inital texture, when given world position coordinates as UV will outperform any and all math. And the noise node possibly.

Noise cheap is just a 256 texture, so it depends on the size of the texture you use for coloring.

Since the color of the one instance can be derived from the single pixel of the texture its likely cheapr than lerping or iffing.

Note: applying the world UV can paint your instance multi-color.
If thats unwanted you have to take further steps to read the correct pixel for the isntance origin point.

I’m really not sure how to use what you’ve suggested, can you show an example?

Do something like wpo / scalar (set to 2560) and mask RG. Use the output as the UV.
Put the grass in the world and see what it looks like when you change the scalar value of the material instance.

Still not coming out as solid color.

Yes, thats expected.
The texture is being stretched across the whole mesh.
Moving the instance will also show different colors on it.

To sample just one specific pixel you have to do some pretty crazy math.

One technique would be to feed in a texture which references each vert of the texture and its local v3. You can look into Pivot Painter as its essentially this.

Another - far easierl - is to levarage vertex paint to do just the same.

Once you have that data in the model or in the material, it would be sufficient to subtract each vertex (R,G) from wpo to find the “pivot” point.
Once you have that, you can use it as the UV to sample from.

Because all vertex on the mesh are being calculated as the same value, the UV will sample just that one specific pixel / area.
It is a single point, so it should always be a solid color.

Math in the UV is cheaper than a texture sample, but pivot painter would allow for even crazyer things than this if you were to learn the ins and outs.

Alternatively, you could try to game out the math just using the object pivot and WPO. You may want to attempt that prior to delving into setting up scripts to write vertex values.

1 Like