zoukankan      html  css  js  c++  java
  • 基于Unity实现像素化风格的着色器

    Shader "MyShaderTest/SimplePixelationShader"
    {
        Properties 
        {
            _MainTex ("Base (RGB)", 2D) = "white" {}
            _PixelAmount ("Pixel Amount", float) = 50
        }
    
        SubShader
        {
            ZTest Always Cull Off ZWrite Off
    
            Pass
            {
                CGPROGRAM
                #pragma vertex vert
                #pragma fragment frag
                #include "UnityCG.cginc"
    
                sampler2D _MainTex;
                half4 _MainTex_TexelSize;
                float _PixelAmount;
    
                struct v2f
                {
                    float4 vertex : SV_POSITION;
                    half2 uv : TEXCOORD0;
                };
    
    
                v2f vert(appdata_img v)
                {
                    v2f o;
                    o.vertex = UnityObjectToClipPos(v.vertex);
                    o.uv = v.texcoord;
    
                    #if UNITY_UV_STARTS_AT_TOP
                        if (_MainTex_TexelSize.y < 0.0)
                        o.uv.y = 1.0 - o.uv.y;
                    #endif
    
                    return o;
                }
    
    
                fixed4 frag(v2f i) : SV_Target
                {
                    fixed uv_X = floor(i.uv.x * _PixelAmount) / _PixelAmount;
                    fixed uv_Y = floor(i.uv.y * _PixelAmount) / _PixelAmount;
    
                    i.uv = half2(uv_X,uv_Y);
    
                    fixed4 color = tex2D(_MainTex,i.uv);
    
                    return fixed4(color.rgb,1);
                }
    
                ENDCG
            }		
        }
        FallBack Off
    }
    

    这是比较简单的实现方式,比上回的还要方便,用法也是一样。

  • 相关阅读:
    中国象棋评估函数建模
    C语言中指针变量传参
    STM32外部中断
    C语言中的注释
    STM32学习网址
    C语言中的布尔值
    更改KEIL背景配色
    Modbus通讯协议
    DUP
    算法的时间复杂度
  • 原文地址:https://www.cnblogs.com/ezhar/p/12836321.html
Copyright © 2011-2022 走看看