GameCrew AIEarly access
Sign in
Unity 6materialsRevision 1 · Compile-verified pattern

AAA Photo-to-Foliage Pack: Solid Geometry, Shared Atlas, 3-LOD & Transmission in Unity 6 URP

Updated

Turn plant photos or concept references into a reusable Unity 6 URP hand-painted foliage pack with zero alpha-cutout cards: 18-triangle solid grass blades, 500/250/100-triangle 3-LOD flowers, baked vertex-color wind masks, a shared texture atlas, normal maps, and backlit subsurface transmission.

  • foliage
  • grass
  • flowers
  • atlas
  • lod
  • transmission
  • sss
  • wind-mask
  • normal-map
  • vertex-color
  • terrain
  • urp

No demo.

When to Use (and When Not To)

Use this recipe whenever a game needs lush, hand-painted or stylized grass, wildflowers, ferns, or meadow clusters that hold up both up close and across wide terrain without the overdraw and harsh edges of alpha-tested billboard cards:

  • Solid geometry, zero see-through cards: Every grass blade (18 triangles) and flower petal has real 3D thickness. That eliminates WebGL 2 / mobile alpha-clip overdraw, ugly silhouette popping, and flat side-on collapse.
  • Three explicit LODs per species: Hero wildflowers sit around ~500 triangles at LOD0 (close-up), ~250 triangles at LOD1 (mid-range), and ~100 triangles at LOD2 (distance), managed cleanly via LODGroup or distance-tiered Graphics.RenderMeshInstanced batches.
  • One shared texture atlas across species: Packing grass, tulips, daffodils, and clover into a single albedo + normal + transmission atlas sheet lets an entire meadow render through one URP material (1–4 draw calls instead of dozens).
  • Backlit transmission + normal detail + vertex-color wind masks: Sunlight glows realistically through thin petals and leaf blades while roots stay locked to terrain and tips flutter independently.

Skip volumetric per-blade geometry for distant background forests past 80 m — switch to simplified canopy meshes or distant terrain color tinting there.

Repeatable Photo-to-Foliage Asset Pipeline

Follow this 5-step loop to turn a single plant photo or concept study into a reusable Unity 6 URP foliage pack:

  1. Reference & Ground Textures (1K): Generate a 1K botanical reference study (make_concept_art) and a 1K seamless soil/meadow ground texture (make_texture) so grass roots match the underlying terrain palette.
  2. Low-Poly Plant Parts (Geometry-First): Generate clean low-poly 3D plant parts with make_model (style: "low_poly", untextured mode when repacking into a hand-painted shared atlas) for complex botanical silhouettes such as seed heads, tulip cups, or sunflower disks.
  3. Mesh Cleanup, Atlas Packing, Wind Masks & 3-LOD Export (foliage-atlas): Run the studio's foliage-atlas mesh-processing stage (--lods 500,250,100 --atlas-size 1024 --height 0.45 --pad 4) to normalize base pivots to the origin, bake RGBA vertex-color wind masks (Col), pack multiple plant species into one shared power-of-two atlas (atlas_albedo.png, atlas_normal.png, atlas_transmission.png) with edge-clamped mipmap gutters, remap every species' UVs into its padded atlas cell, and export triangle-budgeted LOD0 / LOD1 / LOD2 FBX meshes plus atlas_manifest.json.
  1. Shared URP Material (Custom/FoliageAtlasTransmission): Bind the packed atlas_albedo, atlas_normal (marked Normal Map), and atlas_transmission (linear grayscale) textures to one instanced URP material.
  2. Scene Placement / Terrain Painting: Register the 3-LOD prefabs on a Unity Terrain (DetailPrototype / TreePrototype) or batch them with Graphics.RenderMeshInstanced per LOD ring for maximum WebGL 2 throughput.

Mathematical & Shading Model

Vertex-Color Wind Mask Packing (COLOR RGBA)

| Channel | Meaning | Formula | |---|---|---| | R | Primary root-to-tip bend weight | h^2 = saturate(y / H)^2 (0 pinned at soil, 1 at tip) | | G | Petal & leaf edge micro-flutter | saturate(r_radial / R_max) · √h | | B | Per-species / per-clump phase offset | Deterministic hash in $[0, 1]$ so neighbors never sway in lockstep | | A | Stem stiffness / root AO floor | 0.25 at root (darkened contact AO) → 1.0 at open petals |

Arc-Preserving Wind + Backlit Subsurface Transmission

