一个简单的体积shader,可用于制作体积雾、云等

记录下某不知来历的shader,效果还可以。用于各种Volumetric效果,与光照交互。
因为是简单的物体shader效果肯定会比体积光和体积雾差很多。唯一的好处是不需要其他的代码。

Shader "magic/custom/FakeVolumetricShader"
{
	Properties
	{
		_Color("Color", Color) = (1,1,1,1)
		_MainTex("Albedo (RGB)", 2D) = "white" {}
		_MainTexScrollSpeeds("MainTex Scroll Speeds", vector) = (0, 0, 0, 0)

		_SecondTex("Albedo (RGB)", 2D) = "white" {}
		_SecondTexScrollSpeeds("MainTex Scroll Speeds", vector) = (0, 0, 0, 0)
		_Intensity("Color Intensity 浓度", Float) = 1.0
		_RimPower("Rim Power 边缘光强度", Float) = 1.0
		_CloudDensity("Cloud Density 云层密度", Float) = 1.0
		_LightningConcentration("Lightning concentration 光线集中程度", Float) = 1.0
		_MinLightningValue("Min Lightning value", Range(0.0,1.0)) = 0.0
	}
		SubShader
		{
			Tags {"Queue" = "Transparent" "RenderType" = "Transparent" }
			LOD 200

			CGPROGRAM
			half4 _Color;
			#pragma surface surf SimpleVolumetric alpha:blend
			#pragma skip_variants FOG_LINEAR FOG_EXP FOG_EXP2 LIGHTMAP_ON   SHADOWS_SOFT DIRLIGHTMAP_COMBINED LIGHTMAP_ON SHADOWS_SHADOWMASK

			struct Input
			{
				float2 uv_MainTex;
				float2 uv_SecondTex;
				float3 viewDir;
				float3 worldNormal;
			};

			sampler2D _MainTex;
			sampler2D _SecondTex;

			float _LightningConcentration;
			float _MinLightningValue;


			float _Intensity;
			float _CloudDensity;
			float _RimPower;
			float4 _MainTexScrollSpeeds;
			float4 _SecondTexScrollSpeeds;

			//Custom Volumetric light model
			half4 LightingSimpleVolumetric(SurfaceOutput s, half3 lightDir, half3 viewDir, half atten) {
				half3 h = normalize(lightDir + viewDir);
				float NdotL = abs(dot(s.Normal, lightDir));
				float diff = max(_MinLightningValue, pow(NdotL, _LightningConcentration));
				//negative normals are transformed to positive. To simulate the fact that light run through the object
				float nh = max(0, dot(s.Normal, h));
				half4 c;
				c.rgb = (s.Albedo * _LightColor0.rgb * diff * _LightColor0.rgb*atten);
				c.a = s.Alpha;
				return c;
			}


			void surf(Input IN, inout SurfaceOutput o) {
				//Texture translations
				IN.uv_MainTex += _MainTexScrollSpeeds * _Time.x;
				IN.uv_SecondTex += _SecondTexScrollSpeeds * _Time.x;
				fixed4 mainTextureColor = tex2D(_MainTex, IN.uv_MainTex);
				fixed4 secondTextureColor = tex2D(_SecondTex, IN.uv_SecondTex);
				//(text1 + text2) + RimEffect
				fixed4 textureColor = (mainTextureColor + secondTextureColor) + abs(pow(dot(IN.viewDir, IN.worldNormal), _RimPower));
				fixed4 c = saturate(textureColor)  * _Color;
				//o.Albedo = textureColor.rgb * _Intensity;
				o.Albedo = c.rgb * _Intensity;
				//change alpha pixel based on cloud density parameter
				c.a = saturate(textureColor.r - _CloudDensity);
				o.Alpha = c.a;
			}
			ENDCG
		}
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值