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 ...
随机推荐
- oracle的resetlogs机制浅析(转)
文章转自:http://blog.csdn.net/wyzxg/article/details/5869543 alter database open resetlogs 这个命令我想大家都很熟悉了, ...
- install docker on xubuntu
ref: https://docs.docker.com/engine/installation/linux/ubuntulinux/#/install-the-latest-version ps: ...
- fedora22有时不能启动
[3.327871][drm:intel_set_pch_fifo_underrun_reporting [i915]] *ERROR* uncleared pch fifo underrun on ...
- A.Kaw矩阵代数初步学习笔记 5. System of Equations
“矩阵代数初步”(Introduction to MATRIX ALGEBRA)课程由Prof. A.K.Kaw(University of South Florida)设计并讲授. PDF格式学习笔 ...
- django写的留言板
代码见 https://github.com/linux-wang/show-me-the-code/tree/master/dj_test 实际上是 https://github.com/linux ...
- Redis 学习笔记续
Redis - 数据类型 Redis支持5种类型的数据类型,它描述如下的: 字符串 Redis字符串是字节序列.Redis字符串是二进制安全的,这意味着他们有一个已知的长度没有任何特殊字符终止,所以你 ...
- .net 运用YUI相关的dll压缩js (按照自己的规则,想想都觉得强大和有趣)
写在前面 不管是做前端的还是做后台的,不管是懂javaScript的还是不太懂JavaScript的人,我想都或多或想的知道些许js压缩对于页面性能提升的效应吧. 之前老喜欢用在线压缩工具去压缩js, ...
- JavaWeb---总结(十)JSP标签
一.JSP标签介绍 JSP标签也称之为Jsp Action(JSP动作)元素,它用于在Jsp页面中提供业务逻辑功能,避免在JSP页面中直接编写java代码,造成jsp页面难以维护. 二.JSP常用标签 ...
- OC description
description方法的作用是打印对象,对于一个类,如果没有重写description方法,NSLog(@“%@”,此处写类的对象), 输出的是该类的地址如下: -- :::] <Class ...
- [转发]Dumps of system information with Apple computers
In this article, I gathered up all the dumps, who found. If you see something new table will be upda ...