C++:世界上唯一能让程序员在配置环境上比写代码还累的|

香菇0_0

园龄:2年7个月粉丝:10关注:1

【Unity Shader学习】接收并显示光照贴图

Shader "Sbin/Textures/Texture03" {
	Properties {
		_MainTex("MainTex",2D) = ""{}
	}
	SubShader {
		Tags { "RenderType"="Opaque" }
		LOD 200
		
	pass
	{
		CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "unitycg.cginc"

		sampler2D _MainTex;
		// 光照贴图
		sampler2D unity_Lightmap ;
		float4 _MainTex_ST;
		// 光照贴图的UV变换(只需声明即可,启用光照贴图时自动赋值)
		float4 unity_LightmapST;

		struct v2f
		{
			float4 pos:POSITION;
			float2 uv:TEXCOORD0;
			float2 uv2:TEXCOORD1;
		};

		v2f vert(appdata_full v)
		{
			v2f o;
			o.pos = mul(UNITY_MATRIX_MVP,v.vertex);
			// 用宏计算出采样二维纹理UV的缩放和偏移量
			o.uv = TRANSFORM_TEX(v.texcoord,_MainTex);
// 计算光照贴图UV坐标的缩放量和偏移量
			o.uv2 = v.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw;
			return o;
		}

		fixed4 frag(v2f IN):COLOR
		{
			float3 lm = DecodeLightmap (tex2D(unity_Lightmap,IN.uv2)) * 2;
			fixed4 color = tex2D(_MainTex,IN.uv);
			color.rgb *= lm;
			return color;
		}
		ENDCG
	}
	}
	FallBack "Diffuse"
}

效果截图:

本文作者:香菇0_0

本文链接:https://www.cnblogs.com/Xiang-gu/p/16512361.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   香菇0_0  阅读(200)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起
  1. 1 404 not found REOL
404 not found - REOL
00:00 / 00:00
An audio error has occurred.