For world-space gust phase φ = w·p_xz - ω t + 6.283\,color.b:

  • Macro sway + edge flutter: $Δ x = d_wind · (gust(φ) · A_gust · color.r) + d_perp · (sin(3.7 t + φ) · A_flutter · color.g)$
  • Length-preserving arc droop: Δ y = -0.32\,\|Δ x\| so blades bend in an arc instead of stretching taller.
  • Fast backlit translucency (Barré-Brisebois & Bouchard): $H_back = normalize(L + N · δ), I_sss = saturate(-V·H_back)^p · M_trans(u, v)$ Added on top of wrapped diffuse lighting so petals and thin blades light up warmly when the sun sits behind them.

Engine Implementation

1. URP Foliage Atlas, Wind-Mask & Backlit Transmission Shader (Assets/Game/Resources/Shaders/FoliageAtlasTransmission.shader)

Shader "Custom/FoliageAtlasTransmission"
{
    Properties
    {
        _BaseMap ("Shared Foliage Atlas (Albedo)", 2D) = "white" {}
        _BaseColor ("Global Tint", Color) = (1.0, 1.0, 1.0, 1.0)
        [Normal] _BumpMap ("Shared Normal Atlas", 2D) = "bump" {}
        _BumpScale ("Normal Strength", Range(0.0, 2.0)) = 0.85
        _TransmissionMap ("Shared Transmission Mask (R)", 2D) = "white" {}
        _TransmissionColor ("Backlit Transmission Tint", Color) = (0.95, 0.92, 0.42, 1.0)
        _TransmissionStrength ("Transmission Strength", Range(0.0, 2.5)) = 0.85
        _TransmissionPower ("Transmission Focus", Range(1.0, 8.0)) = 3.2
        _TransmissionDistortion ("Normal Distortion", Range(0.0, 1.0)) = 0.35
        _WindParams ("DirX, DirZ, Strength, Speed", Vector) = (0.85, 0.52, 0.24, 2.2)
        _FlutterStrength ("Edge Flutter Strength", Range(0.0, 0.15)) = 0.045
        _InteractorPos ("Player Feet XYZ, Radius W", Vector) = (0.0, -999.0, 0.0, 1.35)
    }

    SubShader
    {
        Tags { "RenderPipeline" = "UniversalPipeline" "RenderType" = "Opaque" "Queue" = "Geometry" }

        Pass
        {
            Name "FoliageAtlasForward"
            Tags { "LightMode" = "UniversalForward" }
            Cull Back
            ZWrite On

            HLSLPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #pragma multi_compile_instancing
            #pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE
            #pragma multi_compile_fog

            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"

            TEXTURE2D(_BaseMap);         SAMPLER(sampler_BaseMap);
            TEXTURE2D(_BumpMap);         SAMPLER(sampler_BumpMap);
            TEXTURE2D(_TransmissionMap); SAMPLER(sampler_TransmissionMap);

            CBUFFER_START(UnityPerMaterial)
                float4 _BaseMap_ST;
                half4 _BaseColor;
                half _BumpScale;
                half4 _TransmissionColor;
                half _TransmissionStrength;
                half _TransmissionPower;
                half _TransmissionDistortion;
                float4 _WindParams;
                float _FlutterStrength;
                float4 _InteractorPos;
            CBUFFER_END

            struct Attributes
            {
                float4 positionOS : POSITION;
                float3 normalOS   : NORMAL;
                float4 tangentOS  : TANGENT;
                float2 uv         : TEXCOORD0;
                float4 color      : COLOR;
                UNITY_VERTEX_INPUT_INSTANCE_ID
            };

            struct Varyings
            {
                float4 positionCS : SV_POSITION;
                float2 uv         : TEXCOORD0;
                float3 positionWS : TEXCOORD1;
                float3 normalWS   : TEXCOORD2;
                float4 tangentWS  : TEXCOORD3;
                float4 color      : TEXCOORD4;
                float  fogFactor  : TEXCOORD5;
                UNITY_VERTEX_INPUT_INSTANCE_ID
            };

            float3 ApplyFoliageWind(float3 positionOS, float4 windMask)
            {
                float3 rootWS = TransformObjectToWorld(float3(0.0, 0.0, 0.0));
                float3 posWS  = TransformObjectToWorld(positionOS);

                float t = _Time.y * _WindParams.w;
                float phase = windMask.b * 6.2831853;
                float gust = sin(dot(rootWS.xz, float2(0.24, 0.17)) - t + phase) * 0.65
                           + sin(dot(rootWS.xz, float2(0.63, -0.45)) - t * 1.8 + phase * 1.7) * 0.35;

                float2 windDir = normalize(_WindParams.xy + float2(1e-4, 0.0));
                float2 perpDir = float2(-windDir.y, windDir.x);

                float bend = windMask.r;
                float flutter = windMask.g * sin(t * 3.6 + phase + dot(posWS.xz, float2(2.7, 3.1)));
                float2 sway = windDir * ((gust * 0.5 + 0.5) * _WindParams.z * bend)
                            + perpDir * (flutter * _FlutterStrength);

                float3 toPlant = posWS - _InteractorPos.xyz;
                float dist = length(toPlant);
                float radius = max(0.1, _InteractorPos.w);
                if (dist < radius)
                {
                    float push = 1.0 - dist / radius;
                    float2 pushDir = normalize(toPlant.xz + float2(1e-4, 1e-4));
                    sway += pushDir * (push * push * 0.55 * bend);
                }

                posWS.xz += sway;
                posWS.y  -= length(sway) * 0.32;
                return posWS;
            }

            Varyings vert(Attributes input)
            {
                Varyings o;
                UNITY_SETUP_INSTANCE_ID(input);
                UNITY_TRANSFER_INSTANCE_ID(input, o);

                float3 posWS = ApplyFoliageWind(input.positionOS.xyz, input.color);
                VertexNormalInputs nrm = GetVertexNormalInputs(input.normalOS, input.tangentOS);

                o.positionWS = posWS;
                o.positionCS = TransformWorldToHClip(posWS);
                o.uv         = TRANSFORM_TEX(input.uv, _BaseMap);
                o.normalWS   = nrm.normalWS;
                o.tangentWS  = float4(nrm.tangentWS, input.tangentOS.w);
                o.color      = input.color;
                o.fogFactor  = ComputeFogFactor(o.positionCS.z);
                return o;
            }

            half4 frag(Varyings input) : SV_Target
            {
                UNITY_SETUP_INSTANCE_ID(input);

                half3 albedo = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, input.uv).rgb * _BaseColor.rgb;
                half3 normalTS = UnpackNormalScale(SAMPLE_TEXTURE2D(_BumpMap, sampler_BumpMap, input.uv), _BumpScale);
                half transMask = SAMPLE_TEXTURE2D(_TransmissionMap, sampler_TransmissionMap, input.uv).r;

                float3 nWS = normalize(input.normalWS);
                float3 tWS = normalize(input.tangentWS.xyz);
                float3 bWS = normalize(cross(nWS, tWS) * input.tangentWS.w);
                float3 normalWS = normalize(tWS * normalTS.x + bWS * normalTS.y + nWS * normalTS.z);

                float4 shadowCoord = TransformWorldToShadowCoord(input.positionWS);
                Light mainLight = GetMainLight(shadowCoord);
                float3 viewWS = normalize(GetWorldSpaceViewDir(input.positionWS));

                // Soft wrapped diffuse + root AO encoded in vertex color alpha
                half ndotl = saturate((dot(normalWS, mainLight.direction) + 0.35h) / 1.35h);
                half rootAo = lerp(0.58h, 1.0h, saturate(input.color.a));
                half shadow = lerp(0.45h, 1.0h, mainLight.shadowAttenuation);

                // Backlit subsurface transmission through petals and blades
                float3 backDir = normalize(mainLight.direction + normalWS * _TransmissionDistortion);
                half backScatter = pow(saturate(dot(-viewWS, backDir)), _TransmissionPower);
                half3 transmission = backScatter * transMask * _TransmissionStrength * _TransmissionColor.rgb * albedo * mainLight.color;

                half3 ambient = SampleSH(normalWS) * albedo * rootAo;
                half3 direct  = albedo * mainLight.color * (ndotl * shadow * rootAo);
                half3 color   = MixFog(ambient + direct + transmission, input.fogFactor);
                return half4(color, 1.0h);
            }
            ENDHLSL
        }

        Pass
        {
            Name "ShadowCaster"
            Tags { "LightMode" = "ShadowCaster" }
            ZWrite On
            ZTest LEqual
            ColorMask 0
            Cull Back

            HLSLPROGRAM
            #pragma vertex ShadowVert
            #pragma fragment ShadowFrag
            #pragma multi_compile_instancing

            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"

            CBUFFER_START(UnityPerMaterial)
                float4 _BaseMap_ST;
                half4 _BaseColor;
                half _BumpScale;
                half4 _TransmissionColor;
                half _TransmissionStrength;
                half _TransmissionPower;
                half _TransmissionDistortion;
                float4 _WindParams;
                float _FlutterStrength;
                float4 _InteractorPos;
            CBUFFER_END

            struct Attributes
            {
                float4 positionOS : POSITION;
                float3 normalOS   : NORMAL;
                float4 color      : COLOR;
                UNITY_VERTEX_INPUT_INSTANCE_ID
            };

            struct Varyings
            {
                float4 positionCS : SV_POSITION;
                UNITY_VERTEX_INPUT_INSTANCE_ID
            };

            Varyings ShadowVert(Attributes input)
            {
                Varyings o;
                UNITY_SETUP_INSTANCE_ID(input);
                UNITY_TRANSFER_INSTANCE_ID(input, o);
                float3 posWS = TransformObjectToWorld(input.positionOS.xyz);
                float3 normalWS = TransformObjectToWorldNormal(input.normalOS);
                o.positionCS = TransformWorldToHClip(ApplyShadowBias(posWS, normalWS, float3(0, 1, 0)));
                return o;
            }

            half4 ShadowFrag(Varyings input) : SV_Target { return 0; }
            ENDHLSL
        }
    }
}

