#Scale billboard with distance from player

27 messages · Page 1 of 1 (latest)

clear sundial
#

Anyone know how do change the scale the billboard based off distance from player ie visually it looks the same size no matter the distance im using the BillboardMage shader to create a billboard I even tried making my own shader but it only works in unity not ingame

// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'

Shader "Unlit/BillboardTest"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
        _ScaleFactor ("Scale Factor", Range(0,1)) = 0
        _ReferenceDistance ("Reference Distance", Float) = 10
    }
    SubShader
    {
        Tags { "RenderType"="Transparent" "Queue"="Transparent" }
        LOD 100

        Pass
        {
            ZWrite Off
            Blend SrcAlpha OneMinusSrcAlpha
            Cull Off

            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            // make fog work
            #pragma multi_compile_fog

            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct v2f
            {
                float2 uv : TEXCOORD0;
                UNITY_FOG_COORDS(1)
                float4 vertex : SV_POSITION;
            };

            sampler2D _MainTex;
            float4 _MainTex_ST;
            float _ScaleFactor;
            float _ReferenceDistance;

            v2f vert (appdata v)
            {
                v2f o;

                float4 world_origin = mul(UNITY_MATRIX_M, float4(0, 0, 0, 1));
                float4 view_origin = float4(UnityObjectToViewPos(float3(0, 0, 0)), 1);

                float scale = (_ScaleFactor * (length(view_origin) / _ReferenceDistance)) + ((1 - _ScaleFactor));

                float4 world_pos = mul(UNITY_MATRIX_M, float4(scale, scale, scale, 1) * v.vertex);
                float4 flipped_world_pos = float4(-1, 1, -1, 1) * (world_pos - world_origin) + world_origin;
                //float4 view_pos = mul(UNITY_MATRIX_V, world_pos);
                float4 view_pos = flipped_world_pos - world_origin + view_origin;
                float4 clip_pos = mul(UNITY_MATRIX_P, view_pos);

                o.vertex = clip_pos;

                o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                UNITY_TRANSFER_FOG(o,o.vertex);
                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {
                // sample the texture
                fixed4 col = tex2D(_MainTex, i.uv);
                // apply fog
                UNITY_APPLY_FOG(i.fogCoord, col);
                return col;
            }
            ENDCG
        }
    }
}
glass sigil
#

use chatgpt to make the shader tbh

clear sundial
#

Chat gpt is brain dead sometimes

urban vine
#

Just dont be brainded urself and try to go with the flow and describe what dont work ;3

dense parcel
#

asking for help

#

insane!

clear sundial
#

This is gonna be the death of me

dense parcel
#

fuck shaders

#

!

clear sundial
#

Fr I’ve gotten it to work like 10 different ways in the editor but when I put it in unturned nah

clear sundial
urban vine
#

Asset_Bundle_Version 5

#

U dont need to master

#

if it dont work then go ahead

#

but ig shaders need it

clear sundial
#

Ty so much I’ll give it a try when I get home

clear sundial
dense parcel
clear sundial
#

yes i am