自发光效果(控制自发光的颜色、强度,呼吸光可选)

xiaoxiao2021-02-27  308

通过一个贴图控制自发光的颜色,一个控制自发光主色调的颜色(注意此处mask直接用rgb格式即可,不需要阿尔法通道控制发光程度,因为颜色自带一个亮度的属性) _EmissionMask (“Emission Mask”, 2D) = “white” {} _EmissionColor (“Emission Color”, Color) = (1, 1, 1, 1) _EmissionColorScale (“Emission Color Scale”, Range(0, 0.5)) = 0

sampler2D _EmissionMask; fixed4 _EmissionColor; float _EmissionColorScale;

fixed3 emissionMaskColor = lerp(tex2D(_EmissionMask, i.uv).rgb, _EmissionColor.rgb, _EmissionColorScale);

fixed3 emission = lerp(albedo, emissionMaskColor, emissionScale); fixed3 finalRGB = ambient + diffuse + specular + emission;

return fixed4(finalRGB, finalA);

呼吸光v:增加控制自发光变化的三角函数 包含频率参数和振幅参数 _EmissionTimeFrequency(“Emission Time Frequency”,Float) =1.0 _EmissionAreaScale (“Emission Area Scale”,Range(0,5)) = 1.0

float _EmissionTimeFrequency; float _EmissionAreaScale;

struct v2f { float4 pos : SV_POSITION; float3 uv : TEXCOORD0; ^} o.uv.z = (sin(_Time.w * _EmissionTimeFrequency) + 1)_EmissionAreaScale 0.5; fixed3 emission = lerp(albedo, emissionMaskColor*i.uv.z, emissionScale);

要下拉列表选择是否用呼吸光,用到枚举 [KeywordEnum(Enable, Disable)] _Breathe (“Enable Breathe”, Float) = 1,#pragma multi_compile _BREATHE_ENABLE _BREATHE_DISABLE,#if _BREATHE_ENABLE float scale; #endif,#if _BREATHE_ENABLE o.scale = (sin(_Time.w * _EmissionBreTimeFrequency) + 1)_EmissionBreAreaScale 0.5; #endif, #if _BREATHE_ENABLE float scale = (sin(_Time.w * _EmissionBreTimeFrequency) + 1)_EmissionBreAreaScale 0.5; o.Emission = emissionMaskColor * _EmissionScale * IN.scale; #else o.Emission = emissionMaskColor * _EmissionScale; #endif 看到博客也能用shader_feature表示toggle,但在用AssetsBundle打包的时候会出现只有某种情况有定义,另一种情况没有定义,还是用上面的。用法如下:[Toggle(ENABLE_BREATHE)] _Breather (“Enable Breather”, Float) = 0, //#pragma shader_feature ENABLE_BREATHE //#if defined(ENABLE_BREATHE) // float scale; //#endif //#if _BREATHE_ENABLE // o.Emission = emissionMaskColor * _EmissionScale * IN.scale; //#elif _BREATHE_DISABLE // o.Emission = emissionMaskColor * _EmissionScale; //#endif

用顶点shader会出现一系列问题: 不接收lightmap,不接收雾,场景光为mix的时候、烘焙后还能接收实时光。如果用surface shader写,这些问题都会迎刃而解.surface shader也分应用到顶点和顶点到像素,vert函数和frag函数,Input, SurfaceOutput,appdatafull等结构。

转载请注明原文地址: https://www.6miu.com/read-3935.html

最新回复(0)