NPR-Hatching素描渲染
来源:互联网 发布:forge软件 编辑:程序博客网 时间:2024/06/02 12:58
Hatching(素描)渲染——通过光照的强弱,用不同深浅的纹理,实现一种类似素描效果。
Hatching的实现原理是:通过N.L计算点受光的强弱,将该值分成不同的段,不同的光照强度对应不同深浅的素描贴图
算法对应的VS如下:
[cpp] view plaincopy
- VS_OUTPUT vs_main( VS_INPUT Input )
- {
- VS_OUTPUT Output;
- Output.Position = mul( Input.Position, matViewProjection );
- Output.Texcoord = Input.Texcoord;
- float3 normalW = mul( Input.Normal, matView);
- float diffuse = min( 1, max(0, dot( vecLightDir, normalW)));
- //把diffuse平方两次是为了,把亮度降低点,把整体亮度向暗方向偏移,以得到更好的视觉效果。
- diffuse = diffuse * diffuse;
- diffuse = diffuse * diffuse;
- float factor = diffuse * 6.0;
- // 通过两个weight,来记录权值,减少传入ps的变量数。
- float3 weight0 = 0.0;
- float3 weight1 = 0.0;
- // 不同光照强度,对应不同的权值,及不同的纹理贴图
- if( factor > 5.0)
- {
- weight0.x = 1;
- }
- else if( factor > 4.0)
- {
- weight0.x = factor - 4.0;
- weight0.y = 1.0 - weight0.x;
- }
- else if( factor > 3.0)
- {
- weight0.y = factor - 3.0;
- weight0.z = 1.0 - weight0.y;
- }
- else if( factor > 2.0)
- {
- weight0.z = factor - 2.0;
- weight1.x = 1.0 - weight0.z;
- }
- else if( factor > 1.0)
- {
- weight1.x = factor - 1.0;
- weight1.y = 1.0 - weight1.x;
- }
- else if( factor > 0.0)
- {
- weight1.y = factor;
- weight1.z = 1.0 - weight1.y;
- }
- Output.Weight0 = weight0;
- Output.Weight1 = weight1;
- return( Output );
- }
PS为:
[c-sharp] view plaincopy
- struct PS_INPUT
- {
- float2 tex : TEXCOORD0;
- float3 weight0 : TEXCOORD1;
- float3 weight1 : TEXCOORD2;
- };
- float4 ps_main( PS_INPUT input) : COLOR0
- {
- float4 hattch0 = tex2D(hattch0Map, input.tex)*input.weight0.x;
- float4 hattch1 = tex2D(hattch1Map, input.tex)*input.weight0.y;
- float4 hattch2 = tex2D(hattch2Map, input.tex)*input.weight0.z;
- float4 hattch3 = tex2D(hattch3Map, input.tex)*input.weight1.x;
- float4 hattch4 = tex2D(hattch4Map, input.tex)*input.weight1.y;
- float4 hattch5 = tex2D(hattch5Map, input.tex)*input.weight1.z;
- return hattch0 + hattch1 + hattch2
- + hattch3 + hattch4 + hattch5;
- }
最终效果
0 0
- NPR-Hatching素描渲染
- NPR技术(2)—Hatching 素描渲染
- NPR-卡通渲染
- 【NPR】卡通渲染
- 【NPR】非真实感渲染实验室
- 【NPR】非真实感渲染实验室
- 【NPR】非真实感渲染实验室
- 【NPR】漫谈轮廓线的渲染
- 【NPR】Unity3D非真实感渲染----铅笔画滤镜
- 非真实渲染技术(NPR)-1.卡通渲染
- WebGL+shader实现素描效果渲染
- 素描
- 素描
- 素描
- 素描
- 简易NPR
- 【NPR】铅笔画
- Unity Shader 学习笔记(27)渲染轮廓线(描边)方法、卡通风格渲染、素描风格渲染
- 流量劫持是如何产生的?
- OpenCV(三) 关于图片的存储
- .NET Observer模式
- HTML标签转义问题
- 安装Kienct驱动后出现"no ready kinect found" 解决方案
- NPR-Hatching素描渲染
- /etc/rc.d/与/etc/rc.d/init.d的关系 (转)
- How to: Manage CBO Statistics During an Upgrade from 10g or 9i into 11g (文档 ID 465787.1)
- 声音的强度
- SDImageCache手动清除缓存
- android GridView加载图片,一张张显示
- dxhjdfjdfg
- SOPC开发中软件开发工具:Nios II IDE 与 Nios II SBT for Eclipse的区别
- hibernate hql case when 子查询报java.lang.NullPointerException错误