Shader 之 顶点变形
可以使3D物体通过顶点变形弯曲,常见于跑酷游戏的跑道。可向左、右、上、下弯曲。
Shader "Custom/VertexColorCurved" {
Properties {
// Shader需要的6个参数
_MainTex ("Base (RGB)", 2D) = "white" {}
_QOffset ("Offset", Vector) = (,,,)
_Dist ("Distance", Float) = 100.0
_BrightnessAmount ("Brightness Amount", Float) = 1.0
_SaturationAmount ("Saturation Amount", Float) = 1.0
_ContrastAmount ("Contrast Amount", Float) = 1.0
}
SubShader {
Tags { "Queue" = "Transparent"}
Pass
{
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
float4 _QOffset;
float _Dist;
fixed _BrightnessAmount;
fixed _SaturationAmount;
fixed _ContrastAmount;
float _OpacityAmount;
struct v2f {
float4 pos : SV_POSITION;
float4 uv : TEXCOORD0;
float3 viewDir : TEXCOORD1;
fixed4 color : COLOR;
};
v2f vert (appdata_full v)
{
v2f o;
float4 vPos = mul (UNITY_MATRIX_MV, v.vertex);
float zOff = vPos.z/_Dist;
vPos += _QOffset*zOff*zOff;
o.pos = mul (UNITY_MATRIX_P, vPos);
o.uv = v.texcoord;
//o.color.rgb = v.color.rgb; // 取顶点色
return o;
}
float3 ContrastSaturationBrightness (float3 color, float brt, float sat, float con) {
// Increase or decrease these values to
// adjust r, g and b color channels separately
float avgLumR = 0.5;
float avgLumG = 0.5;
float avgLumB = 0.5;
// Luminance coefficients for getting luminance from the image
float3 LuminanceCoeff = float3 (0.2125, 0.7154, 0.0721);
// Operation for brightmess
float3 avgLumin = float3 (avgLumR, avgLumG, avgLumB);
float3 brtColor = color * brt;
float intensityf = dot (brtColor, LuminanceCoeff);
float3 intensity = float3 (intensityf, intensityf, intensityf);
// Operation for saturation
float3 satColor = lerp (intensity, brtColor, sat);
// Operation for contrast
float3 conColor = lerp (avgLumin, satColor, con);
return conColor;
}
half4 frag (v2f i) : COLOR0
{
fixed4 renderTex = tex2D(_MainTex, i.uv);
// // Apply vertex color
// renderTex.rgb *= i.color.rgb; // 顶点色和贴图混合
// Apply the brightness, saturation, contrast operations
renderTex.rgb = ContrastSaturationBrightness (renderTex.rgb, _BrightnessAmount, _SaturationAmount, _ContrastAmount);
return renderTex;
}
ENDCG
}
}
FallBack "Diffuse"
}
Shader 之 顶点变形的更多相关文章
- Vertex And Fragment Shader(顶点和片段着色器)
Vertex And Fragment Shader(顶点和片段着色器) Shader "Unlit/ Vertex_And_Fragment_Shader " { Proper ...
- shader之顶点着色器
Vertex Shader 是渲染管道中一个可编程的模块,用于处理独立的顶点.Vertex Shader接收Vertex Attribute Data,由定点数组对象通过渲染指令来生成. Vertex ...
- [Unity Shader] 逐顶点光照和逐片元漫反射光照
书中的6.4节讲的是漫反射的逐顶点光照和逐片元光照. 前一种算法是根据漫反射公式计算顶点颜色(顶点着色器),对颜色插值(光栅化过程)返回每个像素的颜色值(片元着色器). 第二种算法是获得顶点的法线(顶 ...
- Cg入门14:Vertex Shader - 几何变换 —顶点扭曲
mul (UNITY_MATRIX_MVP,upPos): 參数说明 由第一个參数UNITY_MATRIX_MVP 矩阵去影响第二个參数upPos向量(或者矩阵) Shader "Sbin/ ...
- DX shader根据顶点设置颜色
matrix ViewProjMatrix; vector Blue = {0.0f, 0.0f, 1.0f, 0.0f}; struct VS_INPUT { vector position : P ...
- 【Unity Shader】一、顶点函数(vertex)和片元函数(fragment)
学习资料:http://www.sikiedu.com/course/37/task/430/show 学习Shader中顶点函数(vertex)和片元函数(fragment)的基本用法. Shade ...
- [翻译]利用顶点位移的VR畸变校正
文章英文原网址: http://www.gamasutra.com/blogs/BrianKehrer/20160125/264161/VR_Distortion_Correction_using_V ...
- Shader的语法
Shader "name" { [Properties] Subshaders [Fallback] }(1)Properties:{ Property [Property ... ...
- 利用顶点位移进行VR畸变校正
VR开发的最大挑战之一是对高帧率与高分辨率结合的要求.我们通过把顶点转化为“镜头空间”,删除了需要全屏渲染的纹理,这样就可以大规模提高手机性能. 下面的技术使用谷歌的Cardboard Unity S ...
随机推荐
- SPOJ375 Query on a tree
Description You are given a tree (an acyclic undirected connected graph) with N nodes, and edges num ...
- OC冒泡排序
NSMutableArray *p = [[NSMutableArray alloc] initWithObjects:@"3",@"5",@"4&q ...
- 电脑开启wifi功能
在Win7下,以管理员身份启动cmd,输入以下两条命令创建虚拟Wifi,并启动Wifi.其中ssid为WiFi的名字,key为密码.C:\>netsh wlan set hostednetwor ...
- CSS3-canvas绘制线性渐变
<!doctype html><html><head><meta charset="utf-8"><title>canv ...
- Excel_replace
有时候我们需要对单元格中的数据需要一些精确的处理,比如将部分以70开的工号升为706,这时简单的查找替换就不能满足我的需求,因为这样会替换掉工号中末尾或者中间位的70,造成工号的错误. 如何实现这种精 ...
- php函数ob_start()、ob_end_clean()、ob_get_contents()
下面3个函数的用法 ob_get_contents() - 返回输出缓冲区的内容 ob_flush() - 冲刷出(送出)输出缓冲区中的内容 ob_clean() - 清空(擦掉)输出缓冲区 ob_e ...
- openstack虚拟机启动过程
核心项目3个 1.控制台 服务名:Dashboard 项目名:Horizon 功能:web方式管理云平台,建云主机,分配网络,配安全组,加云盘 2.计算 服务名:计算 项目名:Nova 功能:负责响应 ...
- ctypes 操作 python 与 c++ dll 互传结构体指针
CMakeLists.txt # project(工程名) project(blog-3123958139-1) # add_library(链接库名称 SHARED 链接库代码) add_libra ...
- 关于linux发行版i386/i686/x86-64/的区别
http://blog.chinaunix.net/uid-20448327-id-172412.html
- yourphp 的 ThinkTemplate.class.php与ContentReplaceBehavior.class.php
ThinkTemplate.class.php :去掉版权(针对html代码) ContentReplaceBehavior.class.php:一些默认标签的路劲,如:__PUBLIC__,../P ...