2. Solid 18-Tri Grass, 3-LOD 500/250/100-Tri Flowers & Shared Atlas Builder (Assets/Game/Runtime/Rendering/FoliageAtlasPack.cs)

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;

namespace Game.Rendering
{
    /// <summary>
    /// Builds solid-geometry foliage assets (zero alpha-cutout cards) matching AAA budgets:
    /// - 18-triangle volumetric grass blades (triangular cross-section with real thickness)
    /// - 3-LOD wildflowers: LOD0 (~480 tris), LOD1 (~242 tris), LOD2 (100 tris)
    /// - Shared 2x2 texture atlas (Albedo, Tangent Normal, Transmission Mask) + RGBA vertex-color wind masks.
    /// </summary>
    public static class FoliageAtlasPack
    {
        public struct AtlasTextures
        {
            public Texture2D Albedo;
            public Texture2D Normal;
            public Texture2D Transmission;
        }

        // 2x2 shared atlas tile UV bounds (with 3% inset padding to prevent mipmap bleed)
        public static Rect TileRect(int tileIndex)
        {
            const float pad = 0.03f;
            float ox = (tileIndex % 2) * 0.5f;
            float oy = (tileIndex / 2) * 0.5f;
            return new Rect(ox + pad, oy + pad, 0.5f - pad * 2f, 0.5f - pad * 2f);
        }

