default.fragment.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. // Do not edit.
  2. import { ShaderStore } from "../Engines/shaderStore.js";
  3. import "./ShadersInclude/defaultFragmentDeclaration.js";
  4. import "./ShadersInclude/defaultUboDeclaration.js";
  5. import "./ShadersInclude/prePassDeclaration.js";
  6. import "./ShadersInclude/oitDeclaration.js";
  7. import "./ShadersInclude/mainUVVaryingDeclaration.js";
  8. import "./ShadersInclude/helperFunctions.js";
  9. import "./ShadersInclude/lightFragmentDeclaration.js";
  10. import "./ShadersInclude/lightUboDeclaration.js";
  11. import "./ShadersInclude/lightsFragmentFunctions.js";
  12. import "./ShadersInclude/shadowsFragmentFunctions.js";
  13. import "./ShadersInclude/samplerFragmentDeclaration.js";
  14. import "./ShadersInclude/fresnelFunction.js";
  15. import "./ShadersInclude/reflectionFunction.js";
  16. import "./ShadersInclude/imageProcessingDeclaration.js";
  17. import "./ShadersInclude/imageProcessingFunctions.js";
  18. import "./ShadersInclude/bumpFragmentMainFunctions.js";
  19. import "./ShadersInclude/bumpFragmentFunctions.js";
  20. import "./ShadersInclude/clipPlaneFragmentDeclaration.js";
  21. import "./ShadersInclude/logDepthDeclaration.js";
  22. import "./ShadersInclude/fogFragmentDeclaration.js";
  23. import "./ShadersInclude/clipPlaneFragment.js";
  24. import "./ShadersInclude/bumpFragment.js";
  25. import "./ShadersInclude/decalFragment.js";
  26. import "./ShadersInclude/depthPrePass.js";
  27. import "./ShadersInclude/lightFragment.js";
  28. import "./ShadersInclude/logDepthFragment.js";
  29. import "./ShadersInclude/fogFragment.js";
  30. import "./ShadersInclude/oitFragment.js";
  31. const name = "defaultPixelShader";
  32. const shader = `#include<__decl__defaultFragment>
  33. #if defined(BUMP) || !defined(NORMAL)
  34. #extension GL_OES_standard_derivatives : enable
  35. #endif
  36. #include<prePassDeclaration>[SCENE_MRT_COUNT]
  37. #include<oitDeclaration>
  38. #define CUSTOM_FRAGMENT_BEGIN
  39. #ifdef LOGARITHMICDEPTH
  40. #extension GL_EXT_frag_depth : enable
  41. #endif
  42. varying vec3 vPositionW;
  43. #ifdef NORMAL
  44. varying vec3 vNormalW;
  45. #endif
  46. #if defined(VERTEXCOLOR) || defined(INSTANCESCOLOR) && defined(INSTANCES)
  47. varying vec4 vColor;
  48. #endif
  49. #include<mainUVVaryingDeclaration>[1..7]
  50. #include<helperFunctions>
  51. #include<__decl__lightFragment>[0..maxSimultaneousLights]
  52. #include<lightsFragmentFunctions>
  53. #include<shadowsFragmentFunctions>
  54. #include<samplerFragmentDeclaration>(_DEFINENAME_,DIFFUSE,_VARYINGNAME_,Diffuse,_SAMPLERNAME_,diffuse)
  55. #include<samplerFragmentDeclaration>(_DEFINENAME_,AMBIENT,_VARYINGNAME_,Ambient,_SAMPLERNAME_,ambient)
  56. #include<samplerFragmentDeclaration>(_DEFINENAME_,OPACITY,_VARYINGNAME_,Opacity,_SAMPLERNAME_,opacity)
  57. #include<samplerFragmentDeclaration>(_DEFINENAME_,EMISSIVE,_VARYINGNAME_,Emissive,_SAMPLERNAME_,emissive)
  58. #include<samplerFragmentDeclaration>(_DEFINENAME_,LIGHTMAP,_VARYINGNAME_,Lightmap,_SAMPLERNAME_,lightmap)
  59. #include<samplerFragmentDeclaration>(_DEFINENAME_,DECAL,_VARYINGNAME_,Decal,_SAMPLERNAME_,decal)
  60. #ifdef REFRACTION
  61. #ifdef REFRACTIONMAP_3D
  62. uniform samplerCube refractionCubeSampler;
  63. #else
  64. uniform sampler2D refraction2DSampler;
  65. #endif
  66. #endif
  67. #if defined(SPECULARTERM)
  68. #include<samplerFragmentDeclaration>(_DEFINENAME_,SPECULAR,_VARYINGNAME_,Specular,_SAMPLERNAME_,specular)
  69. #endif
  70. #include<fresnelFunction>
  71. #ifdef REFLECTION
  72. #ifdef REFLECTIONMAP_3D
  73. uniform samplerCube reflectionCubeSampler;
  74. #else
  75. uniform sampler2D reflection2DSampler;
  76. #endif
  77. #ifdef REFLECTIONMAP_SKYBOX
  78. varying vec3 vPositionUVW;
  79. #else
  80. #if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)
  81. varying vec3 vDirectionW;
  82. #endif
  83. #endif
  84. #include<reflectionFunction>
  85. #endif
  86. #include<imageProcessingDeclaration>
  87. #include<imageProcessingFunctions>
  88. #include<bumpFragmentMainFunctions>
  89. #include<bumpFragmentFunctions>
  90. #include<clipPlaneFragmentDeclaration>
  91. #include<logDepthDeclaration>
  92. #include<fogFragmentDeclaration>
  93. #define CUSTOM_FRAGMENT_DEFINITIONS
  94. void main(void) {
  95. #define CUSTOM_FRAGMENT_MAIN_BEGIN
  96. #include<clipPlaneFragment>
  97. vec3 viewDirectionW=normalize(vEyePosition.xyz-vPositionW);vec4 baseColor=vec4(1.,1.,1.,1.);vec3 diffuseColor=vDiffuseColor.rgb;float alpha=vDiffuseColor.a;
  98. #ifdef NORMAL
  99. vec3 normalW=normalize(vNormalW);
  100. #else
  101. vec3 normalW=normalize(-cross(dFdx(vPositionW),dFdy(vPositionW)));
  102. #endif
  103. #include<bumpFragment>
  104. #ifdef TWOSIDEDLIGHTING
  105. normalW=gl_FrontFacing ? normalW : -normalW;
  106. #endif
  107. #ifdef DIFFUSE
  108. baseColor=texture2D(diffuseSampler,vDiffuseUV+uvOffset);
  109. #if defined(ALPHATEST) && !defined(ALPHATEST_AFTERALLALPHACOMPUTATIONS)
  110. if (baseColor.a<alphaCutOff)
  111. discard;
  112. #endif
  113. #ifdef ALPHAFROMDIFFUSE
  114. alpha*=baseColor.a;
  115. #endif
  116. #define CUSTOM_FRAGMENT_UPDATE_ALPHA
  117. baseColor.rgb*=vDiffuseInfos.y;
  118. #endif
  119. #if defined(DECAL) && !defined(DECAL_AFTER_DETAIL)
  120. vec4 decalColor=texture2D(decalSampler,vDecalUV+uvOffset);
  121. #include<decalFragment>(surfaceAlbedo,baseColor,GAMMADECAL,_GAMMADECAL_NOTUSED_)
  122. #endif
  123. #include<depthPrePass>
  124. #if defined(VERTEXCOLOR) || defined(INSTANCESCOLOR) && defined(INSTANCES)
  125. baseColor.rgb*=vColor.rgb;
  126. #endif
  127. #ifdef DETAIL
  128. baseColor.rgb=baseColor.rgb*2.0*mix(0.5,detailColor.r,vDetailInfos.y);
  129. #endif
  130. #if defined(DECAL) && defined(DECAL_AFTER_DETAIL)
  131. vec4 decalColor=texture2D(decalSampler,vDecalUV+uvOffset);
  132. #include<decalFragment>(surfaceAlbedo,baseColor,GAMMADECAL,_GAMMADECAL_NOTUSED_)
  133. #endif
  134. #define CUSTOM_FRAGMENT_UPDATE_DIFFUSE
  135. vec3 baseAmbientColor=vec3(1.,1.,1.);
  136. #ifdef AMBIENT
  137. baseAmbientColor=texture2D(ambientSampler,vAmbientUV+uvOffset).rgb*vAmbientInfos.y;
  138. #endif
  139. #define CUSTOM_FRAGMENT_BEFORE_LIGHTS
  140. #ifdef SPECULARTERM
  141. float glossiness=vSpecularColor.a;vec3 specularColor=vSpecularColor.rgb;
  142. #ifdef SPECULAR
  143. vec4 specularMapColor=texture2D(specularSampler,vSpecularUV+uvOffset);specularColor=specularMapColor.rgb;
  144. #ifdef GLOSSINESS
  145. glossiness=glossiness*specularMapColor.a;
  146. #endif
  147. #endif
  148. #else
  149. float glossiness=0.;
  150. #endif
  151. vec3 diffuseBase=vec3(0.,0.,0.);lightingInfo info;
  152. #ifdef SPECULARTERM
  153. vec3 specularBase=vec3(0.,0.,0.);
  154. #endif
  155. float shadow=1.;float aggShadow=0.;float numLights=0.;
  156. #ifdef LIGHTMAP
  157. vec4 lightmapColor=texture2D(lightmapSampler,vLightmapUV+uvOffset);
  158. #ifdef RGBDLIGHTMAP
  159. lightmapColor.rgb=fromRGBD(lightmapColor);
  160. #endif
  161. lightmapColor.rgb*=vLightmapInfos.y;
  162. #endif
  163. #include<lightFragment>[0..maxSimultaneousLights]
  164. aggShadow=aggShadow/numLights;vec4 refractionColor=vec4(0.,0.,0.,1.);
  165. #ifdef REFRACTION
  166. vec3 refractionVector=normalize(refract(-viewDirectionW,normalW,vRefractionInfos.y));
  167. #ifdef REFRACTIONMAP_3D
  168. #ifdef USE_LOCAL_REFRACTIONMAP_CUBIC
  169. refractionVector=parallaxCorrectNormal(vPositionW,refractionVector,vRefractionSize,vRefractionPosition);
  170. #endif
  171. refractionVector.y=refractionVector.y*vRefractionInfos.w;vec4 refractionLookup=textureCube(refractionCubeSampler,refractionVector);if (dot(refractionVector,viewDirectionW)<1.0) {refractionColor=refractionLookup;}
  172. #else
  173. vec3 vRefractionUVW=vec3(refractionMatrix*(view*vec4(vPositionW+refractionVector*vRefractionInfos.z,1.0)));vec2 refractionCoords=vRefractionUVW.xy/vRefractionUVW.z;refractionCoords.y=1.0-refractionCoords.y;refractionColor=texture2D(refraction2DSampler,refractionCoords);
  174. #endif
  175. #ifdef RGBDREFRACTION
  176. refractionColor.rgb=fromRGBD(refractionColor);
  177. #endif
  178. #ifdef IS_REFRACTION_LINEAR
  179. refractionColor.rgb=toGammaSpace(refractionColor.rgb);
  180. #endif
  181. refractionColor.rgb*=vRefractionInfos.x;
  182. #endif
  183. vec4 reflectionColor=vec4(0.,0.,0.,1.);
  184. #ifdef REFLECTION
  185. vec3 vReflectionUVW=computeReflectionCoords(vec4(vPositionW,1.0),normalW);
  186. #ifdef REFLECTIONMAP_OPPOSITEZ
  187. vReflectionUVW.z*=-1.0;
  188. #endif
  189. #ifdef REFLECTIONMAP_3D
  190. #ifdef ROUGHNESS
  191. float bias=vReflectionInfos.y;
  192. #ifdef SPECULARTERM
  193. #ifdef SPECULAR
  194. #ifdef GLOSSINESS
  195. bias*=(1.0-specularMapColor.a);
  196. #endif
  197. #endif
  198. #endif
  199. reflectionColor=textureCube(reflectionCubeSampler,vReflectionUVW,bias);
  200. #else
  201. reflectionColor=textureCube(reflectionCubeSampler,vReflectionUVW);
  202. #endif
  203. #else
  204. vec2 coords=vReflectionUVW.xy;
  205. #ifdef REFLECTIONMAP_PROJECTION
  206. coords/=vReflectionUVW.z;
  207. #endif
  208. coords.y=1.0-coords.y;reflectionColor=texture2D(reflection2DSampler,coords);
  209. #endif
  210. #ifdef RGBDREFLECTION
  211. reflectionColor.rgb=fromRGBD(reflectionColor);
  212. #endif
  213. #ifdef IS_REFLECTION_LINEAR
  214. reflectionColor.rgb=toGammaSpace(reflectionColor.rgb);
  215. #endif
  216. reflectionColor.rgb*=vReflectionInfos.x;
  217. #ifdef REFLECTIONFRESNEL
  218. float reflectionFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,reflectionRightColor.a,reflectionLeftColor.a);
  219. #ifdef REFLECTIONFRESNELFROMSPECULAR
  220. #ifdef SPECULARTERM
  221. reflectionColor.rgb*=specularColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;
  222. #else
  223. reflectionColor.rgb*=reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;
  224. #endif
  225. #else
  226. reflectionColor.rgb*=reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;
  227. #endif
  228. #endif
  229. #endif
  230. #ifdef REFRACTIONFRESNEL
  231. float refractionFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,refractionRightColor.a,refractionLeftColor.a);refractionColor.rgb*=refractionLeftColor.rgb*(1.0-refractionFresnelTerm)+refractionFresnelTerm*refractionRightColor.rgb;
  232. #endif
  233. #ifdef OPACITY
  234. vec4 opacityMap=texture2D(opacitySampler,vOpacityUV+uvOffset);
  235. #ifdef OPACITYRGB
  236. opacityMap.rgb=opacityMap.rgb*vec3(0.3,0.59,0.11);alpha*=(opacityMap.x+opacityMap.y+opacityMap.z)* vOpacityInfos.y;
  237. #else
  238. alpha*=opacityMap.a*vOpacityInfos.y;
  239. #endif
  240. #endif
  241. #if defined(VERTEXALPHA) || defined(INSTANCESCOLOR) && defined(INSTANCES)
  242. alpha*=vColor.a;
  243. #endif
  244. #ifdef OPACITYFRESNEL
  245. float opacityFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,opacityParts.z,opacityParts.w);alpha+=opacityParts.x*(1.0-opacityFresnelTerm)+opacityFresnelTerm*opacityParts.y;
  246. #endif
  247. #ifdef ALPHATEST
  248. #ifdef ALPHATEST_AFTERALLALPHACOMPUTATIONS
  249. if (alpha<alphaCutOff)
  250. discard;
  251. #endif
  252. #ifndef ALPHABLEND
  253. alpha=1.0;
  254. #endif
  255. #endif
  256. vec3 emissiveColor=vEmissiveColor;
  257. #ifdef EMISSIVE
  258. emissiveColor+=texture2D(emissiveSampler,vEmissiveUV+uvOffset).rgb*vEmissiveInfos.y;
  259. #endif
  260. #ifdef EMISSIVEFRESNEL
  261. float emissiveFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,emissiveRightColor.a,emissiveLeftColor.a);emissiveColor*=emissiveLeftColor.rgb*(1.0-emissiveFresnelTerm)+emissiveFresnelTerm*emissiveRightColor.rgb;
  262. #endif
  263. #ifdef DIFFUSEFRESNEL
  264. float diffuseFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,diffuseRightColor.a,diffuseLeftColor.a);diffuseBase*=diffuseLeftColor.rgb*(1.0-diffuseFresnelTerm)+diffuseFresnelTerm*diffuseRightColor.rgb;
  265. #endif
  266. #ifdef EMISSIVEASILLUMINATION
  267. vec3 finalDiffuse=clamp(diffuseBase*diffuseColor+vAmbientColor,0.0,1.0)*baseColor.rgb;
  268. #else
  269. #ifdef LINKEMISSIVEWITHDIFFUSE
  270. vec3 finalDiffuse=clamp((diffuseBase+emissiveColor)*diffuseColor+vAmbientColor,0.0,1.0)*baseColor.rgb;
  271. #else
  272. vec3 finalDiffuse=clamp(diffuseBase*diffuseColor+emissiveColor+vAmbientColor,0.0,1.0)*baseColor.rgb;
  273. #endif
  274. #endif
  275. #ifdef SPECULARTERM
  276. vec3 finalSpecular=specularBase*specularColor;
  277. #ifdef SPECULAROVERALPHA
  278. alpha=clamp(alpha+dot(finalSpecular,vec3(0.3,0.59,0.11)),0.,1.);
  279. #endif
  280. #else
  281. vec3 finalSpecular=vec3(0.0);
  282. #endif
  283. #ifdef REFLECTIONOVERALPHA
  284. alpha=clamp(alpha+dot(reflectionColor.rgb,vec3(0.3,0.59,0.11)),0.,1.);
  285. #endif
  286. #ifdef EMISSIVEASILLUMINATION
  287. vec4 color=vec4(clamp(finalDiffuse*baseAmbientColor+finalSpecular+reflectionColor.rgb+emissiveColor+refractionColor.rgb,0.0,1.0),alpha);
  288. #else
  289. vec4 color=vec4(finalDiffuse*baseAmbientColor+finalSpecular+reflectionColor.rgb+refractionColor.rgb,alpha);
  290. #endif
  291. #ifdef LIGHTMAP
  292. #ifndef LIGHTMAPEXCLUDED
  293. #ifdef USELIGHTMAPASSHADOWMAP
  294. color.rgb*=lightmapColor.rgb;
  295. #else
  296. color.rgb+=lightmapColor.rgb;
  297. #endif
  298. #endif
  299. #endif
  300. #define CUSTOM_FRAGMENT_BEFORE_FOG
  301. color.rgb=max(color.rgb,0.);
  302. #include<logDepthFragment>
  303. #include<fogFragment>
  304. #ifdef IMAGEPROCESSINGPOSTPROCESS
  305. color.rgb=toLinearSpace(color.rgb);
  306. #else
  307. #ifdef IMAGEPROCESSING
  308. color.rgb=toLinearSpace(color.rgb);color=applyImageProcessing(color);
  309. #endif
  310. #endif
  311. color.a*=visibility;
  312. #ifdef PREMULTIPLYALPHA
  313. color.rgb*=color.a;
  314. #endif
  315. #define CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR
  316. #ifdef PREPASS
  317. float writeGeometryInfo=color.a>0.4 ? 1.0 : 0.0;gl_FragData[0]=color;
  318. #ifdef PREPASS_POSITION
  319. gl_FragData[PREPASS_POSITION_INDEX]=vec4(vPositionW,writeGeometryInfo);
  320. #endif
  321. #ifdef PREPASS_VELOCITY
  322. vec2 a=(vCurrentPosition.xy/vCurrentPosition.w)*0.5+0.5;vec2 b=(vPreviousPosition.xy/vPreviousPosition.w)*0.5+0.5;vec2 velocity=abs(a-b);velocity=vec2(pow(velocity.x,1.0/3.0),pow(velocity.y,1.0/3.0))*sign(a-b)*0.5+0.5;gl_FragData[PREPASS_VELOCITY_INDEX]=vec4(velocity,0.0,writeGeometryInfo);
  323. #endif
  324. #ifdef PREPASS_IRRADIANCE
  325. gl_FragData[PREPASS_IRRADIANCE_INDEX]=vec4(0.0,0.0,0.0,writeGeometryInfo);
  326. #endif
  327. #ifdef PREPASS_DEPTH
  328. gl_FragData[PREPASS_DEPTH_INDEX]=vec4(vViewPos.z,0.0,0.0,writeGeometryInfo);
  329. #endif
  330. #ifdef PREPASS_NORMAL
  331. #ifdef PREPASS_NORMAL_WORLDSPACE
  332. gl_FragData[PREPASS_NORMAL_INDEX]=vec4(normalW,writeGeometryInfo);
  333. #else
  334. gl_FragData[PREPASS_NORMAL_INDEX]=vec4(normalize((view*vec4(normalW,0.0)).rgb),writeGeometryInfo);
  335. #endif
  336. #endif
  337. #ifdef PREPASS_ALBEDO_SQRT
  338. gl_FragData[PREPASS_ALBEDO_SQRT_INDEX]=vec4(0.0,0.0,0.0,writeGeometryInfo);
  339. #endif
  340. #ifdef PREPASS_REFLECTIVITY
  341. #if defined(SPECULARTERM)
  342. #if defined(SPECULAR)
  343. gl_FragData[PREPASS_REFLECTIVITY_INDEX]=vec4(toLinearSpace(specularMapColor))*writeGeometryInfo;
  344. #else
  345. gl_FragData[PREPASS_REFLECTIVITY_INDEX]=vec4(toLinearSpace(specularColor),1.0)*writeGeometryInfo;
  346. #endif
  347. #else
  348. gl_FragData[PREPASS_REFLECTIVITY_INDEX]=vec4(0.0,0.0,0.0,1.0)*writeGeometryInfo;
  349. #endif
  350. #endif
  351. #endif
  352. #if !defined(PREPASS) || defined(WEBGL2)
  353. gl_FragColor=color;
  354. #endif
  355. #include<oitFragment>
  356. #if ORDER_INDEPENDENT_TRANSPARENCY
  357. if (fragDepth==nearestDepth) {frontColor.rgb+=color.rgb*color.a*alphaMultiplier;frontColor.a=1.0-alphaMultiplier*(1.0-color.a);} else {backColor+=color;}
  358. #endif
  359. #define CUSTOM_FRAGMENT_MAIN_END
  360. }
  361. `;
  362. // Sideeffect
  363. ShaderStore.ShadersStore[name] = shader;
  364. /** @internal */
  365. export const defaultPixelShader = { name, shader };
  366. //# sourceMappingURL=default.fragment.js.map