博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【Shader】使用Unity创建水流岩浆等流动效果
阅读量:4086 次
发布时间:2019-05-25

本文共 1510 字,大约阅读时间需要 5 分钟。

Shader "Custom/Stream" {	Properties {        _MainTex ("Albedo (RGB)", 2D) = "white" {}        _MainTint ("Diffuse Tint", Color) = (1,1,1,1)		_ScrollXSpeed ("X Scroll Speed", Range(0,10)) = 2		_ScrollYSpeed ("Y Scroll Speed", Range(0,10)) = 2	}	SubShader {		Tags { "RenderType"="Opaque" }		LOD 200				CGPROGRAM		// Physically based Standard lighting model, and enable shadows on all light types        #pragma surface surf Standard fullforwardshadows		// Use shader model 3.0 target, to get nicer looking lighting		#pragma target 3.0        // 将类型转换到CG中的可用类型		sampler2D _MainTex;        fixed4 _MainTint;        fixed _ScrollXSpeed;        fixed _ScrollYSpeed;        // 读取模型数据的结构体,名字有些迷惑人		struct Input {			float2 uv_MainTex;		};        // inout类型是一个输出数据的类型,顶点着色器处理好数据之后传递给片段着色器        // 就是通过inout修饰的参数来传递的,也就是说inout修饰的类型是提供给片段着色器进一步渲染的     		void surf (Input IN, inout SurfaceOutputStandard o) {                    // 先将UV坐标保存起来(这个值的类型是float2或者fixed2都可以)            float2 scrolledUV = IN.uv_MainTex;            // 可以根据自己的需求来决定滚动方向,此处为xy两个方向偏移            // _Time:是基于Unity的系统内置的时间变量            fixed xScrollValue = _ScrollXSpeed * _Time;            fixed yScrollValue = _ScrollYSpeed * _Time;            // fixed2(x,y):这个就不用过多解释了,将xy合并成一个二元的数据类型            scrolledUV += fixed2(xScrollValue,yScrollValue);            // tex2D(sampler2D,fixed2)官方定义叫:二维纹理查询            // 给出一张图和纹理坐标计算出颜色			half4 c = tex2D (_MainTex, scrolledUV)* _MainTint;			o.Albedo = c.rgb;			o.Alpha = c.a;		}		ENDCG	}	FallBack "Diffuse"}

转载地址:http://lbkii.baihongyu.com/

你可能感兴趣的文章
Node.js核心模块
查看>>
express的应用
查看>>
NodeJS开发指南——mongoDB、Session
查看>>
Express: Can’t set headers after they are sent.
查看>>
2017年,这一次我们不聊技术
查看>>
实现接口创建线程
查看>>
Java对象序列化与反序列化(1)
查看>>
HTML5的表单验证实例
查看>>
JavaScript入门笔记:全选功能的实现
查看>>
程序设计方法概述:从面相对象到面向功能到面向对象
查看>>
数据库事务
查看>>
JavaScript基础1:JavaScript 错误 - Throw、Try 和 Catch
查看>>
SQL基础总结——20150730
查看>>
SQL join
查看>>
JavaScript实现页面无刷新让时间走动
查看>>
CSS实例:Tab选项卡效果
查看>>
前端设计之特效表单
查看>>
前端设计之CSS布局:上中下三栏自适应高度CSS布局
查看>>
Java的时间操作玩法实例若干
查看>>
JavaScript:时间日期格式验证大全
查看>>