        /// <summary>Exact 18-triangle solid curved grass blade (4 rings x 3-vert triangular ridge, zero transparent cards).</summary>
        public static Mesh BuildSolidGrassBladeMesh(float width = 0.08f, float height = 0.72f, float phase = 0.25f)
        {
            Rect tile = TileRect(0);
            var verts = new Vector3[12];
            var uvs   = new Vector2[12];
            var cols  = new Color[12];

            float[] hs = { 0f, 0.34f, 0.68f, 1.0f };
            float[] ws = { 1.0f, 0.72f, 0.38f, 0.06f };
            float[] ts = { 0.018f, 0.013f, 0.008f, 0.002f };

            for (int r = 0; r < 4; r++)
            {
                float h = hs[r];
                float hw = width * 0.5f * ws[r];
                float bendZ = h * h * height * 0.24f;
                float y = h * height;
                float thick = ts[r];
                Color c = new Color(h * h, h * 0.6f, phase, Mathf.Lerp(0.28f, 1.0f, h));

                int b = r * 3;
                // Counter-clockwise in XZ so triangle normals face strictly outward under Cull Back
                verts[b + 0] = new Vector3(-hw, y, bendZ);
                verts[b + 1] = new Vector3(0f,  y, bendZ - thick);
                verts[b + 2] = new Vector3( hw, y, bendZ);

                float v = Mathf.Lerp(tile.yMin, tile.yMax, h);
                uvs[b + 0] = new Vector2(tile.xMin, v);
                uvs[b + 1] = new Vector2(tile.center.x, v);
                uvs[b + 2] = new Vector2(tile.xMax, v);
                cols[b + 0] = cols[b + 1] = cols[b + 2] = c;
            }

            var tris = new int[54]; // 3 segments x 3 sides x 2 tris = 18 triangles
            int ti = 0;
            for (int s = 0; s < 3; s++)
            {
                int a = s * 3;
                int b = (s + 1) * 3;
                for (int k = 0; k < 3; k++)
                {
                    int kn = (k + 1) % 3;
                    tris[ti++] = a + k;  tris[ti++] = b + k;  tris[ti++] = a + kn;
                    tris[ti++] = a + kn; tris[ti++] = b + k;  tris[ti++] = b + kn;
                }
            }

            var mesh = new Mesh { name = "SolidGrassBlade_18Tri" };
            mesh.vertices = verts;
            mesh.uv = uvs;
            mesh.colors = cols;
            mesh.triangles = tris;
            mesh.RecalculateNormals();
            mesh.RecalculateTangents();
            mesh.RecalculateBounds();
            return mesh;
        }

