zoukankan      html  css  js  c++  java
  • Cg入门20:Fragment shader

    Unity 一个面片的最大顶点数为65524,所以大于这个数,请拆分成多个面片
    1.获取汽车x轴的最大值和最小值[-2.5,2.5]+R

    surfaceShader 语法

    surf :surface shader的方法名
    vert :使用顶点程序方法名

    surface shader 方法不能有返回值


    源码:
    Shader "Sbin/SurfaceShader" {
    	Properties {
    		_Glossiness ("Smoothness", Range(0,1)) = 0.5
    		_Metallic ("Metallic", Range(0,1)) = 0.0
    
    		_UpColor("UpColor",color) = (1,0,0,1)
    		_DownColor("DownColor",color) = (0,1,0,1)
    		_Center("Center",range(-0.7,0.7)) = 0
    		_R("R",range(0,0.5)) = 0.2
    	}
    	SubShader {
    		Tags { "RenderType"="Opaque" }
    		LOD 200
    		
    		CGPROGRAM
    		#pragma surface surf Standard vertex:vert fullforwardshadows
    		//说明:pragma surface method1 Standard vertex:method2	fullforwardshadows
    		
    		#pragma target 3.0
    
    		sampler2D _MainTex;
    
    		struct Input {
    			float2 uv_MainTex;
    			float x:TEXCOORD0;
    		};
    
    		half _Glossiness;
    		half _Metallic;
    
    		float4 _UpColor;
    		float4 _DownColor;
    		float _Center; 
    		float _R; 
    
    		void vert(inout appdata_full v,out Input o){
    			o.uv_MainTex = v.texcoord.xy;
    			o.x = v.vertex.x;
    		}
    
    		void surf (Input IN, inout SurfaceOutputStandard o) {
    			fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
    			o.Albedo = c.rgb;
    			o.Metallic = _Metallic;
    			o.Smoothness = _Glossiness;
    			o.Alpha = c.a;
    
    			float d = IN.x - _Center;//融合带
    			float s = abs(d);
    			d = d/s;//正负值分别描写叙述上半部分和下半部分。取值1和-1
    
    			float f = s/_R;	//范围>1:表示上下部分;范围<1:表示融合带
    			f = saturate(f);
    			d *= f;//表示所有[-1,1];范围>1:表示上部分;范围<1:表示融合带;范围<-1:表示下部分
    				
    			d = d/2+0.5;//将范围控制到[0,1],由于颜色值返回就是[0,1]
    			o.Albedo += lerp(_UpColor,_DownColor,d);
    		}
    		ENDCG
    	}
    	FallBack "Diffuse"
    }
    

    效果:

  • 相关阅读:
    手机开发中的AP与BP的概念
    pk8和x509.pem转换成keystore
    android系统release签名
    java读取pfx或P12格式的个人交换库公私钥
    使用IntelliJ IDEA查看类的继承关系图形
    Java日志框架与日志系统
    Java常见加密技术的密钥与加密串长度
    quartz的持久化任务调度使用应用的dataSource
    敏感数据脱敏
    Jquery的Ajax中contentType和dataType的区别
  • 原文地址:https://www.cnblogs.com/lxjshuju/p/7127512.html
Copyright © 2011-2022 走看看