logo80lv
Articlesclick_arrow
Research
Talentsclick_arrow
Events
Workshops
Aboutclick_arrow
profile_loginLogIn

Using RenderTexture Painting Shader

Joyce (MinionsArt) has shared a guide to using the RenderTexture Painting shader the artist shared a while ago.

Joyce (MinionsArt) has shared a guide to using the RenderTexture Painting shader the artist shared a while ago. You can do so many things with the help of this cool thing, so take some to study it. 

Here are the links if you’ve missed something: 

Persistent Damage

Leave persistent damage from laser or other weapons on the environment

Setup:

This is the basic setup from linked code, Raycast to the mouse position when you click, adding the brush texture to the lightmap based RenderTexture result on collision 

Trails

Let the player leave trails with depth in snow/ sand

Setup:

Set up your shader for tesselation, the Unity Manual here shows how to 

Add a vertex function for displacement, using the Paintmap as a texture reference for pushing the vertices

void disp(inout appdata v)
{
float d = tex2Dlod(_PaintMap, float4(v.texcoord1.xy, 0, 0)).r * _Height;
v.vertex.xyz += v.normal *d;
}

Now the untouched parts of the snow/sand are slightly higher, and the paintbrush script will push it down

Map Notes

Letting the Player add notes or draw on a map

Setup:

You dont need the shader for this
Set up a canvas with a raw image, and make a RenderTexture for it

Instead of Raycasting, use the mouse position to paint to the RenderTexture. Get the X and Y coordinates by 

xCoordinate = Mathf.Floor(Input.mousePosition.x – rawImage.rectTransform.position.x);

yCoordinate = Mathf.Floor(Input.mousePosition.y – rawImage.rectTransform.position.y);

DrawTexture(texture, xCoordinate, yCoordinate);

With this you can draw on the RawImage UI component

Player Made Textures

Use the painted RenderTextures as a Texture2D for models

Setup:

Start the same way as the draw map example

To convert the rendertexture to a usable texture, Make a new Texture2D and read the active RenderTexture’s pixels

 Texture2D toTexture2D(RenderTexture rTex)

{
sourceTex = new Texture2D(rTex.width, rTex.height, TextureFormat.RGB24, false);
RenderTexture.active = rTex;
sourceTex.ReadPixels(new Rect(0, 0, rTex.width, rTex.height), 0, 0);
sourceTex.Apply();
RenderTexture.active = null;
return sourceTex;
}

Then assign the result texture to your renderer, and you’ve got a user made custom material!

Joyce (MinionsArt) 

Make sure to follow Joyce on Twitter and support the artist on Patreon if you find his work useful. 

30 hand sculpted veins and burn scars all contained within one Multi-Alpha brush.

Join discussion

Comments 0

    You might also like

    Rumor: Possible Release Date for Grand Theft Auto 6 Revealed

    A video game store from Uruguay appears to have disclosed the launch date for the gaming industry's most anticipated title.

    Breaking: Unity Suddenly Lays Off Numerous Developers With a 5 AM Email

    Apparently, the entire Unity Behavior team was cut, alongside many other employees.

    EXCLUSIVE: Unity CEO's Internal Announcement to Staff Amidst the Layoffs

    80 Level has obtained the text of the email sent by Matthew Bromberg to Unity employees, announcing the layoffs and shedding light on Unity's strategy going forward.
    • Cartoon Water Shader
      by Adam Homoki

      Cartoon Water Shader is an easy to use highly stylized water material, and river tool with many features. Demo scenes also included!

    • Clearcut Series: SD Materials
      by Emiel Sleegers

      In this tutorial, you will be going over on how to create 4 very different materials from scratch in SD. The goal of these courses is to teach you a solid workflow that we also use in the AAA game industry.

    We need your consent

    We use cookies on this website to make your browsing experience better. By using the site you agree to our use of cookies.Learn more

    ×