Shader "Unlit/NewUnlitShader" { Properties { _MainTex ("Texture", 2D) = "white" {} _BloomThreshold ("Bloom Threshold", Float) = 0.25 _BloomIntensity ("Bloom Intensity", Float) = 5.0 _BlurAmount ("Blur Amount", Float) = 0.01 _BlurIterations ("Blur Iterations", Int) = 2 _FisheyeStrength ("Fisheye Strength", Float) = 1.1 _Resolution ("Resolution", Vector) = (1080, 1920,0,0) _OffsetY ("Offset Y", Float) = 0.2 _FadeAmount ("Fade Amount", Float) = 1.0 } SubShader { Tags { "RenderType"="Opaque" } LOD 100 Pass { 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 _BloomThreshold; float _BloomIntensity; float _BlurAmount; int _BlurIterations; float _FisheyeStrength; float2 _Resolution; float _OffsetY; float _FadeAmount; v2f vert (appdata v) { v2f o; o.vertex = UnityObjectToClipPos(v.vertex); o.uv = TRANSFORM_TEX(v.uv, _MainTex); UNITY_TRANSFER_FOG(o,o.vertex); return o; } fixed4 blur(float2 uv, sampler2D tex, float blurAmount, int iterations) { fixed4 color = tex2D(tex, uv); // fixed2 offsets[4] = { float2(-blurAmount, 0), float2(blurAmount, 0), float2(0, -blurAmount), float2(0, blurAmount) }; fixed2 offsets[8]={ float2(-blurAmount, 0), float2(blurAmount, 0), float2(0, -blurAmount), float2(0, blurAmount), float2(-blurAmount, -blurAmount), float2(blurAmount, -blurAmount), float2(-blurAmount, blurAmount), float2(blurAmount, blurAmount) }; int len=offsets.Length; // fixed2 offsets[4] = { float2(0,-blurAmount), float2(0, blurAmount), float2(0, -blurAmount*2.0), float2(0,blurAmount*2.0) }; int it=min(iterations, 16); // Limit iterations to 4 for performance for (int iter = 0; iter < it; iter++) { for (int i = 0; i < len; i++) { // Gaussian weights for 8 offsets (approximate) // float weights[8] = {0.1531, 0.1531, 0.1531, 0.1531, 0.0925, 0.0925, 0.0925, 0.0925}; // color += tex2D(tex, uv + offsets[i]/_Resolution * (iter + 1)) * weights[i]; color += tex2D(tex, uv + offsets[i]/_Resolution * (iter + 1)); } } return color / (1.0 + len*it); } fixed luminance(fixed4 color) { return 0.2125 * color.r + 0.7154 * color.g + 0.0721 * color.b; } fixed4 bloom(fixed4 col, float threshold, float intensity) { // fixed4 col = tex2D(tex, uv); fixed lum = luminance(col); fixed val = clamp(lum - threshold, 0.0, 1.0); return col * (val * intensity); // Apply bloom effect by multiplying color with intensity // } } float2 fisheyeWarp(float2 uv, float strength) { float2 center = float2(0.5, 0.5); float2 delta = uv - center; float dist = length(delta); float theta = atan2(delta.y, delta.x); float warpedDist = pow(dist, strength); float2 warpedDelta = float2(cos(theta), sin(theta)) * warpedDist; return center + warpedDelta; } float2 mirror(float2 uv, float offsety) { float y= uv.y*_Resolution.y; float offset=offsety * _Resolution.y; if (y < offset) { // return float2(uv.x, 1.0-(offsety-uv.y)); return float2(uv.x, (offsety- uv.y)/(_Resolution.x/_Resolution.y)); } else if(y < offset + _Resolution.x) { return float2(uv.x, (uv.y-offsety)/(_Resolution.x/_Resolution.y)); } else { return float2(uv.x, 1.0-(uv.y- offsety - _Resolution.x/_Resolution.y)/(_Resolution.x/_Resolution.y)); } } fixed4 frag (v2f i) : SV_Target { // sample the texture v2f o; o.uv=mirror(i.uv, _OffsetY); // Apply mirror effect based on offset // o.uv = fisheyeWarp(o.uv, _FisheyeStrength); // Apply fisheye warp effect float dist= length(i.uv*_Resolution - float2(0.5, _OffsetY + _Resolution.x/_Resolution.y*0.5)* _Resolution)/_Resolution.x; // Calculate distance from center // float dist = length(i.uv.y ); // Calculate distance from center dist=pow(1.0 - dist, 2.0); // Square the distance for a smoother fade effect fixed4 col_raw = tex2D(_MainTex, o.uv); fixed4 col_blur = blur(o.uv, _MainTex, _BlurAmount*((1.0-dist)*4.0), _BlurIterations+floor((1.0-dist)*16.0)); // Apply blur with a small amount fixed4 col_bloom = bloom(col_blur, _BloomThreshold, _BloomIntensity); // Apply bloom with threshold and intensity fixed4 col = col_blur*col_bloom + col_raw*(dist) + col_blur*(1.0-dist); // Combine raw color with blurred and bloom effects col.rgb = col.rgb * col.a ; // Premultiplied alpha col.a*= _FadeAmount; // Apply fade amount to alpha // col.r=col.g=col.b= ( dist); // Apply fade effect based on distance from center // apply fog // UNITY_APPLY_FOG(i.fogCoord, col); return col; // Return the final color with bloom effect } ENDCG } } }