这是一个能让平面呈现出曲面效果的Shaer。

代码:

Shader "Custom/CurvedWorld"{
Properties {
// Diffuse texture
_MainTex ("Base (RGB)", 2D) = "white" {}
// Degree of curvature
_Curvature ("Curvature", Float) = 0.001
// Axis Around which the curvature is required
_Axis ("Axis", int ) = 2 }
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200 CGPROGRAM
// Surface shader function is called surf, and vertex preprocessor function is called vert
// addshadow used to add shadow collector and caster passes following vertex modification
#pragma surface surf Lambert vertex:vert addshadow // Access the shaderlab properties
uniform sampler2D _MainTex;
uniform float _Curvature;
uniform int _Axis; // Basic input structure to the shader function
// requires only a single set of UV texture mapping coordinates
struct Input {
float2 uv_MainTex;
}; // This is where the curvature is applied
void vert( inout appdata_full v)
{
// Transform the vertex coordinates from model space into world space
float4 vv = mul( _Object2World, v.vertex ); // Now adjust the coordinates to be relative to the camera position
vv.xyz -= _WorldSpaceCameraPos.xyz; // Reduce the y coordinate (i.e. lower the “height”) of each vertex based
// on the square of the distance from the camera in the z axis, multiplied
// by the chosen curvature factor
if(_Axis == 0)
vv = float4( 0.0f, (vv.x * vv.x) *_Curvature, 0.0f, 0.0f );
else if(_Axis == 1)
vv = float4( 0.0f, (vv.y * vv.y) * _Curvature, 0.0f, 0.0f );
else if(_Axis == 2)
vv = float4( 0.0f, (vv.z * vv.z) * _Curvature, 0.0f, 0.0f ); // Now apply the offset back to the vertices in model space
v.vertex += mul(_World2Object, vv);
} // This is just a default surface shader
void surf (Input IN, inout SurfaceOutput o) {
half4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
// FallBack “Diffuse”
}

  效果图:

不同角度有不同效果:

曲面Shader的更多相关文章

  1. OpenGL 4.0的Tessellation Shader(细分曲面着色器)

    细分曲面着色器(Tessellation Shader)处于顶点着色器阶段的下一个阶段,我们可以看以下链接的OpenGL渲染流水线的图:https://www.opengl.org/wiki/Rend ...

  2. 解读Unity中的CG编写Shader系列三

    转自http://www.itnose.net/detail/6096068.html 在上一个例子中,我们得到了由mesh组件传递的信息经过数学转换至合适的颜色区间以颜色的形式着色到物体上.这篇文章 ...

  3. Unity Shader入门基础(一)

    渲染流水线   一.渲染流水线 渲染流水线的工作任务在于由一个三维场景出发.生存(或者说渲染)一张二维图像.换句话说,计算机需要从一系列的顶点数据.纹理等信息出发,把这些信息最终转换成一张人眼可以看到 ...

  4. Unity shader(CG) 写一个 散色、折射、反射、菲涅尔、gamma、简单后期屏幕特效

    http://www.lai18.com/content/506918.html 1.自生要求是很重要的,当然不是什么强迫工作之类的,而是自己有限的能力上不断的扩展兴趣上的内容. 2.用生活的眼光去发 ...

  5. Unity3d 使用DX11的曲面细分

    Unity3d surface Shaderswith DX11 Tessellation Unity3d surface shader 在DX11上的曲面细分 I write this articl ...

  6. Unity Shader 知识点总结(一)

    在学习了一段时间的Unity Shader后,打算写一些知识总结,便于今后的查找.如有错误,希望大家指出更改. 本文参照的unity入门精要一书,做一个知识归纳,如有兴趣可以看看其开源的部分,是一本比 ...

  7. Unity Shader入门精要读书笔记(一)序章

    本系列的博文是笔者读<Unity Shader入门精要>的读书笔记,这本书的章节框架是: 第一章:着手准备. 第二章:GPU流水线. 第三章:Shader基本语法. 第四章:Shader数 ...

  8. Shader 入门笔记(二) CPU和GPU之间的通信,渲染流水线

    渲染流水线 1)应用阶段(CPU处理) 首先,准备好场景数据(摄像机位置,视锥体,模型和光源等) 接着,做粗粒度剔除工作. 最后,设置好每个模型的渲染状态(使用的材质,纹理,shader等) 这一阶段 ...

  9. Unity shader 官网文档全方位学习(二)

    摘要: 这篇文章主要介绍Lighting model及自定义Lighting model 上文咱们学了surface shader.这玩意在开始的时候啊,在定义哪个函数处理surface时用一定要指定 ...

随机推荐

  1. 《Junit实战》读书笔记

    核心原则:任何没有经过自动测试的程序功能都可以当做不存在 单元测试框架的大三规则: 1.每个单元测试都必须独立于其他所有单元测试而运行 2.框架应该以单个测试为单元来检测和报告错误 3.应该易于定义要 ...

  2. AngularJS的使用方法

    1.第一个ng demo <div ng-app="" ng-init="name='Kevin'"> <input ng-model=&qu ...

  3. SGU 194 Reactor Cooling Dinic求解 无源无汇有上下界的可行流

    题目链接 题意:有向图中有n(1 <= n <= 200)个点,无自环或者环的节点个数至少为3.给定每条边的最小流量和最大流量,问每条边的可行流量为多少? 思路:一般求解的网络流并不考虑下 ...

  4. c语言贪吃蛇

    思路:函数gotoxy(x,y)使光标移植屏幕的x,y坐标(屏幕左上角为0,0),用来绘制蛇和界面,color()函数用来设置绘制的颜色.设有snakelong节,第i节蛇的x坐标为x[i],y坐标为 ...

  5. Ubuntu启动停止在checking battery state...

    Ubuntu在“checking battery state...”处停止了,出现这种现象的原因可能有很多种.笔者遇到的是其中的一种. 情景描述: 笔者此前将Ubuntu的图形启动方式修改为了字符界面 ...

  6. js为链接绑定点击事件并且附带return false;来阻止跳转

    <!DOCTYPE HTML> <html> <head> <meta charset="gb2312" /> <title& ...

  7. ECSHOP安装或使用中提示Strict Standards: Non-static method cls_image:

    随着ECSHOP的不断发展,越来越多的人成为了ECSHOP的忠实粉丝.由于每个人的服务器环境和配置都不完全相同,所以ECSHOP也接二连三的爆出了各种各样的错误信息.相信不少新手朋友在ECSHOP安装 ...

  8. oracle----修改表中的数据

    1. 修改表中的数据:UPDATE语句: 语法: UPDTAE table_name SET column1 = value1,... [WHERE conditions] (2),无条件的更新(没有 ...

  9. XSS之学习误区分析

    有段时间没写东西了, 最近看到zone里出现了很多“XSS怎么绕过某某符号的帖子”,觉得很多新手在寻找XSS时走进了一些误区,比如:专门想着怎么去“绕过”.这里做个总结,希望对大家有所帮助. 1. 误 ...

  10. php多线程thread开发与应用的例子

    Php多线程的使用,首先需要PHP5.3以上版本,并安装pthreads PHP扩展,可以使PHP真正的支持多线程,扩展如何安装请自行百度 PHP扩展下载:https://github.com/kra ...