        /// <summary>
        /// Builds a 3-LOD volumetric wildflower mapped into a shared atlas tile:
        /// LOD0 = 480 tris (~500), LOD1 = 242 tris (~250), LOD2 = 100 tris.
        /// </summary>
        public static Mesh BuildFlowerLodMesh(int lodIndex, int atlasTile = 1, float height = 0.56f, float phase = 0.5f)
        {
            lodIndex = Mathf.Clamp(lodIndex, 0, 2);
            Rect stemTile  = TileRect(0);
            Rect petalTile = TileRect(atlasTile);

            var verts = new List<Vector3>(512);
            var uvs   = new List<Vector2>(512);
            var cols  = new List<Color>(512);
            var tris  = new List<int>(1600);

            int stemSides = lodIndex == 0 ? 6 : (lodIndex == 1 ? 5 : 4);
            int stemSegs  = lodIndex == 0 ? 4 : (lodIndex == 1 ? 3 : 2);
            AddTube(verts, uvs, cols, tris, stemSides, stemSegs, 0.022f, 0.014f, height * 0.78f, stemTile, phase);

            // Two solid curving basal leaves
            int leafSegs = lodIndex == 0 ? 4 : (lodIndex == 1 ? 2 : 1);
            AddLeaf(verts, uvs, cols, tris, leafSegs, -1f, height * 0.52f, stemTile, phase);
            AddLeaf(verts, uvs, cols, tris, leafSegs,  1f, height * 0.46f, stemTile, phase);

            // Six cupped solid petals (lenticular cross-section with real thickness)
            int pSegs  = lodIndex == 0 ? 4 : (lodIndex == 1 ? 3 : 1);
            int pSides = lodIndex == 0 ? 6 : 4;
            for (int p = 0; p < 6; p++)
            {
                float yaw = p * (Mathf.PI * 2f / 6f) + (p % 2) * 0.12f;
                AddSolidPetal(verts, uvs, cols, tris, pSides, pSegs, yaw, height * 0.74f, height * 0.28f, petalTile, phase);
            }

            // Stamen + calyx detail on LOD0 / LOD1
            if (lodIndex == 0)
            {
                AddCup(verts, uvs, cols, tris, 6, 3, height * 0.77f, 0.045f, 0.075f, petalTile, phase, 0.92f);
                AddCup(verts, uvs, cols, tris, 6, 2, height * 0.70f, 0.036f, 0.055f, stemTile, phase, 0.75f);
            }
            else if (lodIndex == 1)
            {
                AddCup(verts, uvs, cols, tris, 5, 2, height * 0.76f, 0.042f, 0.065f, petalTile, phase, 0.9f);
            }

            var mesh = new Mesh { name = $"Flower_Tile{atlasTile}_LOD{lodIndex}" };
            mesh.SetVertices(verts);
            mesh.SetUVs(0, uvs);
            mesh.SetColors(cols);
            mesh.SetTriangles(tris, 0);
            mesh.RecalculateNormals();
            mesh.RecalculateTangents();
            mesh.RecalculateBounds();
            return mesh;
        }

        public static GameObject CreateLodFlower(string name, Material sharedAtlasMat, int atlasTile, float height, float phase)
        {
            var root = new GameObject(name);
            var group = root.AddComponent<LODGroup>();
            var lods = new LOD[3];
            float[] heights = { 0.42f, 0.16f, 0.02f };
            for (int i = 0; i < 3; i++)
            {
                var child = new GameObject($"{name}_LOD{i}");
                child.transform.SetParent(root.transform, false);
                child.AddComponent<MeshFilter>().sharedMesh = BuildFlowerLodMesh(i, atlasTile, height, phase);
                var mr = child.AddComponent<MeshRenderer>();
                mr.sharedMaterial = sharedAtlasMat;
                mr.shadowCastingMode = i == 0 ? ShadowCastingMode.On : ShadowCastingMode.Off;
                lods[i] = new LOD(heights[i], new Renderer[] { mr });
            }
            group.SetLODs(lods);
            group.RecalculateBounds();
            return root;
        }

