#Shader that auto resizes object based onH distance?
72 messages · Page 1 of 1 (latest)
Dallas, I've used ChatGPT for shaders quite a lot, try it, it might help you
Coding is something that this thing knows
You have the premium one, right?
I used the base version but it didn’t give me a working shader
You have to feed it with the errors that unity gives you if it doesnt work
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
@terse dirge
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
It just doesnt work upclose
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.
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
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
same, i also have no clue so i use gpt 3.5
Thank you so much man!
Ill have to test it in game!
I'll put it ingame now quickly as a test
But yeah, as I said, use gpt to edit the shader and it should be good
Sorry for the background speaking, I'm in call with someone xD
Yoooo! It does work
That's incredible
@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
That will be 50€ sir.
:(((
hahaha
I can send the script if someone wants to use it
It's visible through walls + autoscales (perfect for icons!)
Wanna see how GPT4 fucked me over in the beginning & it got me charged for pretty much nothing?
sure
Smh, it generated so many pointless words, each costs some fraction of a cent :(
Does ChatGPT really cost per message?
May I see your idea behind it?
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
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
Icons.. are you doing like.. some kind of an arena?
For my heists
All the objectives will have markers (place down drill, secure loot, etc)
A lot of people might be using it
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!
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
Oooh!
I can do that, good idea!
hi
yeah it works suprisingly well
thats doable with vanilla unity shaders afaik