Hey Guys,
i use this shader from here:
and i loved it. But now i try to change to URP and ask GPT to rewrite the Shader for URP (i have no Shader skills).
In Game mode it looks fine, but in any build its just pink (i have tried mac intel+arm, webGL).
The shader is added to “always included shaders” in project settings. (I also try the reset on graphic settings)
If i try to select “update to URP” with the original shader from tutorial it just failed. If i use any other default shader on my material it looks good in game mode.
Searched and tried hundreds of threads, still no look, so i may think the shader itselfs caused the issue.
(but i wonder why its looking good in game mode…)
this is the shader:
Shader "URP/OptimizedFogShader"
{
Properties
{
_Color ("Fog Color", Color) = (0,0,0,1)
_MainTex ("Fog Texture", 2D) = "white" {}
_Smoothness ("Blur Strength", Range(0.0, 0.1)) = 0.005
}
SubShader
{
Tags { "Queue"="Transparent" "RenderType"="Transparent" "RenderPipeline"="UniversalRenderPipeline" }
Blend SrcAlpha OneMinusSrcAlpha
Pass
{
Name "FogEffect"
Tags { "LightMode"="UniversalForward" }
HLSLPROGRAM
#pragma target 3.0
#pragma vertex vert
#pragma fragment frag
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
// Shader properties
float4 _Color;
TEXTURE2D(_MainTex);
SAMPLER(sampler_MainTex);
float _Smoothness;
struct VertexInput
{
float4 position : POSITION; // Vertex position
float2 uv : TEXCOORD0; // UV coordinates
};
struct FragmentInput
{
float4 position : SV_POSITION; // Screen-space position
float2 uv : TEXCOORD0; // UV coordinates
};
// Vertex shader
FragmentInput vert(VertexInput v)
{
FragmentInput o;
o.position = TransformObjectToHClip(v.position.xyz); // Transform to clip space
o.uv = v.uv; // Pass UV coordinates
return o;
}
// Fragment shader
float4 frag(FragmentInput i) : SV_Target
{
// Sample the main texture
float4 texColor = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv);
// Gaussian blur
float2 uvOffsetH = float2(_Smoothness, 0);
float2 uvOffsetV = float2(0, _Smoothness);
float4 blurredH = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv - uvOffsetH) * 0.25 +
texColor * 0.5 +
SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv + uvOffsetH) * 0.25;
float4 blurredV = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv - uvOffsetV) * 0.25 +
texColor * 0.5 +
SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv + uvOffsetV) * 0.25;
float4 blurred = (blurredH + blurredV) * 0.5;
// Final fog color
float4 finalColor = _Color * blurred.g;
finalColor.a = _Color.a - blurred.g;
return finalColor;
}
ENDHLSL
}
}
}
Any ideas?
Thanks <3