|
|
???????????????????????????????????????????????????????????unity??????????????????
?????????????????????????????????????????????????????????????????????????????????????????????
?????????????????????????????????????????????????????
????????ff7???????2?
????????????????????????????????????????????????????????????????????????????PBR??
????????????????
????RT???????
????????????????????
??????????????????????unity?????No tonemapping ?
???????????????
??????????????shader????
??????????????????
???????????
???????????????????2???
1???
??????????????
2???
????????????
???????????????
????????????????????????????????????????????????????????????????????????????????????
??????????Matcap?????????????????????????????PBR?ibl?????????
??Matcap
??MaterailCapture??????????????????????xy?????????????????????????wiki???
http://wiki.unity3d.com/index.php/MatCap
?????????????????????????????????????normal?????????2???????
- //MatCap ???
- half2 MatCapUV ;
- matCapUV.x = dot(UNITY_MATRIX_IT_MV[0].xyz,v.normal);
- matCapUV.y = dot(UNITY_MATRIX_IT_MV[1].xyz,v.normal);
- matCapUV = matCapUV * 0.5 + 0.5;
- //MatCap ???
- // float3 N = normalize(UnityObjectToWorldNormal(v.normal));
- // float3 viewPos = UnityObjectToViewPos(v.vertex);
- float2 MatCapUV (in float3 N,in float3 viewPos)
- {
- float3 viewNorm = mul((float3x3)UNITY_MATRIX_V, N);
- float3 viewDir = normalize(viewPos);
- float3 viewCross = cross(viewDir, viewNorm);
- viewNorm = float3(-viewCross.y, viewCross.x, 0.0);
- float2 matCapUV = viewNorm.xy * 0.5 + 0.5;
- return matCapUV;
- }
复制代码
????????????????VS????
????????????????????Matcap?????????????
???Matcap?????????Matcap??alpha???
- [HDR]_SpColor("Sp Color", Color) = (1.0,1.0,1.0,1.0)
- //?????????????????????
- float3 spmatCap= tex2D(_CapTex,matCapuv);
- spmatCap *=_SpColor.rgb
- o.color.rgb = spmatCap ;
- o.color.a = spmatCap .r;
复制代码
3.1 ????MASK
????????????????????????????????????
A.????????
??????????????????????????????????
?????????2?????????
1???????????
2?????????????
- float3 thicknessTex= tex2D(_MaskTex, i.uv);
- float sThickness = thicknessTex.r * i.color.r; //??????????
复制代码
???????R?????????????????
??????????????????
B.??????
????????????????
- _FenierEdge("Fenier Range", Range(-2, 2)) = 0.0
- _FenierIntensity("Fenier intensity", Range(0, 10)) = 2.0
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- float3 V = normalize(_WorldSpaceCameraPos - i.worldPos);
- float NoV = dot(N,V);
- float EdgeThickness (in float NoV)
- {
- float ET = saturate((NoV-_FenierEdge)*_FenierIntensity);
- return ET;
- }
复制代码
????????????????????
?????????????????????????????
- _FenierEdge("FenierRange", Range(-2, 2)) = 0.0
- _FenierIntensity("Fenierintensity", Range(0, 10)) = 2.0
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- float3 V = normalize(_WorldSpaceCameraPos - i.worldPos);
- float NoV = dot(N,V);
- float3 thicknessTex= tex2D(_MaskTex, i.uv) ;
- float sThickness = thicknessTex.r * i.color.r; //??????????
- float fThickness = thicknessTex.g;// ???????
- float EdgeThickness (in float NoV ,in float eThickness )
- {
- fThickness = (eThickness -0.5)*0.5;
- float ET = saturate((NoV-_FenierEdge+fThickness)*_FenierIntensity);
- return 1-ET*eThickness ;
- }
复制代码
3.2 ??????
??????matcap???????????UV??????????????????mask?????matcap??????????????matcap?????????????????????????????
- float Refintensity = Thickness*_Refintensity;
- float3 rfmatCap = tex2D(_RfCapTex,matCapuv+Refintensity);
- float3 rfmatColor= RFLerpColor(rfmatCap,Thickness)
- //_BaseColor??????????????????????????
- float3 RFLerpColor (in float3 rfmatCap,in float Thickness)
- {
- float3 c1 = _BaseColor.rgb*0.5;
- float3 c2 = rfmatCap*_BaseColor.rgb;
- float cMask = Thickness;
- return lerp(c1,c2,cMask ); //????? *v.color.rgb ????????????????????????
- }
复制代码
??????????????????????Mask ??alpha????????????????
??????????????????????????
- float alpha = saturate(max(spmatCap.r*_SpColor.a ,Thickness)*_BaseColor.a);
- //_SpColor ???????????????
- //alpha???????????????????????????????
- col.rgb = rfColor+spColor;//???????
- col.a = alpha;
复制代码
3.3 ??????
????????????????????????????????????????????????????
????? ??MASK ? Matcap??????? N(normal) ??? ?????????normalMap????????
- o.worldTangent =normalize(UnityObjectToWorldNormal(v.tangent));
- o.worldBinormal = cross(o.worldNorm, o.worldTangent) * v.tangent.w;
- o.uv.zw = TRANSFORM_TEX(v.texcoord.xy,_NormalTex) ;//(??????UV???????????
- ??????????????)
- o.uv.xy = TRANSFORM_TEX(v.texcoord.xy,_MaskTex) ;
- //------?VSout----------------------------------------------------------------------------------------------
- void GetNormal(v2f i, inout float3 N)
- {
- float4 normalTex = tex2D(_NormalTex, i.uv.zw);
- float3 normalTS = normalize(UnpackNormal(normalTex));
- float3x3 tbn = float3x3(i.worldTangent, i.worldBinormal, i.worldNorm);
- N = normalize(mul(normalTS, tbn));
- }
复制代码
PS???????????????????RT???????????????????????????
?????????????????????????????????
4.1 ????
???????Matcap??????????????Matcap?????Photoshop????????????
???IBL?Phone?GGX?????? ?????????????
4.2 ???????
???????????????????????
??????????????????????
?????????3????
?????????????????????????????????
???????1????????????????????? ?????????
???? ??????????????????????????????????mask?????????????
??????
???????????????????????????????????????
??????mask??????????????????????????????
????????????K????????UV????????????????????
??????
?????---?????????? RenderQueue ?????????-1????????????????????????????
???????????????RenderQueue?
?????3000???????2999???????2998?
????????????????????????????????????????????????????????????????????????
4.3 ???????
???????????????????????????????????????
??PBR???????
???????????LightProbes???????????????????????????
???Blood
?????GWB????
????https://mp.weixin.qq.com/s/-ukjq_pJqCCAYHQEcmzO3w
|
|