        public static AtlasTextures BuildSharedAtlasTextures(int size = 512)
        {
            var albedo = new Texture2D(size, size, TextureFormat.RGBA32, true, false) { name = "FoliageAtlas_Albedo", wrapMode = TextureWrapMode.Clamp };
            var normal = new Texture2D(size, size, TextureFormat.RGBA32, true, true)  { name = "FoliageAtlas_Normal", wrapMode = TextureWrapMode.Clamp };
            var trans  = new Texture2D(size, size, TextureFormat.RGBA32, true, true)  { name = "FoliageAtlas_Transmission", wrapMode = TextureWrapMode.Clamp };

            var albedoPx = new Color32[size * size];
            var normalPx = new Color32[size * size];
            var transPx  = new Color32[size * size];
            int half = size / 2;

            for (int y = 0; y < size; y++)
            {
                for (int x = 0; x < size; x++)
                {
                    int tile = (x >= half ? 1 : 0) + (y >= half ? 2 : 0);
                    float u = (x % half) / (float)half;
                    float v = (y % half) / (float)half;

                    // Hand-painted brushstroke striations & botanical vein relief
                    float vein = Mathf.Sin((u - 0.5f) * 28f) * 0.5f + 0.5f;
                    float stroke = Mathf.Sin(v * 22f + u * 5f) * 0.04f;
                    Color baseCol;
                    float transVal;
                    if (tile == 0)
                    {
                        baseCol = Color.Lerp(new Color(0.16f, 0.36f, 0.14f), new Color(0.48f, 0.78f, 0.26f), v);
                        transVal = Mathf.Lerp(0.15f, 0.85f, v * v);
                    }
                    else if (tile == 1)
                    {
                        baseCol = Color.Lerp(new Color(0.84f, 0.22f, 0.18f), new Color(1.0f, 0.66f, 0.22f), v);
                        transVal = Mathf.Lerp(0.35f, 0.98f, v);
                    }
                    else if (tile == 2)
                    {
                        baseCol = Color.Lerp(new Color(0.95f, 0.72f, 0.12f), new Color(1.0f, 0.96f, 0.62f), v);
                        transVal = Mathf.Lerp(0.40f, 0.95f, v);
                    }
                    else
                    {
                        baseCol = Color.Lerp(new Color(0.40f, 0.30f, 0.76f), new Color(0.76f, 0.68f, 0.98f), v);
                        transVal = Mathf.Lerp(0.30f, 0.90f, v);
                    }

                    baseCol.r = Mathf.Clamp01(baseCol.r + stroke + (vein - 0.5f) * 0.05f);
                    baseCol.g = Mathf.Clamp01(baseCol.g + stroke + (vein - 0.5f) * 0.05f);
                    baseCol.b = Mathf.Clamp01(baseCol.b + stroke);

                    float nx = Mathf.Cos((u - 0.5f) * 28f) * 0.22f;
                    float ny = (v - 0.5f) * 0.08f;
                    Vector3 n = new Vector3(nx, ny, 1f).normalized;

                    int idx = y * size + x;
                    albedoPx[idx] = baseCol;
                    normalPx[idx] = new Color(n.x * 0.5f + 0.5f, n.y * 0.5f + 0.5f, n.z * 0.5f + 0.5f, 1f);
                    transPx[idx] = new Color(transVal, transVal, transVal, 1f);
                }
            }

            albedo.SetPixels32(albedoPx); albedo.Apply(true, false);
            normal.SetPixels32(normalPx); normal.Apply(true, false);
            trans.SetPixels32(transPx);  trans.Apply(true, false);
            return new AtlasTextures { Albedo = albedo, Normal = normal, Transmission = trans };
        }

        static void AddTube(List<Vector3> verts, List<Vector2> uvs, List<Color> cols, List<int> tris,
            int sides, int segs, float r0, float r1, float h, Rect tile, float phase)
        {
            int start = verts.Count;
            for (int r = 0; r <= segs; r++)
            {
                float t = r / (float)segs;
                float rad = Mathf.Lerp(r0, r1, t);
                float swayX = Mathf.Sin(t * 2.1f + phase * 6f) * 0.025f * t;
                for (int s = 0; s < sides; s++)
                {
                    float a = s * (Mathf.PI * 2f / sides);
                    verts.Add(new Vector3(Mathf.Cos(a) * rad + swayX, t * h, Mathf.Sin(a) * rad));
                    uvs.Add(new Vector2(Mathf.Lerp(tile.xMin, tile.xMax, s / (float)sides), Mathf.Lerp(tile.yMin, tile.yMax, t)));
                    cols.Add(new Color(t * t * 0.7f, 0f, phase, Mathf.Lerp(0.3f, 0.9f, t)));
                }
            }
            for (int r = 0; r < segs; r++)
            {
                int a = start + r * sides;
                int b = start + (r + 1) * sides;
                for (int s = 0; s < sides; s++)
                {
                    int sn = (s + 1) % sides;
                    tris.Add(a + s);  tris.Add(b + s);  tris.Add(a + sn);
                    tris.Add(a + sn); tris.Add(b + s);  tris.Add(b + sn);
                }
            }
        }

