【着色器实现Shine局部或整体扫光效果_Shader效果第三篇】

简介: 【着色器实现Shine局部或整体扫光效果_Shader效果第三篇】

效果图如下


属性栏如下


带Shine Mask效果,可以实现Tex的部分Shine。


完整代码如下

Shader "XKB/Shine"
{
    Properties
    {
        _MainTex ("Main Texture", 2D) = "white" {}
    _Color("Main Color", Color) = (1,1,1,1)
    _Alpha("General Alpha",  Range(0,1)) = 1
        _ShineColor("Shine Color", Color) = (1,1,1,1)
        _ShineLocation("Shine Location", Range(0,1)) = 0.5
        _ShineRotate("Rotate Angle(radians)", Range(0, 6.2831)) = 0
        _ShineWidth("Shine Width", Range(0.05,1)) = 0.1
        _ShineGlow("Shine Glow", Range(0,100)) = 1
    [NoScaleOffset] _ShineMask("Shine Mask", 2D) = "white" {}
    }

    SubShader
    {
        Tags {"Queue" = "Transparent" "RenderType"="Opaque" "IgnoreProjector" = "True" }        
        Blend SrcAlpha OneMinusSrcAlpha
        ZWrite Off
        Cull Off
        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
        half4 color : COLOR;
            };

            struct v2f
            {
                float2 uv : TEXCOORD0;
                float4 vertex : SV_POSITION;
        half4 color : COLOR;
            };

            sampler2D _MainTex;
            half4 _MainTex_ST, _MainTex_TexelSize, _Color;
      half _Alpha;
            float _RandomSeed;
      sampler2D _ShineMask;
      half4 _ShineColor;
      half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow;
      
            v2f vert (appdata v)
            {
                v2f o;
        o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = TRANSFORM_TEX(v.uv, _MainTex);
        o.color = v.color;
                return o;
            }

            half4 frag (v2f i) : SV_Target
            {
        float2 uvRect = i.uv;
        half2 center = half2(0.5, 0.5);
        half2 centerTiled = half2(center.x *  _MainTex_ST.x, center.y *  _MainTex_ST.y);
        half4 col = tex2D(_MainTex, i.uv) * i.color;
        half originalAlpha = col.a;
        half2 uvShine = uvRect;
        half cosAngle = cos(_ShineRotate);
        half sinAngle = sin(_ShineRotate);
        half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle);
        uvShine -= half2(0.5, 0.5);
        uvShine = mul(rot, uvShine);
        uvShine += half2(0.5, 0.5);
        half shineMask = tex2D(_ShineMask, i.uv).a;
        half currentDistanceProjection = (uvShine.x + uvShine.y) / 2;
        half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth);
        col.rgb +=  col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0)
        * max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask;
        col.a *= _Alpha;
        col *= _Color;
                return col;
            }
            ENDCG
        }
    }
  Fallback "Sprites/Default"
}
相关文章
【着色器实现Glow可控局部发光效果_Shader效果第十三篇】
【着色器实现Glow可控局部发光效果_Shader效果第十三篇】
【着色器实现Swaying摇曳效果_Shader效果第四篇】
【着色器实现Swaying摇曳效果_Shader效果第四篇】
【着色器实现Pixelate马赛克效果_Shader效果第七篇】
【着色器实现Pixelate马赛克效果_Shader效果第七篇】
【着色器实现Overlay重新覆盖变装效果_Shader效果第九篇】
【着色器实现Overlay重新覆盖变装效果_Shader效果第九篇】
|
存储 芯片 异构计算
|
图形学
【Unity3D Shader】学习笔记-纹理采样①
前言 纹理采样属于在片段着色器中进行,通过提供的贴图和uv坐标使用tex2D进行采样。本篇主要介绍对同一纹理多次采样然后进行混合来获得不同的效果。 [声明:本笔记系列文章的图片资源都源自百度图片搜索,如有问题联系我] 一、简单重影 对同一纹理进行两次采样,采样时的UV两次坐标不一样,然后将采样的结果进行取平均得到最终的结果。
493 0
【Unity3D Shader】学习笔记-纹理采样①
|
图形学
【Unity3D Shader】学习笔记-纹理采样②
前言 上一篇对同一纹理进行多次采样混合,本篇则是通过不同的纹理采样进行混合产生一些效果。 一、简单贴花 贴花简单来说就是在原贴图上面贴上细节贴图,就像墙面上的喷绘一样。下面这个只是最简单的例子,也就是只能在一张图(一个模型)上面贴其他细节。
231 0
【Unity3D Shader】学习笔记-纹理采样②
|
Windows
【OpenGL】二十三、OpenGL 光照中的法线原理
【OpenGL】二十三、OpenGL 光照中的法线原理
185 0
【OpenGL】二十三、OpenGL 光照中的法线原理
《OpenGL编程指南(原书第9版)》——2.7 独立的着色器对象
本节书摘来自华章计算机《OpenGL编程指南(原书第9版)》一书中的第2章,第2.7节,作者:(美)约翰·克赛尼希(John Kessenich)著, 更多章节内容可以访问云栖社区“华章计算机”公众号查看。
1497 0