Hatching shader
Hatching Shader 是最初在NICONICO上看到的MME的效果( 手描き風シェーダー by ogugu )·前段時間把它改寫為了適合自己引擎的方式·
簡單的講它就是把預制的紋理和場景渲染的結果相互混合·
實作上Hatching Shader本體是個ImageProcess·其輸入除去場景的目標紋理·還需要UV紋理·和預制的Hatching紋理至少三張Texture2D·
這里指的UV紋理只是簡單的把模型變換后的TexCoord的兩個值寫入到紋理的RG通道就可以了·
?
Hatching Shader的計算和Hatching紋理本體是相關的·(這里依舊使用的ogugu的4*4一共16個層級的格式)
float4 t_OrgColor = SceneMap.Sample( SceneMapSampler, i_TexCoord ); const float t_Luminous = dot( float3( 0.29891f, 0.58661f, 0.11448f ), t_OrgColor.rgb ); //亮度值const int t_Index = min( 15.f, t_Luminous * 16.f );const float t_Weight = frac( t_Luminous * 16.f );? 首先計算原本場景的亮度值·然后計算對應到HatchingMap的十六個等級·和后面需要用到的權重·
const float2 t_UV = UVMap.Sample( UVMapSampler, i_TexCoord ).rg;float t_f0 = HatchingMap.Sample( HatchingSampler, 0.25f * ( frac( t_UV * float2(-1.f,1.f) * s_TileRepeat) +float2( 3.f - t_Index % 4, t_Index / 4 ) ) ).r;const int t_UIndex = t_Index + 1;float t_f1 = 1.f; //限界值if( t_UIndex < 16 ){t_f1 = HatchingMap.Sample( HatchingSampler, 0.25f * ( frac( t_UV * float2(-1.f,1.f) * s_TileRepeat) + float2( 3.f - t_UIndex % 4, t_UIndex / 4 ))).r;}const float t_f = lerp( t_f0, t_f1, t_Weight );float3 t_Color = lerp( t_OrgColor.rgb, s_WhiteLineColor, t_f );float4 o_OutColor = float4( lerp( t_OrgColor.rgb, t_Color, s_Mixture ), t_OrgColor.a);?然后通過UVMap來計算HatchingMap所對應的位置(UV決定X軸,亮度決定Y軸)·最后通過插值(其實這里想怎么弄都可以)得到最終的輸出顏色···
(這里s_TileRepeat是HatchingMap的重復周期·s_Mixture為最終混合權重·)
?
更換不同的HatchingMap可以得到不同的效果·
(人物模型為 機巧少女TV官方配布的 yeye, 背景模型為 天界 )
轉載于:https://www.cnblogs.com/macom/p/3423819.html
總結
以上是生活随笔為你收集整理的Hatching shader的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 37. DDR2内存内部结构-6
- 下一篇: 敏感词过滤及反垃圾文本的相关知识(欢迎收