zoukankan      html  css  js  c++  java
  • 雷达波Shader

    OSG版本:

    vert

    #version 120
    varying out vec3 v;
    void main()
    {
        gl_FrontColor = gl_Color;
        gl_Position = ftransform();
        v = gl_Vertex.xyz;
    }

    frag

    #version 120
    varying in vec3 v;
    uniform float osg_FrameTime;
    void main()
    {
        //gl_FragColor = vec4(1,0,0,1);
        gl_FragColor = gl_Color;
        // 条带间隔
        //if (mod(floor((v.z-osg_FrameTime*100000)/ 100000),2)!=0)
        //    discard;
        //gl_FragColor = vec4(1,0,0,0.5);
        float alpha = (cos((v.z-osg_FrameTime*50000) / 20000)+1-0.2)/2;
        gl_FragColor = vec4(gl_Color.xyz,alpha);
    }

    Unity版本:

    // Upgrade NOTE: replaced '_World2Object' with 'unity_WorldToObject'
    
    // Upgrade NOTE: replaced '_World2Object' with 'unity_WorldToObject'
    
    Shader "Custom/RadarWave" {
        Properties {
            _Color ("Color", Color) = (1,1,1,1)
            _MainTex ("Albedo (RGB)", 2D) = "white" {}
            _Glossiness("Smoothness", Range(0,1)) = 0.5
            _Metallic("Metallic", Range(0,1)) = 0.0
            _TransVal("Transparency Value", Range(0,1)) = 0.5
            _StripWidth("Strip Width", Range(0.01,1)) = 0.1
            _Speed("Speed", Range(0.1,10)) = 1
            [Enum(x,1,y,2,z,3)]_Direction("Moving Direction", Int)=3
        }
        SubShader {
            Tags { "RenderType"="Opaque" "Queue" = "Transparent" }
            LOD 200
            //Cull Off//关闭背面裁剪
            //Lighting Off//此设置在surface shader中不起作用,貌似是在Unlit Shader中使用的
            //ZWrite On
            //ZTest On
            Blend SrcAlpha OneMinusSrcAlpha
            
            CGPROGRAM
            // Physically based Standard lighting model, and enable shadows on all light types
            //#pragma surface surf Standard fullforwardshadows alpha vertex:vert
            #pragma surface surf NoLightModel fullforwardshadows alpha vertex:vert
    
            
    
            // Use shader model 3.0 target, to get nicer looking lighting
            #pragma target 3.0
    
            sampler2D _MainTex;
    
            struct Input {
                float2 uv_MainTex;
                float4 modelPos_;
            };
    
            half _Glossiness;
            half _Metallic;
            half _TransVal;
            half _StripWidth;
            half _Speed;
            int _Direction;
            fixed4 _Color;
    
            // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
            // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
            // #pragma instancing_options assumeuniformscaling
            UNITY_INSTANCING_CBUFFER_START(Props)
                // put more per-instance properties here
            UNITY_INSTANCING_CBUFFER_END
    
            void surf(Input IN, inout SurfaceOutput o) {
                // Albedo comes from a texture tinted by color
                fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
                o.Albedo = c.rgb;
                //float4 tmp = mul(unity_WorldToObject, IN.modelPos_);
                //_Time    float4    t是自该场景加载开始所经过的时间,4个分量分别是 (t/20, t, t*2, t*3)
                float modelPos = _Direction == 1 ? IN.modelPos_.x : _Direction == 2 ? IN.modelPos_.y : IN.modelPos_.z;
                /*if (fmod(floor((modelPos -_Time.y*_Speed)/ _StripWidth),3)!=0)
                {
                    //clip(-1);
                    discard;
                }
                //o.Alpha = c.a;
                o.Alpha = _TransVal;*/
                o.Alpha = (cos((modelPos - _Time.y*_Speed) / _StripWidth) + 1) / 2;
                o.Alpha = clamp(o.Alpha, 0.1, 0.9);
            }
    
            void vert(inout appdata_full v, out Input o)
            {
                UNITY_INITIALIZE_OUTPUT(Input, o);
                o.modelPos_ = v.vertex;
            }
    
            //命名规则:Lighting接#pragma suface之后起的名字   
            //lightDir :点到光源的单位向量   viewDir:点到摄像机的单位向量   atten:衰减系数   
            float4 LightingNoLightModel(SurfaceOutput s, float3 lightDir, half3 viewDir, half atten)
            {
                float4 c;
                c.rgb = s.Albedo;
                c.a = s.Alpha;
                return c;
            }
    
            ENDCG
        }
        FallBack "Diffuse"
    }
  • 相关阅读:
    KLSudoku的数独题目生成方法和难度控制说明
    对XChain和ForcingChain的实现解说
    开源数独游戏软件KLSudoku发布第一个Release版本
    每个 Vim 用户都应该阅读的文章
    自己常用的几个gvim的vimrc设置
    KLSudoku数独游戏软件1.1预览版发布
    KLSudoku数独游戏软件1.1正式版发布
    字符串
    .NET面试大全
    IIS是如何处理ASP.NET请求的
  • 原文地址:https://www.cnblogs.com/coolbear/p/8745937.html
Copyright © 2011-2022 走看看