eye.effect 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. // Copyright (c) 2017-2022 Xiamen Yaji Software Co., Ltd.
  2. CCEffect %{
  3. techniques:
  4. - name: opaque
  5. passes:
  6. - vert: standard-vs
  7. frag: standard-fs
  8. properties: &props
  9. occlusion: { value: 1.0, target: pbrParams.x, editor: { slide: true, range: [0, 1.0], step: 0.001 } }
  10. roughness: { value: 0.07, target: pbrParams.y, editor: { slide: true, range: [0, 1.0], step: 0.001 } }
  11. metallic: { value: 0.0, target: pbrParams.z, editor: { slide: true, range: [0, 1.0], step: 0.001 } }
  12. specularIntensity: { value: 1.0, target: pbrParams.w, editor: { slide: true, range: [0.0, 1.0], step: 0.001 } }
  13. normalStrength: { value: 1.0, target: emissiveScaleParam.w, editor: { parent: USE_NORMAL_MAP, slide: true, range: [0, 5.0], step: 0.001 } }
  14. mainTexture: { value: grey, target: albedoMap, editor: { displayName: ScleraColorMap, tooltip: 'T_Sclera_D' } }
  15. normalMap: { value: normal, editor: { displayName: ScleraNormalMap, tooltip: 'T_Sclera_N' } }
  16. occlusionMap: { value: white }
  17. irisGradientMap: { value: white, editor: { tooltip: 'T_Eye_Gradient' } }
  18. irisColorMaskMap: { value: black, editor: { tooltip: 'T_Iris_A_M' } }
  19. veinsColorMap: { value: black, editor: { tooltip: 'T_Veins_D' } }
  20. irisNormalMap: { value: normal, editor: { parent: USE_IRIS_REFRACTION, tooltip: 'normalMap with conreal shape like T_Eye_N' } }
  21. irisHeightMap: { value: black, editor: { tooltip: 'T_EyeMidPlaneDisplacement' } }
  22. irisHeightMapAlpha: { value: black, editor: { tooltip: 'T_EyeMidPlaneDisplacement Alpha Channel' } }
  23. irisHeightScale: { value: 1.0, target: irisParams.x, editor: { parent: USE_IRIS_REFRACTION, slide: true, range: [0, 5.0], step: 0.001 } }
  24. irisScale: { value: 0.5, target: irisParams.z, editor: { slide: true, range: [0, 1.0], step: 0.001 } }
  25. pupilScale: { value: 1.0, target: irisParams.w, editor: { slide: true, range: [1.0, 3.0], step: 0.001 } }
  26. veinsBleeding: { value: 1.5, target: irisParams.y, editor: { slide: true, range: [0.0, 3.0], step: 0.001 } }
  27. irisMainColor: { value: 0.8, target: irisColorParams.x, editor: { slide: true, range: [0.0, 1.0], step: 0.001 } }
  28. irisMainBright: { value: 1.0, target: irisColorParams.y, editor: { slide: true, range: [0.0, 5.0], step: 0.001 } }
  29. irisEdgeColor: { value: 0.5, target: irisColorParams.z, editor: { slide: true, range: [0.0, 1.0], step: 0.001 } }
  30. irisEdgeBright: { value: 1.0, target: irisColorParams.w, editor: { slide: true, range: [0.0, 5.0], step: 0.001 } }
  31. reflectionEnhancement: { value: 1.5, target: emissiveScaleParam.x, editor: { slide: true, range: [1.0, 3.0], step: 0.001 } }
  32. scleraBright: { value: 1.0, target: emissiveScaleParam.y, editor: { slide: true, range: [0.0, 1.0], step: 0.001 } }
  33. causticsPosition: { value: 0.3, target: causticsParams.x, editor: { parent: USE_IRIS_CAUSTICS, slide: true, range: [0.0, 1.0], step: 0.001 } }
  34. causticsWidth: { value: 0.3, target: causticsParams.y, editor: { parent: USE_IRIS_CAUSTICS, slide: true, range: [0.0, 1.0], step: 0.001 } }
  35. causticsIntensity: { value: 1.0, target: causticsParams.w, editor: { parent: USE_IRIS_CAUSTICS, slide: true, range: [0.0, 3.0], step: 0.001 } }
  36. - &forward-add
  37. vert: standard-vs
  38. frag: standard-fs
  39. phase: forward-add
  40. propertyIndex: 0
  41. embeddedMacros: { CC_FORWARD_ADD: true }
  42. depthStencilState:
  43. depthFunc: equal
  44. depthTest: true
  45. depthWrite: false
  46. blendState:
  47. targets:
  48. - blend: true
  49. blendSrc: one
  50. blendDst: one
  51. blendSrcAlpha: zero
  52. blendDstAlpha: one
  53. - &shadow-caster
  54. vert: shadow-caster-vs
  55. frag: shadow-caster-fs
  56. phase: shadow-caster
  57. propertyIndex: 0
  58. rasterizerState:
  59. cullMode: front
  60. properties:
  61. mainTexture: { value: grey, target: albedoMap, editor: { displayName: AlbedoMap } }
  62. - &reflect-map
  63. vert: standard-vs
  64. frag: reflect-map-fs
  65. phase: reflect-map
  66. propertyIndex: 0
  67. - &deferred-forward
  68. vert: standard-vs
  69. frag: standard-fs
  70. phase: deferred-forward
  71. propertyIndex: 0
  72. - name: transparent
  73. passes:
  74. - vert: standard-vs
  75. frag: standard-fs
  76. embeddedMacros: { CC_FORCE_FORWARD_SHADING: true }
  77. depthStencilState: &d1
  78. depthTest: true
  79. depthWrite: false
  80. blendState: &b1
  81. targets:
  82. - blend: true
  83. blendSrc: src_alpha
  84. blendDst: one_minus_src_alpha
  85. blendDstAlpha: one_minus_src_alpha
  86. properties: *props
  87. - *forward-add
  88. - *shadow-caster
  89. - &deferred-forward-transparent
  90. vert: standard-vs
  91. frag: standard-fs
  92. phase: deferred-forward
  93. embeddedMacros: { CC_PIPELINE_TYPE: 0 }
  94. depthStencilState: *d1
  95. blendState: *b1
  96. propertyIndex: 0
  97. }%
  98. CCProgram shared-ubos %{
  99. uniform Constants {
  100. vec4 pbrParams;
  101. vec4 emissiveScaleParam;
  102. vec4 irisParams;
  103. vec4 irisColorParams;
  104. vec4 causticsParams;
  105. };
  106. }%
  107. CCProgram macro-remapping %{
  108. // depend on UI macros
  109. #if USE_NORMAL_MAP
  110. #define CC_SURFACES_USE_TANGENT_SPACE 1
  111. #endif
  112. }%
  113. CCProgram surface-vertex %{
  114. out vec4 v_planeN;
  115. out vec4 v_planeT;
  116. #define CC_SURFACES_VERTEX_MODIFY_LOCAL_SHARED_DATA
  117. void SurfacesVertexModifyLocalSharedData(inout SurfacesStandardVertexIntermediate In)
  118. {
  119. mat4 matWorld, matWorldIT;
  120. CCGetWorldMatrixFull(matWorld, matWorldIT);
  121. v_planeN.xyz = normalize((matWorldIT * vec4(0.0, 0.0, 1.0, 0.0)).xyz); // meta human exported mesh is facing to Z-Axis
  122. v_planeT.xyz = normalize((matWorldIT * vec4(1.0, 0.0, 0.0, 0.0)).xyz);
  123. v_planeN.w = v_planeT.w = 1.0;
  124. }
  125. }%
  126. CCProgram surface-fragment %{
  127. uniform sampler2D albedoMap;
  128. #if USE_NORMAL_MAP
  129. uniform sampler2D normalMap;
  130. #endif
  131. #if USE_OCCLUSION_MAP
  132. uniform sampler2D occlusionMap;
  133. #endif
  134. ////////////////////////////////////////////////////////////////User Define
  135. in vec4 v_planeN;
  136. in vec4 v_planeT;
  137. #if USE_IRIS_REFRACTION
  138. uniform sampler2D irisNormalMap;
  139. #endif
  140. uniform sampler2D irisHeightMap;
  141. uniform sampler2D irisHeightMapAlpha;
  142. uniform sampler2D irisColorMaskMap;
  143. uniform sampler2D irisGradientMap;
  144. uniform sampler2D veinsColorMap;
  145. #define CC_SURFACES_FRAGMENT_MODIFY_WORLD_NORMAL
  146. vec3 SurfacesFragmentModifyWorldNormal()
  147. {
  148. vec3 normal = FSInput_worldNormal;
  149. #if USE_NORMAL_MAP
  150. vec3 nmmp = texture(normalMap, FSInput_texcoord).xyz - vec3(0.5);
  151. normal = CalculateNormalFromTangentSpace(nmmp, emissiveScaleParam.w, normalize(normal.xyz), normalize(FSInput_worldTangent), FSInput_mirrorNormal);
  152. #endif
  153. return normalize(normal);
  154. }
  155. #define CC_SURFACES_FRAGMENT_MODIFY_PBRPARAMS
  156. vec4 SurfacesFragmentModifyPBRParams()
  157. {
  158. vec4 pbr = pbrParams;
  159. pbr.x = 1.0;
  160. #if USE_OCCLUSION_MAP
  161. pbr.x = mix(1.0, texture(occlusionMap, FSInput_texcoord).r, pbrParams.x);
  162. #endif
  163. return pbr;
  164. }
  165. #include <common/texture/texture-misc>
  166. #include <common/lighting/functions>
  167. #include <eye>
  168. #define CONREAL_IOR 1.336
  169. vec2 GetEllipseRefractionOffset(vec3 planeN, vec3 planeT, vec3 planeB, vec3 conrealNormal, vec3 refractDir, float height)
  170. {
  171. float NoR = dot(conrealNormal, -refractDir);
  172. float lenR = height / max(NoR, EPSILON_LOWP);
  173. vec3 refract = refractDir * lenR;
  174. // project R onto plane UV space, -B for Y -> V dir correction
  175. return vec2(dot(refract, planeT), dot(refract, -planeB));
  176. }
  177. // definition of SurfacesMaterialData structure with corresponding shading-model
  178. #include <surfaces/data-structures/standard>
  179. //see <surfaces/default-functions/XXXX> for more overrided functions, XXXX is shading-model name
  180. #define CC_SURFACES_FRAGMENT_MODIFY_SHARED_DATA
  181. void SurfacesFragmentModifySharedData(inout SurfacesMaterialData surfaceData)
  182. {
  183. vec3 worldPos;
  184. HIGHP_VALUE_FROM_STRUCT_DEFINED(worldPos, surfaceData.worldPos);
  185. float irisHeightScale = irisParams.x;
  186. float IrisUVRadius = irisParams.z * 2.0; // default is 0.5
  187. float PupilScale = irisParams.w;
  188. float VeinsPower = irisParams.y;
  189. float IrisColor1U = irisColorParams.x; // default is 0.8 for asian
  190. float IrisColor2U = irisColorParams.z; // default is 0.5 for asian
  191. float IrisColor1Bright = irisColorParams.y;
  192. float IrisColor2Bright = irisColorParams.w;
  193. float scleraBright = emissiveScaleParam.y;
  194. vec3 scleraTintColor = vec3(1.0);
  195. vec3 viewDir = normalize(cc_cameraPos.xyz - worldPos);
  196. // vec2 irisUV = (FSInput_texcoord - vec2(0.5)) / IrisScale + vec2(0.5);
  197. // if (irisUV.x > 0.0 && irisUV.y > 0.0 && irisUV.x < 1.0 && irisUV.y < 1.0)
  198. // Iris Mask with Limbus Ring falloff
  199. vec3 out_IrisUVMask = GetIrisUVMask(IrisUVRadius);
  200. // Refraction
  201. vec2 out_RefractedUV = FSInput_texcoord;
  202. #if USE_IRIS_REFRACTION
  203. float texHeight = SampleTextureExr(irisHeightMap, FSInput_texcoord).x;
  204. float height = texHeight * irisHeightScale;
  205. vec3 irisN = normalize(FSInput_worldNormal);
  206. vec3 R = CalculateRefractDirection(irisN, viewDir, dot(irisN, viewDir), CONREAL_IOR);
  207. vec3 receivePlaneN = v_planeN.xyz;
  208. vec3 receivePlaneT = v_planeT.xyz;
  209. vec3 receivePlaneB = CalculateBinormal(receivePlaneN, receivePlaneT, 1.0);
  210. vec2 uv_offset = GetEllipseRefractionOffset(receivePlaneN, receivePlaneT, receivePlaneB, irisN, normalize(R), height);
  211. out_RefractedUV = saturate(FSInput_texcoord + uv_offset /** texHeight*/ * 0.1); //需要边缘位移稍微小一点的话就加texHeight
  212. #endif
  213. // scaling pupil
  214. vec2 out_IrisUV = GetIrisUV(out_RefractedUV, IrisUVRadius, PupilScale);
  215. // generating iris color
  216. vec3 out_IrisGeneratedColor = GetGeneratedColorForIris(out_IrisUV, irisColorMaskMap, IrisColor1U, IrisColor2U, IrisColor1Bright, IrisColor2Bright);
  217. // blend iris and sclera use IrisMask
  218. surfaceData.baseColor.rgb = GetBlendColorForIrisAndSclera(out_IrisUVMask, out_IrisGeneratedColor, irisHeightMapAlpha, albedoMap, veinsColorMap, scleraTintColor, VeinsPower, scleraBright);
  219. // flatterned normal for iris area
  220. surfaceData.worldNormal = normalize(lerp(surfaceData.worldNormal, FSInput_worldNormal, out_IrisUVMask.r));
  221. // iris area flag (UVMask) and attenuation for caustics
  222. // irisUVMask area is a little bit larger than irisGeneratedColor
  223. float irisAttenuation = saturate(out_IrisUVMask.r * length(out_IrisGeneratedColor) * 10.0);
  224. surfaceData.ior = irisAttenuation;
  225. surfaceData.emissive = out_IrisUVMask;
  226. }
  227. // see <lighting-models/default-functions/XXXX> for more overrided functions, XXXX is lighting-model name
  228. #include <lighting-models/includes/standard>
  229. #define CC_SURFACES_LIGHTING_MODIFY_FINAL_RESULT
  230. void SurfacesLightingModifyFinalResult(inout LightingResult result, in LightingIntermediateData lightingData, in SurfacesMaterialData surfaceData, in LightingMiscData miscData)
  231. {
  232. #if USE_IRIS_REFRACTION
  233. vec3 worldPos;
  234. HIGHP_VALUE_FROM_STRUCT_DEFINED(worldPos, surfaceData.worldPos);
  235. vec3 L = lightingData.L;
  236. vec3 viewDir = normalize(cc_cameraPos.xyz - worldPos);
  237. LightingIntermediateData lightingDataRefract = lightingData;
  238. vec3 newL = -CalculateRefractDirection(surfaceData.worldNormal, L, dot(surfaceData.worldNormal, L), CONREAL_IOR);
  239. CCSurfacesLightingGetIntermediateData_PerLight(lightingDataRefract, newL);
  240. if (surfaceData.emissive.x > 0.0) {
  241. result.directSpecular = CalculateDirectSpecular(lightingDataRefract, miscData.lightColorAndIntensity);
  242. #if !CC_FORWARD_ADD
  243. lightingDataRefract.V = -CalculateRefractDirection(surfaceData.worldNormal, viewDir, dot(surfaceData.worldNormal, viewDir), CONREAL_IOR);
  244. result.environmentSpecular = CalculateEnvironmentSpecular(lightingDataRefract, cc_ambientSky.w);
  245. #endif
  246. }
  247. #endif
  248. // enhanced more contrast for brighter part
  249. result.environmentSpecular = pow(result.environmentSpecular, vec3(emissiveScaleParam.x));
  250. #if USE_SCLERA_SSS
  251. LightingIntermediateData lightingData3S = lightingData;
  252. lightingData3S.N = normalize(FSInput_worldNormal);
  253. CCSurfacesLightingGetIntermediateData_PerLight(lightingData3S, lightingData.L);
  254. result.directDiffuse = CalculateDirectDiffuse(lightingData3S, miscData.lightColorAndIntensity);
  255. #endif
  256. #if USE_IRIS_CAUSTICS
  257. vec3 receivePlaneN = v_planeN.xyz;
  258. vec3 receivePlaneT = v_planeT.xyz;
  259. vec3 receivePlaneB = CalculateBinormal(receivePlaneN, receivePlaneT, 1.0);
  260. // conreal back face normal has inverse projector dir with plane T B
  261. float projectorN = dot(surfaceData.worldNormal, receivePlaneN);
  262. float projectorT = dot(surfaceData.worldNormal, receivePlaneT);
  263. float projectorB = dot(surfaceData.worldNormal, receivePlaneB);
  264. vec3 backN = normalize(projectorN * receivePlaneN - projectorT * receivePlaneT - projectorB * receivePlaneB);
  265. LightingIntermediateData lightingDataCaustics = lightingData;
  266. lightingDataCaustics.N = backN;
  267. CCSurfacesLightingGetIntermediateData_PerLight(lightingDataCaustics, lightingData.L);
  268. float causticsIntensity = causticsParams.w;
  269. float irisMaskAttenuation = surfaceData.ior;
  270. #if USE_IRIS_CAUSTICS_RANGE
  271. // rangeFilter results according to UV distribution, 5.0 can be modified to match different UVs
  272. float uvLength = saturate(length(FSInput_texcoord - vec2(0.5)) * 5.0);
  273. float start = causticsParams.x, end = saturate(start + causticsParams.y), widthAtten = 0.2;
  274. float rangeFilter = saturate(smoothstep(start, end, uvLength)) * (1.0 - saturate(smoothstep(end, saturate(end + widthAtten), uvLength)));
  275. // rangeFilter can be ignored
  276. irisMaskAttenuation *= rangeFilter;
  277. #endif
  278. vec3 directCaustics = vec3(pow(lightingDataCaustics.NoLSat, 10.0)) * 2.0;
  279. result.directDiffuse += directCaustics * causticsIntensity * irisMaskAttenuation * miscData.lightColorAndIntensity.rgb * miscData.lightColorAndIntensity.w;
  280. #if !CC_FORWARD_ADD
  281. vec3 envCaustics = CalculateEnvironmentDiffuse(lightingDataCaustics, 1.0);
  282. envCaustics = pow(envCaustics, vec3(4.0)) * 0.5;
  283. result.environmentDiffuse += envCaustics * causticsIntensity * irisMaskAttenuation * cc_ambientSky.w;
  284. #endif
  285. #endif
  286. // restore emissive
  287. result.emissive = vec3(0.0);
  288. }
  289. }%
  290. CCProgram standard-vs %{
  291. precision highp float;
  292. // 1. surface internal macros, for technique usage or remapping some user (material) macros to surface internal macros
  293. #include <macro-remapping>
  294. #include <surfaces/effect-macros/common-macros>
  295. // 2. common include with corresponding shader stage, include before surface functions
  296. #include <surfaces/includes/common-vs>
  297. // 3. user surface functions that can use user (effect) parameters (ubo Constants)
  298. // see surfaces/default-functions/xxx.chunk
  299. #include <shared-ubos>
  300. #include <surface-vertex>
  301. // 4. surface include with corresponding shader stage and shading-model (optional)
  302. #include <surfaces/includes/standard-vs>
  303. // 5. shader entry with corresponding shader stage and technique usage/type
  304. #include <shading-entries/main-functions/render-to-scene/vs>
  305. }%
  306. CCProgram shadow-caster-vs %{
  307. precision highp float;
  308. #include <macro-remapping>
  309. #include <surfaces/effect-macros/render-to-shadowmap>
  310. #include <surfaces/includes/common-vs>
  311. #include <shared-ubos>
  312. #include <surface-vertex>
  313. #include <shading-entries/main-functions/render-to-shadowmap/vs>
  314. }%
  315. CCProgram standard-fs %{
  316. // shading-model : standard
  317. // lighting-model : standard (isotropy / anisotropy pbr)
  318. // shader stage : fs
  319. // technique usage/type : render-to-scene
  320. precision highp float;
  321. // 1. surface internal macros, for technique usage or remapping some user (material) macros to surface internal macros
  322. #include <macro-remapping>
  323. #include <surfaces/effect-macros/common-macros>
  324. // 2. common include with corresponding shader stage, include before surface functions
  325. #include <surfaces/includes/common-fs>
  326. // 3. user surface functions that can use user (effect) parameters (ubo Constants)
  327. // see surfaces/default-functions/xxx.chunk
  328. #include <shared-ubos>
  329. #include <surface-fragment>
  330. // 4. lighting-model (optional)
  331. #include <lighting-models/includes/standard>
  332. // 5. surface include with corresponding shader stage and shading-model (optional)
  333. #include <surfaces/includes/standard-fs>
  334. // 6. shader entry with corresponding shader stage and technique usage/type
  335. #include <shading-entries/main-functions/render-to-scene/fs>
  336. }%
  337. CCProgram shadow-caster-fs %{
  338. precision highp float;
  339. #include <macro-remapping>
  340. #include <surfaces/effect-macros/render-to-shadowmap>
  341. #include <surfaces/includes/common-fs>
  342. #include <shared-ubos>
  343. #include <surface-fragment>
  344. #include <shading-entries/main-functions/render-to-shadowmap/fs>
  345. }%
  346. CCProgram reflect-map-fs %{
  347. precision highp float;
  348. #include <macro-remapping>
  349. #include <surfaces/effect-macros/common-macros>
  350. #include <surfaces/includes/common-fs>
  351. #include <shared-ubos>
  352. #include <surface-fragment>
  353. #include <lighting-models/includes/standard>
  354. #include <surfaces/includes/standard-fs>
  355. #include <shading-entries/main-functions/render-to-reflectmap/fs>
  356. }%