#Shader that auto resizes object based onH distance?

72 messages · Page 1 of 1 (latest)

terse dirge
#

Hello

I'm looking for a shader that would auto resize itself depending on how far away the player is from it. The idea is, regardless of how far away you are, it's always going to stay the same size.

Any ideas? Obviously no scripts.

untold shadow
#

Coding is something that this thing knows

terse dirge
untold shadow
#

Including unity shaders

#

Yeah I do have GPT4 as well

terse dirge
#

I used the base version but it didn’t give me a working shader

untold shadow
#

You have to feed it with the errors that unity gives you if it doesnt work

terse dirge
#

I know someone that has GPT 4, I’ll ask to use it for a little. Because 3.5 wasn’t too big a help

untold shadow
#

Done within 7 minutes with GPT 3.5
I just fed it with errors and errors until it got it correct

#

Of course it's not perfect, but even then, it already did a lot

#

This one was made with GPT4. I'll send you both codes and just use GPT3.5 to edit it to add some stuff like scale factor, color, albedo etc etc.

untold shadow
# terse dirge Hello I'm looking for a shader that would auto resize itself depending on how f...

GPT4:

    Properties {
        _Color ("Color", Color) = (1,1,1,1)
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
    }
    SubShader {
        Tags { "RenderType"="Opaque" }
        LOD 100

        Pass {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            
            #include "UnityCG.cginc"

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

            struct v2f {
                float2 uv : TEXCOORD0;
                float4 vertex : SV_POSITION;
            };
            
            uniform float4 _MainTex_ST;
            uniform sampler2D _MainTex;
            uniform float4 _Color;

            v2f vert (appdata v) {
                v2f o;
                float d = length(_WorldSpaceCameraPos - mul(unity_ObjectToWorld, v.vertex));
                v.vertex.xyz *= d;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                return o;
            }
            
            fixed4 frag (v2f i) : SV_Target {
                fixed4 col = tex2D(_MainTex, i.uv);
                return _Color * col;
            }
            ENDCG
        }
    }
}```

GPT 3.5:
```Shader "Custom/DistanceScaledShader"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
        _ScaleFactor ("Scale Factor", Float) = 1.0
    }

    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200
        
        CGPROGRAM
        #pragma surface surf Lambert vertex:vert
        
        sampler2D _MainTex;
        float _ScaleFactor;

        struct Input
        {
            float2 uv_MainTex;
        };

        void vert(inout appdata_full v)
        {
            // Calculate distance from camera to vertex
            float dist = distance(_WorldSpaceCameraPos, v.vertex.xyz);
            
            // Apply scaling based on distance
            float scale = _ScaleFactor * dist;
            
            // Apply scaling to vertex position
            v.vertex.xyz *= scale;
        }

        void surf (Input IN, inout SurfaceOutput o)
        {
            // Output the scaled position
            o.Albedo = tex2D(_MainTex, IN.uv_MainTex).rgb;
            o.Alpha = tex2D(_MainTex, IN.uv_MainTex).a;
            o.Normal = float3(0,0,1);
            // No need to assign o.Position, it's automatically set by the surface shader
        }
        ENDCG
    }
    FallBack "Diffuse"
}```

Enjoy :-)
#

Also, addition what GPT4 wrote

karmic cargo
#

hmm gpt 4 might not be that bad of an idea

untold shadow
# karmic cargo hmm gpt 4 might not be that bad of an idea

For simple shaders it is really useful. With GPT 3.5, I had to send it the error around 16 times.
With GPT4, it was straight off working, just not correctly. Explained it what's happening and GPT4 did it immediately

I don't know how to make shaders, neither I want to know this voodoo code, but GPT help is really useful when it comes to it

#

I wish Unturned used shader graph

karmic cargo
#

same, i also have no clue so i use gpt 3.5

terse dirge
#

Thank you so much man!

terse dirge
untold shadow
#

I'll put it ingame now quickly as a test

untold shadow
#

Sorry for the background speaking, I'm in call with someone xD

terse dirge
#

That's incredible

terse dirge
#

@untold shadow It worked brilliantly! I had to ask ChatGPT for a small adjustment to give it small distance drop off, but now it's working beautifully

terse dirge
untold shadow
#

My GPT4 charges depending on how many words it says

#

I have to pay the bills too!

terse dirge
#

hahaha

#

I can send the script if someone wants to use it

#

It's visible through walls + autoscales (perfect for icons!)

untold shadow
#

Wanna see how GPT4 fucked me over in the beginning & it got me charged for pretty much nothing?

terse dirge
#

sure

untold shadow
#

Smh, it generated so many pointless words, each costs some fraction of a cent :(

terse dirge
#

Does ChatGPT really cost per message?

untold shadow
untold shadow
#

I have it on API

terse dirge
#

It's 20 bucks + tokens???

#

damn

untold shadow
#

nono, this is API
Yes, I could buy the 20 bucks version, but since the company I work in uses the API, I just use that

terse dirge
#

ahhhh

#

smart

untold shadow
#

It's not like I use GPT so much like I did before. OpenAI completely censored 3.5 and I honestly don't want to pay for it when something like microsoft copilot is a thing now

#

Which uses GPT4 as well and is free

untold shadow
terse dirge
#

why is copilot so damn slow?

#

or is it just me

terse dirge
#

All the objectives will have markers (place down drill, secure loot, etc)

untold shadow
#

Ah I see, that makes sense, may I get the shader? 👉 👈 😁

terse dirge
# untold shadow Ah I see, that makes sense, may I get the shader? 👉 👈 😁

Shader "Custom/AlwaysOnTopWithAutoScale" {
Properties {
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Color ("Color", Color) = (1, 1, 1, 1)
}
SubShader {
Tags { "RenderType" = "Transparent" "Queue" = "Transparent+100" }
Cull Off
Lighting Off
ZWrite Off
ZTest Always
Fog { Mode Off }
Blend SrcAlpha OneMinusSrcAlpha

    LOD 100
    
    Pass {
        CGPROGRAM
        #pragma vertex vert
        #pragma fragment frag
        #include "UnityCG.cginc"

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

        struct v2f {
            float2 uv : TEXCOORD0;
            float4 vertex : SV_POSITION;
        };

        uniform float4 _MainTex_ST;
        uniform sampler2D _MainTex;
        uniform float4 _Color;

        v2f vert(appdata v) {
            v2f o;
            float d = length(_WorldSpaceCameraPos - mul(unity_ObjectToWorld, v.vertex));
            float scale = log(d + 1.0); // Logarithmic scaling
            float3 scaledVertex = v.vertex.xyz * scale;
            o.vertex = UnityObjectToClipPos(float4(scaledVertex, 1.0));
            o.uv = TRANSFORM_TEX(v.uv, _MainTex);
            return o;
        }

        fixed4 frag(v2f i) : SV_Target {
            fixed4 col = tex2D(_MainTex, i.uv);
            return _Color * col;
        }
        ENDCG
    }
}
Fallback Off

}

#

Here you go!

untold shadow
#

Ty 😁

#

very cool idea

terse dirge
#

How did you design it?

untold shadow
#

These are purchased assets off of unity store 😅
Since I'm just a unity & NPC guy, I don't do models and buying models is very practical for me

#

But yeah Dallas, this is a very cool concept. And wanna know what might make it even cooler?

#

If you make a reverse of something like this, it could be really cool. Like, if you're really close to it, it slowly fades into alpha 0. If you get a bit far away from it, the alpha goes back to 1

ionic ember
#

hi

summer kayak
summer kayak