        static void AddLeaf(List<Vector3> verts, List<Vector2> uvs, List<Color> cols, List<int> tris,
            int segs, float sideSign, float len, Rect tile, float phase)
        {
            int start = verts.Count;
            for (int r = 0; r <= segs; r++)
            {
                float t = r / (float)segs;
                float hw = 0.042f * (1f - t * 0.85f);
                float outX = sideSign * (0.02f + t * len * 0.55f);
                float y = 0.02f + t * len * 0.72f - t * t * len * 0.22f;
                Color c = new Color(t * t * 0.85f, t * 0.55f, phase, Mathf.Lerp(0.35f, 1.0f, t));
                float z0 = sideSign >= 0f ? -hw :  hw;
                float z1 = sideSign >= 0f ?  hw : -hw;
                verts.Add(new Vector3(outX, y, z0));
                verts.Add(new Vector3(outX, y, z1));
                verts.Add(new Vector3(outX - sideSign * 0.01f, y - 0.008f, 0f));
                float v = Mathf.Lerp(tile.yMin, tile.yMax, t);
                uvs.Add(new Vector2(tile.xMin, v));
                uvs.Add(new Vector2(tile.xMax, v));
                uvs.Add(new Vector2(tile.center.x, v));
                cols.Add(c); cols.Add(c); cols.Add(c);
            }
            for (int r = 0; r < segs; r++)
            {
                int a = start + r * 3;
                int b = start + (r + 1) * 3;
                for (int s = 0; s < 3; s++)
                {
                    int sn = (s + 1) % 3;
                    tris.Add(a + s);  tris.Add(b + s);  tris.Add(a + sn);
                    tris.Add(a + sn); tris.Add(b + s);  tris.Add(b + sn);
                }
            }
        }

        static void AddSolidPetal(List<Vector3> verts, List<Vector2> uvs, List<Color> cols, List<int> tris,
            int sides, int segs, float yaw, float baseY, float len, Rect tile, float phase)
        {
            int start = verts.Count;
            Quaternion rot = Quaternion.Euler(0f, yaw * Mathf.Rad2Deg, 0f);
            for (int r = 0; r <= segs; r++)
            {
                float t = r / (float)segs;
                float widthProfile = Mathf.Sin(t * Mathf.PI * 0.88f + 0.18f) * 0.068f;
                float thick = Mathf.Lerp(0.012f, 0.004f, t);
                float flare = 0.025f + Mathf.Pow(t, 0.85f) * 0.115f;
                float y = baseY + t * len;
                Color c = new Color(Mathf.Lerp(0.75f, 1.0f, t), Mathf.Lerp(0.25f, 1.0f, t), phase, 1.0f);
                for (int s = 0; s < sides; s++)
                {
                    float a = s * (Mathf.PI * 2f / sides);
                    Vector3 local = new Vector3(Mathf.Cos(a) * widthProfile, y, flare + Mathf.Sin(a) * thick);
                    verts.Add(rot * local);
                    uvs.Add(new Vector2(Mathf.Lerp(tile.xMin, tile.xMax, Mathf.Cos(a) * 0.5f + 0.5f), Mathf.Lerp(tile.yMin, tile.yMax, t)));
                    cols.Add(c);
                }
            }
            for (int r = 0; r < segs; r++)
            {
                int a = start + r * sides;
                int b = start + (r + 1) * sides;
                for (int s = 0; s < sides; s++)
                {
                    int sn = (s + 1) % sides;
                    tris.Add(a + s);  tris.Add(b + s);  tris.Add(a + sn);
                    tris.Add(a + sn); tris.Add(b + s);  tris.Add(b + sn);
                }
            }
            int tipIdx = verts.Count;
            verts.Add(rot * new Vector3(0f, baseY + len * 1.04f, 0.145f));
            uvs.Add(new Vector2(tile.center.x, tile.yMax));
            cols.Add(new Color(1f, 1f, phase, 1f));
            int lastRing = start + segs * sides;
            for (int s = 0; s < sides; s++)
            {
                int sn = (s + 1) % sides;
                tris.Add(lastRing + s); tris.Add(tipIdx); tris.Add(lastRing + sn);
            }
        }

        static void AddCup(List<Vector3> verts, List<Vector2> uvs, List<Color> cols, List<int> tris,
            int sides, int segs, float baseY, float rad, float h, Rect tile, float phase, float windR)
        {
            int start = verts.Count;
            for (int r = 0; r <= segs; r++)
            {
                float t = r / (float)segs;
                float rr = rad * Mathf.Sin(t * Mathf.PI * 0.85f + 0.2f);
                for (int s = 0; s < sides; s++)
                {
                    float a = s * (Mathf.PI * 2f / sides);
                    verts.Add(new Vector3(Mathf.Cos(a) * rr, baseY + t * h, Mathf.Sin(a) * rr));
                    uvs.Add(new Vector2(Mathf.Lerp(tile.xMin, tile.xMax, s / (float)sides), Mathf.Lerp(tile.yMin, tile.yMax, t)));
                    cols.Add(new Color(windR, 0.25f, phase, 0.95f));
                }
            }
            for (int r = 0; r < segs; r++)
            {
                int a = start + r * sides;
                int b = start + (r + 1) * sides;
                for (int s = 0; s < sides; s++)
                {
                    int sn = (s + 1) % sides;
                    tris.Add(a + s);  tris.Add(b + s);  tris.Add(a + sn);
                    tris.Add(a + sn); tris.Add(b + s);  tris.Add(b + sn);
                }
            }
        }
    }
}

