clouds and sunshafts

Hi!! I have made two shaders. The first one is a cutout shader where is rendered the two faces(for clothes for example), the second one is a fragment shader that uses a noise function for clouds simulation. My problem is the image effect sunshafts. I want my shaders block the sun rays but it dosen’t work. In the first shader the sun rays are only blocked in the front face, the back face dosen’t block it. For the fragment shader i dont know how to do it.

I leave here de code of the two shaders, if it help:

the first shader:

Shader "MAP/SceneTransparentCut" {
	Properties {
		//BASE
		_Color ("Main Color", Color) = (1,1,1,1)
		_MainTex ("Main Texture", 2D) = "white" {}
		//CUTOFF
		_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
	}
	SubShader {
		Tags {
			"Queue"="AlphaTest"
			"IgnoreProjector"="True"
			"RenderType"="TransparentCutout"
		}
		LOD 200
		Cull Off

		CGPROGRAM
		#pragma surface surf Lambert addshadow fullforwardshadows
			sampler2D _MainTex;
			fixed4 _Color;
			half _Cutoff;

			struct Input {
				float2 uv_MainTex;
			};

			void surf (Input IN, inout SurfaceOutput o) {
				//Main Texture
				half4 c = tex2D (_MainTex, IN.uv_MainTex);
				o.Albedo = c.rgb * _Color.rgb;
				
				//Clip
				clip(c.a - _Cutoff);
				
				//Alpha
				o.Alpha = 1;
			}
		ENDCG
	} 
	Fallback "Transparent/Cutout/VertexLit"
}
Shader "MAP/FXClouds" {
	Properties {
		//BASE
		_Color ("Main Color", Color) = (1,1,1,1)
		_Clar("Clarity", range (0,5)) = 0.1
		_PermTexture ("Noise", 2D) = "white" {}
		_T ("Time (used for animation)", Float) = 1
		_R1 ("Random (First Octave)", Float) = 1
		_R2 ("Random (Second Octave)", Float) = 1
		_R3 ("Random (Third Octave)", Float) = 1
		_R4 ("Random (Fourth Octave)", Float) = 1
		_R5 ("Random (Fifth Octave)", Float) = 1
		_R6 ("Random (Sixth Octave)", Float) = 1
		//BUMP MAP
		_BumpMap ("Normalmap", 2D) = "bump" {}
		//ALPHA
		_Alpha("Alpha", range (0,1)) = 0.1
		_AlphaPlus("Alpha Plus", range (-1,4)) = 0.1
		_IntensAlpha("Alpha Intensity", range (0,5)) = 0.1
	}
	SubShader {
		Tags {
			"Queue"="Transparent"
			"IgnoreProjector"="False"
			"RenderType"="Transparent"
		}
		Cull Front
		Blend SrcAlpha OneMinusSrcAlpha 

		Pass {
			Tags {"LightMode" = "ForwardBase"}

			CGPROGRAM
				#pragma target 3.0
				#pragma vertex vert
				#pragma fragment frag
				#pragma multi_compile_fwdbase
				#pragma fragmentoption ARB_fog_exp2
				#pragma fragmentoption ARB_precision_hint_fastest
				#include "UnityCG.cginc"
				#include "AutoLight.cginc"

				half _Clar;
				half _Alpha;
				half _IntensAlpha;
				half _AlphaPlus;
				sampler2D _PermTexture;
				float4 _PermTexture_ST;
				uniform float4 _Tint;
				uniform float _T;
				uniform float _R1;
				uniform float _R2;
				uniform float _R3;
				uniform float _R4;
				uniform float _R5;
				uniform float _R6;
				sampler2D _BumpMap;
				fixed4 _Color;
				fixed4 _LightColor0;

				// 1 / 256 and 1 / 512
				#define ONE 0.00390625
				#define ONEHALF 0.001953125

				float fade(float t) {
					return t*t*t*(t*(t*6.0-15.0)+10.0); // Improved fade, yields C2-continuous noise
				}

				// Note that these texture samples can be replaced with a noise function!
				float noise(float2 P) {
					float2 Pi = ONE * floor(P) + ONEHALF;		// Integer part, scaled and offset for texture lookup
					float2 Pf = frac(P);						// Fractional part for interpolation

					// Noise contribution from lower left corner
					float2 grad00 = tex2D(_PermTexture, Pi).rg * 4.0 - 1.0;
					float n00 = dot(grad00, Pf);

					// Noise contribution from lower right corner
					float2 grad10 = tex2D(_PermTexture, Pi + float2(ONE, 0.0)).rg * 4.0 - 1.0;
					float n10 = dot(grad10, Pf - float2(1.0, 0.0));

					// Noise contribution from upper left corner
					float2 grad01 = tex2D(_PermTexture, Pi + float2(0.0, ONE)).rg * 4.0 - 1.0;
					float n01 = dot(grad01, Pf - float2(0.0, 1.0));

					// Noise contribution from upper right corner
					float2 grad11 = tex2D(_PermTexture, Pi + float2(ONE, ONE)).rg * 4.0 - 1.0;
					float n11 = dot(grad11, Pf - float2(1.0, 1.0));

					// Blend contributions along x
					float2 n_x = lerp(float2(n00, n01), float2(n10, n11), fade(Pf.x));

					// Blend contributions along y
					float n_xy = lerp(n_x.x, n_x.y, fade(Pf.y));

					// We're done, return the final noise value.
					return n_xy;
				}

				float fractalSum(float2 Q) {
					float value = 0;

					// add frequencies
					value += noise(Q / 4 + _R1) * 4;
					value += noise(Q + _R2);
					value += noise(Q * 2 + _R3) / 2;
					value += noise(Q * 4 + _R4) / 4;
					value += noise(Q * 8 + _R5) / 8;
					value += noise(Q * 16 + _R6) / 16;

					return value;
				}

				struct v2f{
					float4 pos: SV_POSITION;
					float2 uv: TEXCOORD0;
					float3 viewDir: TEXCOORD1;
					float3 lightDir: TEXCOORD2;
					LIGHTING_COORDS(3,4)// Macro to send shadow  attenuation to the vertex shader.
				};

				v2f vert (appdata_tan v){
					v2f o;

					o.pos = mul( UNITY_MATRIX_MVP, v.vertex);
					o.uv = TRANSFORM_TEX(v.texcoord.xy, _PermTexture);

					TANGENT_SPACE_ROTATION;// Macro for unity to build the Object>Tangent rotation matrix "rotation".
					o.viewDir = mul(rotation, ObjSpaceViewDir(v.vertex));
					o.lightDir = mul(rotation, ObjSpaceLightDir(v.vertex));

					TRANSFER_VERTEX_TO_FRAGMENT(o);// Macro to send shadow  attenuation to the fragment shader.
					return o;
				}
     
				fixed4 frag(v2f i) : COLOR{
					i.viewDir = normalize(i.viewDir);
					i.lightDir = normalize(i.lightDir);
					half3 h = normalize(i.lightDir + i.viewDir);
					
					fixed3 normalA = UnpackNormal(tex2D(_BumpMap, i.uv));
					
					fixed diff = saturate(dot(normalA, i.lightDir));

					fixed atten = LIGHT_ATTENUATION(i);
					
					float value = fractalSum((i.uv + float2(_T, _T))* 32 + 240);
					
					float4 result;
					result.rgb = UNITY_LIGHTMODEL_AMBIENT.rgb * 2;
					result.rgb += (float3(value, value, value)+_Clar) * _LightColor0.rgb * diff * atten *_Color.rgb;
					result.a = (value*_IntensAlpha+_AlphaPlus)*_Alpha;
					return result;
				}
			ENDCG
		}
	}
}

your first is a surface shader, you should use alphacutoff(i dont remember how its written search the documents) and not use the clip function.

I didnt check your second shader, but i think the sunshafts shader which unity has provided uses alpha channel of the scene to do its thing. So, you must write correct alpha values of the clouds to the screen buffer.

I have tried “AlphaTest Greater [_Cutoff]” and “AlphaTest:_Cutoff” but it doesn’t work (and it appears to have problems with shadows).
For the second shader, i know about the alpha channel, but i am using result.a as alpha so i don’t know what the problem is.

By alpha cutoff i meant this:

#pragma surface surf Lambert alphatest:_Cutoff addshadows…etc

I know. I tried that, but doesn’t happen nothing(there is no cutout).

Ok. Solved it!!