公告板shader

Posted 露夕逝

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了公告板shader相关的知识,希望对你有一定的参考价值。

Shader "Custom/LightPoint" {
    Properties {
        _MainTex ("Main Tex", 2D) = "white" {}
        _Color ("Color Tint", Color) = (1, 1, 1, 1)
    }
    SubShader {
        Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "DisableBatching"="True"}
        
        Pass { 
            Tags { "LightMode"="ForwardBase" }
            
            ZWrite On//深度写入
            Blend SrcAlpha OneMinusSrcAlpha//开启混合模式
            Offset 0,-10000
        
            CGPROGRAM
            
            #pragma vertex vert
            #pragma fragment frag
            
            #include "Lighting.cginc"
            
            sampler2D _MainTex;
            float4 _MainTex_ST;
            fixed4 _Color;
            
            struct a2v {
                float4 vertex : POSITION;
                float4 texcoord : TEXCOORD0;
                fixed4 texcoord1 : TEXCOORD1;
                float3 color:COLOR;
            };
            
            struct v2f {
                float4 pos : SV_POSITION;
                float2 uv : TEXCOORD0;
            };
            
            v2f vert (a2v v) {
                v2f o;
                float scaleX = unity_ObjectToWorld[0][0];//先用3个变量对变换的分量进行记录
                float scaleY = unity_ObjectToWorld[1][1];
                float scaleZ = unity_ObjectToWorld[2][2];
                unity_ObjectToWorld[0][0] = 1;
                unity_ObjectToWorld[1][1] = 1;
                unity_ObjectToWorld[2][2] = 1;

                v.texcoord1.x = v.texcoord.x * scaleX;//将第二套uv坐标进行缩放
                v.texcoord1.y = v.texcoord.y * scaleY;

                float3    centerOffs = float3(float2(0.5, 0.5)*scaleX - v.texcoord1.xy, 0);//得保证面片是整体缩放
                float3    centerLocal = v.vertex.xyz + centerOffs.xyz;

                centerLocal.x = v.vertex.x*scaleX + centerOffs.x;
                centerLocal.y = v.vertex.y*scaleY + centerOffs.y;
                centerLocal.z = v.vertex.z*scaleZ + centerOffs.z;

                float4 centerWolrd = mul(unity_ObjectToWorld, float4(centerLocal.xyz, 1.0));
                float4 centerView = mul(UNITY_MATRIX_V, centerWolrd);
                float4 viewP = centerView + float4(centerOffs.xy, 0.0, 0.0);

                o.pos = mul(UNITY_MATRIX_P, float4(viewP.xyz, 1));
                o.uv = TRANSFORM_TEX(v.texcoord,_MainTex);
                o.uv.y=1-o.uv.y;//上下翻转图像
                return o;
            }
            
            fixed4 frag (v2f i) : SV_Target {
                fixed4 c = tex2D (_MainTex, i.uv);
                c.rgb *= _Color.rgb;
                return c;
            }
            
            ENDCG
        }
    } 
    FallBack off
}

 

以上是关于公告板shader的主要内容,如果未能解决你的问题,请参考以下文章

Cg入门20:Fragment shader - 片段级模型动态变色(实现汽车动态换漆)

Shader2.0的顶点着色器和片段着色器

Shader HLSL片段说明

Cg入门16:Fragment shader - 片段级光照

《java精品毕设》基于javaweb宠物领养平台管理系统(源码+毕设论文+sql):主要实现:个人中心,信息修改,填写领养信息,交流论坛,新闻,寄养信息,公告,宠物领养信息,我的寄养信息等(代码片段

Cg入门17:Fragment shader - 片段级光照(添加阴影)