Performance & Platform Traps

  • No Alpha-Cutout Overdraw: Because every grass blade (18 tris) and petal has real geometry and uses RenderType = "Opaque", WebGL 2 and mobile GPUs run early-Z rejection cleanly with zero transparent sorting cost.
  • Mipmap Padding in Shared Atlases: Keep at least 3% UV gutter padding (or 4–8 px at 1024²) around every species cell so distant mips never bleed red tulip pixels onto green grass blades.
  • Shadows Only on Hero LOD0: Keep ShadowCastingMode.Off on grass blades and LOD1/LOD2 flowers; reserve shadow casting for close-up LOD0 clumps.
  • Linear Import for Normal & Transmission Maps: Mark the normal atlas as Normal Map (TextureImporterType.NormalMap) and the transmission atlas as linear (sRGBTexture = false) so backlit glow stays physically consistent.

Verification Checklist

  1. Confirm Custom/FoliageAtlasTransmission compiles cleanly (Shader.Find(...).isSupported == true) with zero warnings.
  2. Assert grass blade triangle count == 18 and flower LOD0 / LOD1 / LOD2 budgets stay near 500 / 250 / 100 triangles.
  3. Verify root vertices have color.r == 0 (pinned to ground) and petal/blade tips have color.r >= 0.85 (active wind bend).
  4. Capture a backlit meadow angle (capture) and verify sunlight transmission illuminates petals without washing out shadows.

Official references

  • Eric Zhang / Sucker Punch (GDC 2021 — Procedural Grass in Ghost of Tsushima)
  • Colin Barré-Brisebois & Marc Bouchard (GDC 2011 — Approximating Translucency for a Fast, Cheap and Convincing Subsurface Scattering Look)
  • Unity 6 URP HLSL Shader & LODGroup Manual

More Unity 6 games

Games made with GameCrew on the same engine. No game has been built with this guide yet: these show what Unity 6 games here look like.

Saltwood Alley — Step up to the sunlit timber lanes of an old seaside arcade, feel the weight of turned maple in your palm, and bend real wrist-spin shots into tight vintage scoring cups.
Plays in VR

Saltwood Alley

Step up to the sunlit timber lanes of an old seaside arcade, feel the weight of turned maple in your palm, and bend real wrist-spin shots into tight vintage scoring cups.

Thin Air Errands — Three hundred metres up, with a storm on the way, you carry your own plank between rooftops, lay it across the gap, and walk it with your arms out.
Plays in VR

Thin Air Errands

Three hundred metres up, with a storm on the way, you carry your own plank between rooftops, lay it across the gap, and walk it with your arms out.

More Unity 6 techniques

rendering

Anisotropic Kuwahara Painterly Filter in Unity 6 URP RenderGraph →

Two-pass Unity 6 URP 17.6 RenderGraph ScriptableRendererFeature implementing an orientation-aligned Anisotropic Kuwahara painterly filter with structure-tensor edge guidance, WebGL 2 loop bounds, and software-GPU radius scaling.

lighting

Atmospheric Height Fog, Sun Shafts & Rim-Readable Lighting in Unity 6 URP →

Three-point outdoor/interior URP lighting recipe combining directional sun + warm/cool fill, exponential height/distance fog, ACES/Neutral post-processing, and anti-darkness floors so captures never read black or washed out.

shaders

Cel-Shading, Shadow Ramps & Width-Compensated Outlines in Unity 6 URP →

Two-pass URP stylized cel shader combining main-light shadow-attenuated diffuse ramps, crisp specular/rim accents, and clip-space distance-compensated inverted-hull outlines.

optimization

GPU-Instanced Wind Foliage & Interactive Player Bend in Unity 6 URP →

Draw thousands of swaying grass blades, reeds, or wildflowers in 1–4 draw calls using Graphics.RenderMeshInstanced, URP instanced HLSL wind gusts, tip flutter, and player-sphere pushback.

Read via free MCP — or sign in to add techniques & beta test

Use /mcp/library free with no login to query guides, or connect via OAuth at /mcp to contribute technique guides and beta test cloud builds.

Connect via MCP