Guest User

Untitled

a guest
Dec 5th, 2021
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 61.71 KB | None | 0 0
  1. ant -f C:\\eclipse\\workspaces\\jme\\BasicGame -Dnb.internal.action.name=run.single -Djavac.includes=mygame/MySimpleApplication.java -Drun.class=mygame.MySimpleApplication run-single
  2. init:
  3. Deleting: C:\eclipse\workspaces\jme\BasicGame\build\built-jar.properties
  4. deps-jar:
  5. Updating property file: C:\eclipse\workspaces\jme\BasicGame\build\built-jar.properties
  6. Compiling 1 source file to C:\eclipse\workspaces\jme\BasicGame\build\classes
  7. warning: [options] bootstrap class path not set in conjunction with -source 7
  8. 1 warning
  9. compile-single:
  10. run-single:
  11. gru 05, 2021 10:15:36 PM com.jme3.system.JmeDesktopSystem initialize
  12. INFO: Running on jMonkeyEngine 3.3.0-stable
  13. * Branch: HEAD
  14. * Git Hash: 391e0dc
  15. * Build Date: 2021-04-05
  16. gru 05, 2021 10:15:36 PM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
  17. INFO: LWJGL 2.9.3 context running on thread jME3 Main
  18. * Graphics Adapter: igdumd64
  19. * Driver Version: null
  20. * Scaling Factor: 1
  21. WARNING: An illegal reflective access operation has occurred
  22. WARNING: Illegal reflective access by com.jme3.util.ReflectionAllocator (file:/C:/Program%20Files%20(x86)/jmonkeyplatform/jmonkeyplatform/libs/jme3-core-3.3.0-stable.jar) to method sun.nio.ch.DirectBuffer.cleaner()
  23. WARNING: Please consider reporting this to the maintainers of com.jme3.util.ReflectionAllocator
  24. WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
  25. WARNING: All illegal access operations will be denied in a future release
  26. gru 05, 2021 10:15:36 PM com.jme3.renderer.opengl.GLRenderer loadCapabilitiesCommon
  27. INFO: OpenGL Renderer Information
  28. * Vendor: Intel
  29. * Renderer: Intel(R) HD Graphics 4000
  30. * OpenGL Version: 4.0.0 - Build 9.17.10.2867
  31. * GLSL Version: 4.00 - Build 9.17.10.2867
  32. * Profile: Compatibility
  33. gru 05, 2021 10:15:36 PM com.jme3.renderer.opengl.GLRenderer setMainFrameBufferSrgb
  34. WARNING: Driver claims that default framebuffer is not sRGB capable. Enabling anyway.
  35. gru 05, 2021 10:15:36 PM com.jme3.asset.AssetConfig loadText
  36. WARNING: Cannot find loader com.jme3.scene.plugins.blender.BlenderModelLoader
  37. gru 05, 2021 10:15:36 PM com.jme3.audio.openal.ALAudioRenderer initOpenAL
  38. INFO: Audio Renderer Information
  39. * Device: OpenAL Soft
  40. * Vendor: OpenAL Community
  41. * Renderer: OpenAL Soft
  42. * Version: 1.1 ALSOFT 1.15.1
  43. * Supported channels: 64
  44. * ALC extensions: ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE ALC_EXT_DEDICATED ALC_EXT_disconnect ALC_EXT_EFX ALC_EXT_thread_local_context ALC_SOFT_loopback
  45. * AL extensions: AL_EXT_ALAW AL_EXT_DOUBLE AL_EXT_EXPONENT_DISTANCE AL_EXT_FLOAT32 AL_EXT_IMA4 AL_EXT_LINEAR_DISTANCE AL_EXT_MCFORMATS AL_EXT_MULAW AL_EXT_MULAW_MCFORMATS AL_EXT_OFFSET AL_EXT_source_distance_model AL_LOKI_quadriphonic AL_SOFT_buffer_samples AL_SOFT_buffer_sub_data AL_SOFTX_deferred_updates AL_SOFT_direct_channels AL_SOFT_loop_points AL_SOFT_source_latency
  46. gru 05, 2021 10:15:36 PM com.jme3.audio.openal.ALAudioRenderer initOpenAL
  47. WARNING: Pausing audio device not supported.
  48. gru 05, 2021 10:15:36 PM com.jme3.audio.openal.ALAudioRenderer initOpenAL
  49. INFO: Audio effect extension version: 1.0
  50. gru 05, 2021 10:15:36 PM com.jme3.audio.openal.ALAudioRenderer initOpenAL
  51. INFO: Audio max auxiliary sends: 4
  52. gru 05, 2021 10:15:37 PM com.jme3.renderer.opengl.GLRenderer updateShaderSourceData
  53. WARNING: Bad compile of:
  54. 1 #version 150 core
  55. 2 #define SRGB 1
  56. 3 #define FRAGMENT_SHADER 1
  57. 4 #define NUM_BONES 10
  58. 5 #define NORMAL_TYPE -1.0
  59. 6 #define SINGLE_PASS_LIGHTING 1
  60. 7 #define NB_LIGHTS 3
  61. 8 #extension GL_ARB_shader_texture_lod : enable
  62. 9 // -- begin import Common/ShaderLib/GLSLCompat.glsllib --
  63. 10 #if defined GL_ES
  64. 11 # define hfloat highp float
  65. 12 # define hvec2 highp vec2
  66. 13 # define hvec3 highp vec3
  67. 14 # define hvec4 highp vec4
  68. 15 # define lfloat lowp float
  69. 16 # define lvec2 lowp vec2
  70. 17 # define lvec3 lowp vec3
  71. 18 # define lvec4 lowp vec4
  72. 19 #else
  73. 20 # define hfloat float
  74. 21 # define hvec2 vec2
  75. 22 # define hvec3 vec3
  76. 23 # define hvec4 vec4
  77. 24 # define lfloat float
  78. 25 # define lvec2 vec2
  79. 26 # define lvec3 vec3
  80. 27 # define lvec4 vec4
  81. 28 #endif
  82. 29
  83. 30 #if __VERSION__ >= 130
  84. 31 # ifdef GL_ES
  85. 32 out highp vec4 outFragColor;
  86. 33 # else
  87. 34 out vec4 outFragColor;
  88. 35 #endif
  89. 36 # define texture1D texture
  90. 37 # define texture2D texture
  91. 38 # define texture3D texture
  92. 39 # define textureCube texture
  93. 40 # define texture2DLod textureLod
  94. 41 # define textureCubeLod textureLod
  95. 42 # define texture2DArray texture
  96. 43 # if defined VERTEX_SHADER
  97. 44 # define varying out
  98. 45 # define attribute in
  99. 46 # elif defined FRAGMENT_SHADER
  100. 47 # define varying in
  101. 48 # define gl_FragColor outFragColor
  102. 49 # endif
  103. 50 #else
  104. 51 # define isnan(val) !(val<0.0||val>0.0||val==0.0)
  105. 52 #endif
  106. 53
  107. 54
  108. 55 // -- end import Common/ShaderLib/GLSLCompat.glsllib --
  109. 56 // -- begin import Common/ShaderLib/PBR.glsllib --
  110. 57 #ifndef PI
  111. 58 #define PI 3.14159265358979323846264
  112. 59 #endif
  113. 60
  114. 61 //Specular fresnel computation
  115. 62 vec3 F_Shlick(float vh, vec3 F0){
  116. 63 float fresnelFact = pow(2.0, (-5.55473*vh - 6.98316) * vh);
  117. 64 return mix(F0, vec3(1.0, 1.0, 1.0), fresnelFact);
  118. 65 }
  119. 66
  120. 67 vec3 sphericalHarmonics( const in vec3 normal, const vec3 sph[9] ){
  121. 68 float x = normal.x;
  122. 69 float y = normal.y;
  123. 70 float z = normal.z;
  124. 71
  125. 72 vec3 result = (
  126. 73 sph[0] +
  127. 74
  128. 75 sph[1] * y +
  129. 76 sph[2] * z +
  130. 77 sph[3] * x +
  131. 78
  132. 79 sph[4] * y * x +
  133. 80 sph[5] * y * z +
  134. 81 sph[6] * (3.0 * z * z - 1.0) +
  135. 82 sph[7] * (z * x) +
  136. 83 sph[8] * (x*x - y*y)
  137. 84 );
  138. 85
  139. 86 return max(result, vec3(0.0));
  140. 87 }
  141. 88
  142. 89
  143. 90 float PBR_ComputeDirectLight(vec3 normal, vec3 lightDir, vec3 viewDir,
  144. 91 vec3 lightColor, vec3 fZero, float roughness, float ndotv,
  145. 92 out vec3 outDiffuse, out vec3 outSpecular){
  146. 93 // Compute halfway vector.
  147. 94 vec3 halfVec = normalize(lightDir + viewDir);
  148. 95
  149. 96 // Compute ndotl, ndoth, vdoth terms which are needed later.
  150. 97 float ndotl = max( dot(normal, lightDir), 0.0);
  151. 98 float ndoth = max( dot(normal, halfVec), 0.0);
  152. 99 float hdotv = max( dot(viewDir, halfVec), 0.0);
  153. 100
  154. 101 // Compute diffuse using energy-conserving Lambert.
  155. 102 // Alternatively, use Oren-Nayar for really rough
  156. 103 // materials or if you have lots of processing power ...
  157. 104 outDiffuse = vec3(ndotl) * lightColor;
  158. 105
  159. 106 //cook-torrence, microfacet BRDF : http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf
  160. 107
  161. 108 float alpha = roughness * roughness;
  162. 109
  163. 110 //D, GGX normaal Distribution function
  164. 111 float alpha2 = alpha * alpha;
  165. 112 float sum = ((ndoth * ndoth) * (alpha2 - 1.0) + 1.0);
  166. 113 float denom = PI * sum * sum;
  167. 114 float D = alpha2 / denom;
  168. 115
  169. 116 // Compute Fresnel function via Schlick's approximation.
  170. 117 vec3 fresnel = F_Shlick(hdotv, fZero);
  171. 118
  172. 119 //G Shchlick GGX Gometry shadowing term, k = alpha/2
  173. 120 float k = alpha * 0.5;
  174. 121
  175. 122 /*
  176. 123 //classic Schlick ggx
  177. 124 float G_V = ndotv / (ndotv * (1.0 - k) + k);
  178. 125 float G_L = ndotl / (ndotl * (1.0 - k) + k);
  179. 126 float G = ( G_V * G_L );
  180. 127
  181. 128 float specular =(D* fresnel * G) /(4 * ndotv);
  182. 129 */
  183. 130
  184. 131 // UE4 way to optimise shlick GGX Gometry shadowing term
  185. 132 //http://graphicrants.blogspot.co.uk/2013/08/specular-brdf-reference.html
  186. 133 float G_V = ndotv + sqrt( (ndotv - ndotv * k) * ndotv + k );
  187. 134 float G_L = ndotl + sqrt( (ndotl - ndotl * k) * ndotl + k );
  188. 135 // the max here is to avoid division by 0 that may cause some small glitches.
  189. 136 float G = 1.0/max( G_V * G_L ,0.01);
  190. 137
  191. 138 float specular = D * G * ndotl;
  192. 139
  193. 140 outSpecular = vec3(specular) * fresnel * lightColor;
  194. 141 return hdotv;
  195. 142 }
  196. 143
  197. 144 vec3 integrateBRDFApprox( const in vec3 specular, float roughness, float NoV ){
  198. 145 const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022 );
  199. 146 const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04 );
  200. 147 vec4 r = roughness * c0 + c1;
  201. 148 float a004 = min( r.x * r.x, exp2( -9.28 * NoV ) ) * r.x + r.y;
  202. 149 vec2 AB = vec2( -1.04, 1.04 ) * a004 + r.zw;
  203. 150 return specular * AB.x + AB.y;
  204. 151 }
  205. 152
  206. 153 // from Sebastien Lagarde https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf page 69
  207. 154 vec3 getSpecularDominantDir(const in vec3 N, const in vec3 R, const in float realRoughness){
  208. 155 vec3 dominant;
  209. 156
  210. 157 float smoothness = 1.0 - realRoughness;
  211. 158 float lerpFactor = smoothness * (sqrt(smoothness) + realRoughness);
  212. 159 // The result is not normalized as we fetch in a cubemap
  213. 160 dominant = mix(N, R, lerpFactor);
  214. 161
  215. 162 return dominant;
  216. 163 }
  217. 164
  218. 165 vec3 ApproximateSpecularIBL(samplerCube envMap,sampler2D integrateBRDF, vec3 SpecularColor , float Roughness, float ndotv, vec3 refVec, float nbMipMaps){
  219. 166 float Lod = sqrt( Roughness ) * (nbMipMaps - 1.0);
  220. 167 vec3 PrefilteredColor = textureCubeLod(envMap, refVec.xyz,Lod).rgb;
  221. 168 vec2 EnvBRDF = texture2D(integrateBRDF,vec2(Roughness, ndotv)).rg;
  222. 169 return PrefilteredColor * ( SpecularColor * EnvBRDF.x+ EnvBRDF.y );
  223. 170 }
  224. 171
  225. 172 vec3 ApproximateSpecularIBLPolynomial(samplerCube envMap, vec3 SpecularColor , float Roughness, float ndotv, vec3 refVec, float nbMipMaps){
  226. 173 float Lod = sqrt( Roughness ) * (nbMipMaps - 1.0);
  227. 174 vec3 PrefilteredColor = textureCubeLod(envMap, refVec.xyz, Lod).rgb;
  228. 175 return PrefilteredColor * integrateBRDFApprox(SpecularColor, Roughness, ndotv);
  229. 176 }
  230. 177
  231. 178
  232. 179 float renderProbe(vec3 viewDir, vec3 worldPos, vec3 normal, vec3 norm, float Roughness, vec4 diffuseColor, vec4 specularColor, float ndotv, vec3 ao, mat4 lightProbeData,vec3 shCoeffs[9],samplerCube prefEnvMap, inout vec3 color ){
  233. 180
  234. 181 // lightProbeData is a mat4 with this layout
  235. 182 // 3x3 rot mat|
  236. 183 // 0 1 2 | 3
  237. 184 // 0 | ax bx cx | px | )
  238. 185 // 1 | ay by cy | py | probe position
  239. 186 // 2 | az bz cz | pz | )
  240. 187 // --|----------|
  241. 188 // 3 | sx sy sz sp | -> 1/probe radius + nbMipMaps
  242. 189 // --scale--
  243. 190 // parallax fix for spherical / obb bounds and probe blending from
  244. 191 // from https://seblagarde.wordpress.com/2012/09/29/image-based-lighting-approaches-and-parallax-corrected-cubemap/
  245. 192 vec3 rv = reflect(-viewDir, normal);
  246. 193 vec4 probePos = lightProbeData[3];
  247. 194 float invRadius = fract( probePos.w);
  248. 195 float nbMipMaps = probePos.w - invRadius;
  249. 196 vec3 direction = worldPos - probePos.xyz;
  250. 197 float ndf = 0.0;
  251. 198
  252. 199 if(lightProbeData[0][3] != 0.0){
  253. 200 // oriented box probe
  254. 201 mat3 wToLocalRot = mat3(lightProbeData);
  255. 202 wToLocalRot = inverse(wToLocalRot);
  256. 203 vec3 scale = vec3(lightProbeData[0][3], lightProbeData[1][3], lightProbeData[2][3]);
  257. 204 #if NB_PROBES >= 2
  258. 205 // probe blending
  259. 206 // compute fragment position in probe local space
  260. 207 vec3 localPos = wToLocalRot * worldPos;
  261. 208 localPos -= probePos.xyz;
  262. 209 // compute normalized distance field
  263. 210 vec3 localDir = abs(localPos);
  264. 211 localDir /= scale;
  265. 212 ndf = max(max(localDir.x, localDir.y), localDir.z);
  266. 213 #endif
  267. 214 // parallax fix
  268. 215 vec3 rayLs = wToLocalRot * rv;
  269. 216 rayLs /= scale;
  270. 217
  271. 218 vec3 positionLs = worldPos - probePos.xyz;
  272. 219 positionLs = wToLocalRot * positionLs;
  273. 220 positionLs /= scale;
  274. 221
  275. 222 vec3 unit = vec3(1.0);
  276. 223 vec3 firstPlaneIntersect = (unit - positionLs) / rayLs;
  277. 224 vec3 secondPlaneIntersect = (-unit - positionLs) / rayLs;
  278. 225 vec3 furthestPlane = max(firstPlaneIntersect, secondPlaneIntersect);
  279. 226 float distance = min(min(furthestPlane.x, furthestPlane.y), furthestPlane.z);
  280. 227
  281. 228 vec3 intersectPositionWs = worldPos + rv * distance;
  282. 229 rv = intersectPositionWs - probePos.xyz;
  283. 230
  284. 231 } else {
  285. 232 // spherical probe
  286. 233 // paralax fix
  287. 234 rv = invRadius * direction + rv;
  288. 235
  289. 236 #if NB_PROBES >= 2
  290. 237 // probe blending
  291. 238 float dist = sqrt(dot(direction, direction));
  292. 239 ndf = dist * invRadius;
  293. 240 #endif
  294. 241 }
  295. 242
  296. 243 vec3 indirectDiffuse = vec3(0.0);
  297. 244 vec3 indirectSpecular = vec3(0.0);
  298. 245 indirectDiffuse = sphericalHarmonics(normal.xyz, shCoeffs) * diffuseColor.rgb;
  299. 246 vec3 dominantR = getSpecularDominantDir( normal, rv.xyz, Roughness * Roughness );
  300. 247 indirectSpecular = ApproximateSpecularIBLPolynomial(prefEnvMap, specularColor.rgb, Roughness, ndotv, dominantR, nbMipMaps);
  301. 248
  302. 249 #ifdef HORIZON_FADE
  303. 250 //horizon fade from http://marmosetco.tumblr.com/post/81245981087
  304. 251 float horiz = dot(rv, norm);
  305. 252 float horizFadePower = 1.0 - Roughness;
  306. 253 horiz = clamp( 1.0 + horizFadePower * horiz, 0.0, 1.0 );
  307. 254 horiz *= horiz;
  308. 255 indirectSpecular *= vec3(horiz);
  309. 256 #endif
  310. 257
  311. 258 vec3 indirectLighting = (indirectDiffuse + indirectSpecular) * ao;
  312. 259
  313. 260 color = indirectLighting * step( 0.0, probePos.w);
  314. 261 return ndf;
  315. 262 }
  316. 263
  317. 264
  318. 265
  319. 266
  320. 267
  321. 268 // -- end import Common/ShaderLib/PBR.glsllib --
  322. 269 // -- begin import Common/ShaderLib/Parallax.glsllib --
  323. 270 #if (defined(PARALLAXMAP) || (defined(NORMALMAP_PARALLAX) && defined(NORMALMAP))) && !defined(VERTEX_LIGHTING)
  324. 271 vec2 steepParallaxOffset(sampler2D parallaxMap, vec3 vViewDir,vec2 texCoord,float parallaxScale){
  325. 272 vec2 vParallaxDirection = normalize( vViewDir.xy );
  326. 273
  327. 274 // The length of this vector determines the furthest amount of displacement: (Ati's comment)
  328. 275 float fLength = length( vViewDir );
  329. 276 float fParallaxLength = sqrt( fLength * fLength - vViewDir.z * vViewDir.z ) / vViewDir.z;
  330. 277
  331. 278 // Compute the actual reverse parallax displacement vector: (Ati's comment)
  332. 279 vec2 vParallaxOffsetTS = vParallaxDirection * fParallaxLength;
  333. 280
  334. 281 // Need to scale the amount of displacement to account for different height ranges
  335. 282 // in height maps. This is controlled by an artist-editable parameter: (Ati's comment)
  336. 283 parallaxScale *=0.3;
  337. 284 vParallaxOffsetTS *= parallaxScale;
  338. 285
  339. 286 vec3 eyeDir = normalize(vViewDir).xyz;
  340. 287
  341. 288 float nMinSamples = 6.0;
  342. 289 float nMaxSamples = 1000.0 * parallaxScale;
  343. 290 float nNumSamples = mix( nMinSamples, nMaxSamples, 1.0 - eyeDir.z ); //In reference shader: int nNumSamples = (int)(lerp( nMinSamples, nMaxSamples, dot( eyeDirWS, N ) ));
  344. 291 float fStepSize = 1.0 / nNumSamples;
  345. 292 float fCurrHeight = 0.0;
  346. 293 float fPrevHeight = 1.0;
  347. 294 float fNextHeight = 0.0;
  348. 295 float nStepIndex = 0.0;
  349. 296 vec2 vTexOffsetPerStep = fStepSize * vParallaxOffsetTS;
  350. 297 vec2 vTexCurrentOffset = texCoord;
  351. 298 float fCurrentBound = 1.0;
  352. 299 float fParallaxAmount = 0.0;
  353. 300
  354. 301 while ( nStepIndex < nNumSamples && fCurrHeight <= fCurrentBound ) {
  355. 302 vTexCurrentOffset -= vTexOffsetPerStep;
  356. 303 fPrevHeight = fCurrHeight;
  357. 304
  358. 305
  359. 306 #ifdef NORMALMAP_PARALLAX
  360. 307 //parallax map is stored in the alpha channel of the normal map
  361. 308 fCurrHeight = texture2D( parallaxMap, vTexCurrentOffset).a;
  362. 309 #else
  363. 310 //parallax map is a texture
  364. 311 fCurrHeight = texture2D( parallaxMap, vTexCurrentOffset).r;
  365. 312 #endif
  366. 313
  367. 314 fCurrentBound -= fStepSize;
  368. 315 nStepIndex+=1.0;
  369. 316 }
  370. 317 vec2 pt1 = vec2( fCurrentBound, fCurrHeight );
  371. 318 vec2 pt2 = vec2( fCurrentBound + fStepSize, fPrevHeight );
  372. 319
  373. 320 float fDelta2 = pt2.x - pt2.y;
  374. 321 float fDelta1 = pt1.x - pt1.y;
  375. 322
  376. 323 float fDenominator = fDelta2 - fDelta1;
  377. 324
  378. 325 fParallaxAmount = (pt1.x * fDelta2 - pt2.x * fDelta1 ) / fDenominator;
  379. 326
  380. 327 vec2 vParallaxOffset = vParallaxOffsetTS * (1.0 - fParallaxAmount );
  381. 328 return texCoord - vParallaxOffset;
  382. 329 }
  383. 330
  384. 331 vec2 classicParallaxOffset(sampler2D parallaxMap, vec3 vViewDir,vec2 texCoord,float parallaxScale){
  385. 332 float h;
  386. 333 #ifdef NORMALMAP_PARALLAX
  387. 334 //parallax map is stored in the alpha channel of the normal map
  388. 335 h = texture2D(parallaxMap, texCoord).a;
  389. 336 #else
  390. 337 //parallax map is a texture
  391. 338 h = texture2D(parallaxMap, texCoord).r;
  392. 339 #endif
  393. 340 float heightScale = parallaxScale;
  394. 341 float heightBias = heightScale* -0.6;
  395. 342 vec3 normView = normalize(vViewDir);
  396. 343 h = (h * heightScale + heightBias) * normView.z;
  397. 344 return texCoord + (h * normView.xy);
  398. 345 }
  399. 346 #endif
  400. 347 // -- end import Common/ShaderLib/Parallax.glsllib --
  401. 348 // -- begin import Common/ShaderLib/Lighting.glsllib --
  402. 349 /*Common function for light calculations*/
  403. 350
  404. 351
  405. 352 /*
  406. 353 * Computes light direction
  407. 354 * lightType should be 0.0,1.0,2.0, repectively for Directional, point and spot lights.
  408. 355 * Outputs the light direction and the light half vector.
  409. 356 */
  410. 357 void lightComputeDir(in vec3 worldPos, in float lightType, in vec4 position, out vec4 lightDir, out vec3 lightVec){
  411. 358 float posLight = step(0.5, lightType);
  412. 359 vec3 tempVec = position.xyz * sign(posLight - 0.5) - (worldPos * posLight);
  413. 360 lightVec = tempVec;
  414. 361 float dist = length(tempVec);
  415. 362 #ifdef SRGB
  416. 363 lightDir.w = (1.0 - position.w * dist) / (1.0 + position.w * dist * dist);
  417. 364 lightDir.w = clamp(lightDir.w, 1.0 - posLight, 1.0);
  418. 365 #else
  419. 366 lightDir.w = clamp(1.0 - position.w * dist * posLight, 0.0, 1.0);
  420. 367 #endif
  421. 368 lightDir.xyz = tempVec / vec3(dist);
  422. 369 }
  423. 370
  424. 371 /*
  425. 372 * Computes the spot falloff for a spotlight
  426. 373 */
  427. 374 float computeSpotFalloff(in vec4 lightDirection, in vec3 lightVector){
  428. 375 vec3 L=normalize(lightVector);
  429. 376 vec3 spotdir = normalize(lightDirection.xyz);
  430. 377 float curAngleCos = dot(-L, spotdir);
  431. 378 float innerAngleCos = floor(lightDirection.w) * 0.001;
  432. 379 float outerAngleCos = fract(lightDirection.w);
  433. 380 float innerMinusOuter = innerAngleCos - outerAngleCos;
  434. 381 float falloff = clamp((curAngleCos - outerAngleCos) / innerMinusOuter, step(lightDirection.w, 0.001), 1.0);
  435. 382
  436. 383 #ifdef SRGB
  437. 384 // Use quadratic falloff (notice the ^4)
  438. 385 return pow(clamp((curAngleCos - outerAngleCos) / innerMinusOuter, 0.0, 1.0), 4.0);
  439. 386 #else
  440. 387 // Use linear falloff
  441. 388 return falloff;
  442. 389 #endif
  443. 390 }
  444. 391
  445. 392 // -- end import Common/ShaderLib/Lighting.glsllib --
  446. 393
  447. 394 varying vec2 texCoord;
  448. 395 #ifdef SEPARATE_TEXCOORD
  449. 396 varying vec2 texCoord2;
  450. 397 #endif
  451. 398
  452. 399 varying vec4 Color;
  453. 400
  454. 401 uniform vec4 g_LightData[NB_LIGHTS];
  455. 402 uniform vec3 g_CameraPosition;
  456. 403 uniform vec4 g_AmbientLightColor;
  457. 404
  458. 405 uniform float m_Roughness;
  459. 406 uniform float m_Metallic;
  460. 407
  461. 408 varying vec3 wPosition;
  462. 409
  463. 410
  464. 411 #if NB_PROBES >= 1
  465. 412 uniform samplerCube g_PrefEnvMap;
  466. 413 uniform vec3 g_ShCoeffs[9];
  467. 414 uniform mat4 g_LightProbeData;
  468. 415 #endif
  469. 416 #if NB_PROBES >= 2
  470. 417 uniform samplerCube g_PrefEnvMap2;
  471. 418 uniform vec3 g_ShCoeffs2[9];
  472. 419 uniform mat4 g_LightProbeData2;
  473. 420 #endif
  474. 421 #if NB_PROBES == 3
  475. 422 uniform samplerCube g_PrefEnvMap3;
  476. 423 uniform vec3 g_ShCoeffs3[9];
  477. 424 uniform mat4 g_LightProbeData3;
  478. 425 #endif
  479. 426
  480. 427 #ifdef BASECOLORMAP
  481. 428 uniform sampler2D m_BaseColorMap;
  482. 429 #endif
  483. 430
  484. 431 #ifdef USE_PACKED_MR
  485. 432 uniform sampler2D m_MetallicRoughnessMap;
  486. 433 #else
  487. 434 #ifdef METALLICMAP
  488. 435 uniform sampler2D m_MetallicMap;
  489. 436 #endif
  490. 437 #ifdef ROUGHNESSMAP
  491. 438 uniform sampler2D m_RoughnessMap;
  492. 439 #endif
  493. 440 #endif
  494. 441
  495. 442 #ifdef EMISSIVE
  496. 443 uniform vec4 m_Emissive;
  497. 444 #endif
  498. 445 #ifdef EMISSIVEMAP
  499. 446 uniform sampler2D m_EmissiveMap;
  500. 447 #endif
  501. 448 #if defined(EMISSIVE) || defined(EMISSIVEMAP)
  502. 449 uniform float m_EmissivePower;
  503. 450 uniform float m_EmissiveIntensity;
  504. 451 #endif
  505. 452
  506. 453 #ifdef SPECGLOSSPIPELINE
  507. 454
  508. 455 uniform vec4 m_Specular;
  509. 456 uniform float m_Glossiness;
  510. 457 #ifdef USE_PACKED_SG
  511. 458 uniform sampler2D m_SpecularGlossinessMap;
  512. 459 #else
  513. 460 uniform sampler2D m_SpecularMap;
  514. 461 uniform sampler2D m_GlossinessMap;
  515. 462 #endif
  516. 463 #endif
  517. 464
  518. 465 #ifdef PARALLAXMAP
  519. 466 uniform sampler2D m_ParallaxMap;
  520. 467 #endif
  521. 468 #if (defined(PARALLAXMAP) || (defined(NORMALMAP_PARALLAX) && defined(NORMALMAP)))
  522. 469 uniform float m_ParallaxHeight;
  523. 470 #endif
  524. 471
  525. 472 #ifdef LIGHTMAP
  526. 473 uniform sampler2D m_LightMap;
  527. 474 #endif
  528. 475
  529. 476 #if defined(NORMALMAP) || defined(PARALLAXMAP)
  530. 477 uniform sampler2D m_NormalMap;
  531. 478 varying vec4 wTangent;
  532. 479 #endif
  533. 480 varying vec3 wNormal;
  534. 481
  535. 482 #ifdef DISCARD_ALPHA
  536. 483 uniform float m_AlphaDiscardThreshold;
  537. 484 #endif
  538. 485
  539. 486 void main(){
  540. 487 vec2 newTexCoord;
  541. 488 vec3 viewDir = normalize(g_CameraPosition - wPosition);
  542. 489
  543. 490 vec3 norm = normalize(wNormal);
  544. 491 #if defined(NORMALMAP) || defined(PARALLAXMAP)
  545. 492 vec3 tan = normalize(wTangent.xyz);
  546. 493 mat3 tbnMat = mat3(tan, wTangent.w * cross( (norm), (tan)), norm);
  547. 494 #endif
  548. 495
  549. 496 #if (defined(PARALLAXMAP) || (defined(NORMALMAP_PARALLAX) && defined(NORMALMAP)))
  550. 497 vec3 vViewDir = viewDir * tbnMat;
  551. 498 #ifdef STEEP_PARALLAX
  552. 499 #ifdef NORMALMAP_PARALLAX
  553. 500 //parallax map is stored in the alpha channel of the normal map
  554. 501 newTexCoord = steepParallaxOffset(m_NormalMap, vViewDir, texCoord, m_ParallaxHeight);
  555. 502 #else
  556. 503 //parallax map is a texture
  557. 504 newTexCoord = steepParallaxOffset(m_ParallaxMap, vViewDir, texCoord, m_ParallaxHeight);
  558. 505 #endif
  559. 506 #else
  560. 507 #ifdef NORMALMAP_PARALLAX
  561. 508 //parallax map is stored in the alpha channel of the normal map
  562. 509 newTexCoord = classicParallaxOffset(m_NormalMap, vViewDir, texCoord, m_ParallaxHeight);
  563. 510 #else
  564. 511 //parallax map is a texture
  565. 512 newTexCoord = classicParallaxOffset(m_ParallaxMap, vViewDir, texCoord, m_ParallaxHeight);
  566. 513 #endif
  567. 514 #endif
  568. 515 #else
  569. 516 newTexCoord = texCoord;
  570. 517 #endif
  571. 518
  572. 519 #ifdef BASECOLORMAP
  573. 520 vec4 albedo = texture2D(m_BaseColorMap, newTexCoord) * Color;
  574. 521 #else
  575. 522 vec4 albedo = Color;
  576. 523 #endif
  577. 524
  578. 525 #ifdef USE_PACKED_MR
  579. 526 vec2 rm = texture2D(m_MetallicRoughnessMap, newTexCoord).gb;
  580. 527 float Roughness = rm.x * max(m_Roughness, 1e-4);
  581. 528 float Metallic = rm.y * max(m_Metallic, 0.0);
  582. 529 #else
  583. 530 #ifdef ROUGHNESSMAP
  584. 531 float Roughness = texture2D(m_RoughnessMap, newTexCoord).r * max(m_Roughness, 1e-4);
  585. 532 #else
  586. 533 float Roughness = max(m_Roughness, 1e-4);
  587. 534 #endif
  588. 535 #ifdef METALLICMAP
  589. 536 float Metallic = texture2D(m_MetallicMap, newTexCoord).r * max(m_Metallic, 0.0);
  590. 537 #else
  591. 538 float Metallic = max(m_Metallic, 0.0);
  592. 539 #endif
  593. 540 #endif
  594. 541
  595. 542 float alpha = albedo.a;
  596. 543
  597. 544 #ifdef DISCARD_ALPHA
  598. 545 if(alpha < m_AlphaDiscardThreshold){
  599. 546 discard;
  600. 547 }
  601. 548 #endif
  602. 549
  603. 550 // ***********************
  604. 551 // Read from textures
  605. 552 // ***********************
  606. 553 #if defined(NORMALMAP)
  607. 554 vec4 normalHeight = texture2D(m_NormalMap, newTexCoord);
  608. 555 //Note the -2.0 and -1.0. We invert the green channel of the normal map,
  609. 556 //as it's complient with normal maps generated with blender.
  610. 557 //see http://hub.jmonkeyengine.org/forum/topic/parallax-mapping-fundamental-bug/#post-256898
  611. 558 //for more explanation.
  612. 559 vec3 normal = normalize((normalHeight.xyz * vec3(2.0, NORMAL_TYPE * 2.0, 2.0) - vec3(1.0, NORMAL_TYPE * 1.0, 1.0)));
  613. 560 normal = normalize(tbnMat * normal);
  614. 561 //normal = normalize(normal * inverse(tbnMat));
  615. 562 #else
  616. 563 vec3 normal = norm;
  617. 564 #endif
  618. 565
  619. 566 #ifdef SPECGLOSSPIPELINE
  620. 567
  621. 568 #ifdef USE_PACKED_SG
  622. 569 vec4 specularColor = texture2D(m_SpecularGlossinessMap, newTexCoord);
  623. 570 float glossiness = specularColor.a * m_Glossiness;
  624. 571 specularColor *= m_Specular;
  625. 572 #else
  626. 573 #ifdef SPECULARMAP
  627. 574 vec4 specularColor = texture2D(m_SpecularMap, newTexCoord);
  628. 575 #else
  629. 576 vec4 specularColor = vec4(1.0);
  630. 577 #endif
  631. 578 #ifdef GLOSSINESSMAP
  632. 579 float glossiness = texture2D(m_GlossinessMap, newTexCoord).r * m_Glossiness;
  633. 580 #else
  634. 581 float glossiness = m_Glossiness;
  635. 582 #endif
  636. 583 specularColor *= m_Specular;
  637. 584 #endif
  638. 585 vec4 diffuseColor = albedo;// * (1.0 - max(max(specularColor.r, specularColor.g), specularColor.b));
  639. 586 Roughness = 1.0 - glossiness;
  640. 587 vec3 fZero = specularColor.xyz;
  641. 588 #else
  642. 589 float specular = 0.5;
  643. 590 float nonMetalSpec = 0.08 * specular;
  644. 591 vec4 specularColor = (nonMetalSpec - nonMetalSpec * Metallic) + albedo * Metallic;
  645. 592 vec4 diffuseColor = albedo - albedo * Metallic;
  646. 593 vec3 fZero = vec3(specular);
  647. 594 #endif
  648. 595
  649. 596 gl_FragColor.rgb = vec3(0.0);
  650. 597 vec3 ao = vec3(1.0);
  651. 598
  652. 599 #ifdef LIGHTMAP
  653. 600 vec3 lightMapColor;
  654. 601 #ifdef SEPARATE_TEXCOORD
  655. 602 lightMapColor = texture2D(m_LightMap, texCoord2).rgb;
  656. 603 #else
  657. 604 lightMapColor = texture2D(m_LightMap, texCoord).rgb;
  658. 605 #endif
  659. 606 #ifdef AO_MAP
  660. 607 lightMapColor.gb = lightMapColor.rr;
  661. 608 ao = lightMapColor;
  662. 609 #else
  663. 610 gl_FragColor.rgb += diffuseColor.rgb * lightMapColor;
  664. 611 #endif
  665. 612 specularColor.rgb *= lightMapColor;
  666. 613 #endif
  667. 614
  668. 615
  669. 616 float ndotv = max( dot( normal, viewDir ),0.0);
  670. 617 for( int i = 0;i < NB_LIGHTS; i+=3){
  671. 618 vec4 lightColor = g_LightData[i];
  672. 619 vec4 lightData1 = g_LightData[i+1];
  673. 620 vec4 lightDir;
  674. 621 vec3 lightVec;
  675. 622 lightComputeDir(wPosition, lightColor.w, lightData1, lightDir, lightVec);
  676. 623
  677. 624 float fallOff = 1.0;
  678. 625 #if __VERSION__ >= 110
  679. 626 // allow use of control flow
  680. 627 if(lightColor.w > 1.0){
  681. 628 #endif
  682. 629 fallOff = computeSpotFalloff(g_LightData[i+2], lightVec);
  683. 630 #if __VERSION__ >= 110
  684. 631 }
  685. 632 #endif
  686. 633 //point light attenuation
  687. 634 fallOff *= lightDir.w;
  688. 635
  689. 636 lightDir.xyz = normalize(lightDir.xyz);
  690. 637 vec3 directDiffuse;
  691. 638 vec3 directSpecular;
  692. 639
  693. 640 float hdotv = PBR_ComputeDirectLight(normal, lightDir.xyz, viewDir,
  694. 641 lightColor.rgb, fZero, Roughness, ndotv,
  695. 642 directDiffuse, directSpecular);
  696. 643
  697. 644 vec3 directLighting = diffuseColor.rgb *directDiffuse + directSpecular;
  698. 645
  699. 646 gl_FragColor.rgb += directLighting * fallOff;
  700. 647 }
  701. 648
  702. 649 #if NB_PROBES >= 1
  703. 650 vec3 color1 = vec3(0.0);
  704. 651 vec3 color2 = vec3(0.0);
  705. 652 vec3 color3 = vec3(0.0);
  706. 653 float weight1 = 1.0;
  707. 654 float weight2 = 0.0;
  708. 655 float weight3 = 0.0;
  709. 656
  710. 657 float ndf = renderProbe(viewDir, wPosition, normal, norm, Roughness, diffuseColor, specularColor, ndotv, ao, g_LightProbeData, g_ShCoeffs, g_PrefEnvMap, color1);
  711. 658 #if NB_PROBES >= 2
  712. 659 float ndf2 = renderProbe(viewDir, wPosition, normal, norm, Roughness, diffuseColor, specularColor, ndotv, ao, g_LightProbeData2, g_ShCoeffs2, g_PrefEnvMap2, color2);
  713. 660 #endif
  714. 661 #if NB_PROBES == 3
  715. 662 float ndf3 = renderProbe(viewDir, wPosition, normal, norm, Roughness, diffuseColor, specularColor, ndotv, ao, g_LightProbeData3, g_ShCoeffs3, g_PrefEnvMap3, color3);
  716. 663 #endif
  717. 664
  718. 665 #if NB_PROBES >= 2
  719. 666 float invNdf = max(1.0 - ndf,0.0);
  720. 667 float invNdf2 = max(1.0 - ndf2,0.0);
  721. 668 float sumNdf = ndf + ndf2;
  722. 669 float sumInvNdf = invNdf + invNdf2;
  723. 670 #if NB_PROBES == 3
  724. 671 float invNdf3 = max(1.0 - ndf3,0.0);
  725. 672 sumNdf += ndf3;
  726. 673 sumInvNdf += invNdf3;
  727. 674 weight3 = ((1.0 - (ndf3 / sumNdf)) / (NB_PROBES - 1)) * (invNdf3 / sumInvNdf);
  728. 675 #endif
  729. 676
  730. 677 weight1 = ((1.0 - (ndf / sumNdf)) / (NB_PROBES - 1)) * (invNdf / sumInvNdf);
  731. 678 weight2 = ((1.0 - (ndf2 / sumNdf)) / (NB_PROBES - 1)) * (invNdf2 / sumInvNdf);
  732. 679
  733. 680 float weightSum = weight1 + weight2 + weight3;
  734. 681
  735. 682 weight1 /= weightSum;
  736. 683 weight2 /= weightSum;
  737. 684 weight3 /= weightSum;
  738. 685 #endif
  739. 686
  740. 687 #ifdef USE_AMBIENT_LIGHT
  741. 688 color1.rgb *= g_AmbientLightColor.rgb;
  742. 689 color2.rgb *= g_AmbientLightColor.rgb;
  743. 690 color3.rgb *= g_AmbientLightColor.rgb;
  744. 691 #endif
  745. 692 gl_FragColor.rgb += color1 * clamp(weight1,0.0,1.0) + color2 * clamp(weight2,0.0,1.0) + color3 * clamp(weight3,0.0,1.0);
  746. 693
  747. 694 #endif
  748. 695
  749. 696 #if defined(EMISSIVE) || defined (EMISSIVEMAP)
  750. 697 #ifdef EMISSIVEMAP
  751. 698 vec4 emissive = texture2D(m_EmissiveMap, newTexCoord);
  752. 699 #else
  753. 700 vec4 emissive = m_Emissive;
  754. 701 #endif
  755. 702 gl_FragColor += emissive * pow(emissive.a, m_EmissivePower) * m_EmissiveIntensity;
  756. 703 #endif
  757. 704 gl_FragColor.a = alpha;
  758. 705
  759. 706 }
  760.  
  761. gru 05, 2021 10:15:37 PM com.jme3.anim.SkinningControl testHardwareSupported
  762. WARNING: Could not enable HW skinning due to shader compile error:
  763. com.jme3.renderer.RendererException: compile error in: ShaderSource[name=Common/MatDefs/Light/PBRLighting.frag, defines, type=Fragment, language=GLSL150]
  764. ERROR: 0:204: '' : syntax error: incorrect preprocessor directive
  765. WARNING: 0:204: unexpected tokens following the preprocessor directive - expected a newline
  766. ERROR: 0:236: '' : syntax error: incorrect preprocessor directive
  767. WARNING: 0:236: unexpected tokens following the preprocessor directive - expected a newline
  768. ERROR: 0:411: '' : syntax error: incorrect preprocessor directive
  769. WARNING: 0:411: unexpected tokens following the preprocessor directive - expected a newline
  770. ERROR: 0:416: '' : syntax error: incorrect preprocessor directive
  771. WARNING: 0:416: unexpected tokens following the preprocessor directive - expected a newline
  772. ERROR: 0:421: '' : syntax error: incorrect preprocessor directive
  773. WARNING: 0:421: unexpected tokens following the preprocessor directive - expected a newline
  774. ERROR: 0:649: '' : syntax error: incorrect preprocessor directive
  775. WARNING: 0:649: unexpected tokens following the preprocessor directive - expected a newline
  776. ERROR: 0:658: '' : syntax error: incorrect preprocessor directive
  777. WARNING: 0:658: unexpected tokens following the preprocessor directive - expected a newline
  778. ERROR: 0:661: '' : syntax error: incorrect preprocessor directive
  779. WARNING: 0:661: unexpected tokens following the preprocessor directive - expected a newline
  780. ERROR: 0:665: '' : syntax error: incorrect preprocessor directive
  781. WARNING: 0:665: unexpected tokens following the preprocessor directive - expected a newline
  782. ERROR: 0:670: '' : syntax error: incorrect preprocessor directive
  783. WARNING: 0:670: unexpected tokens following the preprocessor directive - expected a newline
  784. ERROR: 0:674: 'NB_PROBES' : undeclared identifier
  785.  
  786.  
  787. at com.jme3.renderer.opengl.GLRenderer.updateShaderSourceData(GLRenderer.java:1476)
  788. at com.jme3.renderer.opengl.GLRenderer.updateShaderData(GLRenderer.java:1503)
  789. at com.jme3.renderer.opengl.GLRenderer.setShader(GLRenderer.java:1567)
  790. at com.jme3.material.Material.preload(Material.java:905)
  791. at com.jme3.renderer.RenderManager.preloadScene(RenderManager.java:663)
  792. at com.jme3.renderer.RenderManager.preloadScene(RenderManager.java:654)
  793. at com.jme3.anim.SkinningControl.testHardwareSupported(SkinningControl.java:175)
  794. at com.jme3.anim.SkinningControl.controlRender(SkinningControl.java:283)
  795. at com.jme3.scene.control.AbstractControl.render(AbstractControl.java:118)
  796. at com.jme3.scene.Spatial.runControlRender(Spatial.java:757)
  797. at com.jme3.renderer.RenderManager.renderSubScene(RenderManager.java:721)
  798. at com.jme3.renderer.RenderManager.renderSubScene(RenderManager.java:731)
  799. at com.jme3.renderer.RenderManager.renderSubScene(RenderManager.java:731)
  800. at com.jme3.renderer.RenderManager.renderScene(RenderManager.java:710)
  801. at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:1096)
  802. at com.jme3.renderer.RenderManager.render(RenderManager.java:1158)
  803. at com.jme3.app.SimpleApplication.update(SimpleApplication.java:272)
  804. at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
  805. at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:197)
  806. at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:232)
  807. at java.base/java.lang.Thread.run(Thread.java:834)
  808.  
  809. gru 05, 2021 10:15:37 PM com.jme3.renderer.opengl.GLRenderer updateShaderSourceData
  810. WARNING: Bad compile of:
  811. 1 #version 150 core
  812. 2 #define SRGB 1
  813. 3 #define FRAGMENT_SHADER 1
  814. 4 #define NORMAL_TYPE -1.0
  815. 5 #define NUM_MORPH_TARGETS 1
  816. 6 #define NUM_TARGETS_BUFFERS 2
  817. 7 #define SINGLE_PASS_LIGHTING 1
  818. 8 #define NB_LIGHTS 3
  819. 9 #extension GL_ARB_shader_texture_lod : enable
  820. 10 // -- begin import Common/ShaderLib/GLSLCompat.glsllib --
  821. 11 #if defined GL_ES
  822. 12 # define hfloat highp float
  823. 13 # define hvec2 highp vec2
  824. 14 # define hvec3 highp vec3
  825. 15 # define hvec4 highp vec4
  826. 16 # define lfloat lowp float
  827. 17 # define lvec2 lowp vec2
  828. 18 # define lvec3 lowp vec3
  829. 19 # define lvec4 lowp vec4
  830. 20 #else
  831. 21 # define hfloat float
  832. 22 # define hvec2 vec2
  833. 23 # define hvec3 vec3
  834. 24 # define hvec4 vec4
  835. 25 # define lfloat float
  836. 26 # define lvec2 vec2
  837. 27 # define lvec3 vec3
  838. 28 # define lvec4 vec4
  839. 29 #endif
  840. 30
  841. 31 #if __VERSION__ >= 130
  842. 32 # ifdef GL_ES
  843. 33 out highp vec4 outFragColor;
  844. 34 # else
  845. 35 out vec4 outFragColor;
  846. 36 #endif
  847. 37 # define texture1D texture
  848. 38 # define texture2D texture
  849. 39 # define texture3D texture
  850. 40 # define textureCube texture
  851. 41 # define texture2DLod textureLod
  852. 42 # define textureCubeLod textureLod
  853. 43 # define texture2DArray texture
  854. 44 # if defined VERTEX_SHADER
  855. 45 # define varying out
  856. 46 # define attribute in
  857. 47 # elif defined FRAGMENT_SHADER
  858. 48 # define varying in
  859. 49 # define gl_FragColor outFragColor
  860. 50 # endif
  861. 51 #else
  862. 52 # define isnan(val) !(val<0.0||val>0.0||val==0.0)
  863. 53 #endif
  864. 54
  865. 55
  866. 56 // -- end import Common/ShaderLib/GLSLCompat.glsllib --
  867. 57 // -- begin import Common/ShaderLib/PBR.glsllib --
  868. 58 #ifndef PI
  869. 59 #define PI 3.14159265358979323846264
  870. 60 #endif
  871. 61
  872. 62 //Specular fresnel computation
  873. 63 vec3 F_Shlick(float vh, vec3 F0){
  874. 64 float fresnelFact = pow(2.0, (-5.55473*vh - 6.98316) * vh);
  875. 65 return mix(F0, vec3(1.0, 1.0, 1.0), fresnelFact);
  876. 66 }
  877. 67
  878. 68 vec3 sphericalHarmonics( const in vec3 normal, const vec3 sph[9] ){
  879. 69 float x = normal.x;
  880. 70 float y = normal.y;
  881. 71 float z = normal.z;
  882. 72
  883. 73 vec3 result = (
  884. 74 sph[0] +
  885. 75
  886. 76 sph[1] * y +
  887. 77 sph[2] * z +
  888. 78 sph[3] * x +
  889. 79
  890. 80 sph[4] * y * x +
  891. 81 sph[5] * y * z +
  892. 82 sph[6] * (3.0 * z * z - 1.0) +
  893. 83 sph[7] * (z * x) +
  894. 84 sph[8] * (x*x - y*y)
  895. 85 );
  896. 86
  897. 87 return max(result, vec3(0.0));
  898. 88 }
  899. 89
  900. 90
  901. 91 float PBR_ComputeDirectLight(vec3 normal, vec3 lightDir, vec3 viewDir,
  902. 92 vec3 lightColor, vec3 fZero, float roughness, float ndotv,
  903. 93 out vec3 outDiffuse, out vec3 outSpecular){
  904. 94 // Compute halfway vector.
  905. 95 vec3 halfVec = normalize(lightDir + viewDir);
  906. 96
  907. 97 // Compute ndotl, ndoth, vdoth terms which are needed later.
  908. 98 float ndotl = max( dot(normal, lightDir), 0.0);
  909. 99 float ndoth = max( dot(normal, halfVec), 0.0);
  910. 100 float hdotv = max( dot(viewDir, halfVec), 0.0);
  911. 101
  912. 102 // Compute diffuse using energy-conserving Lambert.
  913. 103 // Alternatively, use Oren-Nayar for really rough
  914. 104 // materials or if you have lots of processing power ...
  915. 105 outDiffuse = vec3(ndotl) * lightColor;
  916. 106
  917. 107 //cook-torrence, microfacet BRDF : http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf
  918. 108
  919. 109 float alpha = roughness * roughness;
  920. 110
  921. 111 //D, GGX normaal Distribution function
  922. 112 float alpha2 = alpha * alpha;
  923. 113 float sum = ((ndoth * ndoth) * (alpha2 - 1.0) + 1.0);
  924. 114 float denom = PI * sum * sum;
  925. 115 float D = alpha2 / denom;
  926. 116
  927. 117 // Compute Fresnel function via Schlick's approximation.
  928. 118 vec3 fresnel = F_Shlick(hdotv, fZero);
  929. 119
  930. 120 //G Shchlick GGX Gometry shadowing term, k = alpha/2
  931. 121 float k = alpha * 0.5;
  932. 122
  933. 123 /*
  934. 124 //classic Schlick ggx
  935. 125 float G_V = ndotv / (ndotv * (1.0 - k) + k);
  936. 126 float G_L = ndotl / (ndotl * (1.0 - k) + k);
  937. 127 float G = ( G_V * G_L );
  938. 128
  939. 129 float specular =(D* fresnel * G) /(4 * ndotv);
  940. 130 */
  941. 131
  942. 132 // UE4 way to optimise shlick GGX Gometry shadowing term
  943. 133 //http://graphicrants.blogspot.co.uk/2013/08/specular-brdf-reference.html
  944. 134 float G_V = ndotv + sqrt( (ndotv - ndotv * k) * ndotv + k );
  945. 135 float G_L = ndotl + sqrt( (ndotl - ndotl * k) * ndotl + k );
  946. 136 // the max here is to avoid division by 0 that may cause some small glitches.
  947. 137 float G = 1.0/max( G_V * G_L ,0.01);
  948. 138
  949. 139 float specular = D * G * ndotl;
  950. 140
  951. 141 outSpecular = vec3(specular) * fresnel * lightColor;
  952. 142 return hdotv;
  953. 143 }
  954. 144
  955. 145 vec3 integrateBRDFApprox( const in vec3 specular, float roughness, float NoV ){
  956. 146 const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022 );
  957. 147 const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04 );
  958. 148 vec4 r = roughness * c0 + c1;
  959. 149 float a004 = min( r.x * r.x, exp2( -9.28 * NoV ) ) * r.x + r.y;
  960. 150 vec2 AB = vec2( -1.04, 1.04 ) * a004 + r.zw;
  961. 151 return specular * AB.x + AB.y;
  962. 152 }
  963. 153
  964. 154 // from Sebastien Lagarde https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf page 69
  965. 155 vec3 getSpecularDominantDir(const in vec3 N, const in vec3 R, const in float realRoughness){
  966. 156 vec3 dominant;
  967. 157
  968. 158 float smoothness = 1.0 - realRoughness;
  969. 159 float lerpFactor = smoothness * (sqrt(smoothness) + realRoughness);
  970. 160 // The result is not normalized as we fetch in a cubemap
  971. 161 dominant = mix(N, R, lerpFactor);
  972. 162
  973. 163 return dominant;
  974. 164 }
  975. 165
  976. 166 vec3 ApproximateSpecularIBL(samplerCube envMap,sampler2D integrateBRDF, vec3 SpecularColor , float Roughness, float ndotv, vec3 refVec, float nbMipMaps){
  977. 167 float Lod = sqrt( Roughness ) * (nbMipMaps - 1.0);
  978. 168 vec3 PrefilteredColor = textureCubeLod(envMap, refVec.xyz,Lod).rgb;
  979. 169 vec2 EnvBRDF = texture2D(integrateBRDF,vec2(Roughness, ndotv)).rg;
  980. 170 return PrefilteredColor * ( SpecularColor * EnvBRDF.x+ EnvBRDF.y );
  981. 171 }
  982. 172
  983. 173 vec3 ApproximateSpecularIBLPolynomial(samplerCube envMap, vec3 SpecularColor , float Roughness, float ndotv, vec3 refVec, float nbMipMaps){
  984. 174 float Lod = sqrt( Roughness ) * (nbMipMaps - 1.0);
  985. 175 vec3 PrefilteredColor = textureCubeLod(envMap, refVec.xyz, Lod).rgb;
  986. 176 return PrefilteredColor * integrateBRDFApprox(SpecularColor, Roughness, ndotv);
  987. 177 }
  988. 178
  989. 179
  990. 180 float renderProbe(vec3 viewDir, vec3 worldPos, vec3 normal, vec3 norm, float Roughness, vec4 diffuseColor, vec4 specularColor, float ndotv, vec3 ao, mat4 lightProbeData,vec3 shCoeffs[9],samplerCube prefEnvMap, inout vec3 color ){
  991. 181
  992. 182 // lightProbeData is a mat4 with this layout
  993. 183 // 3x3 rot mat|
  994. 184 // 0 1 2 | 3
  995. 185 // 0 | ax bx cx | px | )
  996. 186 // 1 | ay by cy | py | probe position
  997. 187 // 2 | az bz cz | pz | )
  998. 188 // --|----------|
  999. 189 // 3 | sx sy sz sp | -> 1/probe radius + nbMipMaps
  1000. 190 // --scale--
  1001. 191 // parallax fix for spherical / obb bounds and probe blending from
  1002. 192 // from https://seblagarde.wordpress.com/2012/09/29/image-based-lighting-approaches-and-parallax-corrected-cubemap/
  1003. 193 vec3 rv = reflect(-viewDir, normal);
  1004. 194 vec4 probePos = lightProbeData[3];
  1005. 195 float invRadius = fract( probePos.w);
  1006. 196 float nbMipMaps = probePos.w - invRadius;
  1007. 197 vec3 direction = worldPos - probePos.xyz;
  1008. 198 float ndf = 0.0;
  1009. 199
  1010. 200 if(lightProbeData[0][3] != 0.0){
  1011. 201 // oriented box probe
  1012. 202 mat3 wToLocalRot = mat3(lightProbeData);
  1013. 203 wToLocalRot = inverse(wToLocalRot);
  1014. 204 vec3 scale = vec3(lightProbeData[0][3], lightProbeData[1][3], lightProbeData[2][3]);
  1015. 205 #if NB_PROBES >= 2
  1016. 206 // probe blending
  1017. 207 // compute fragment position in probe local space
  1018. 208 vec3 localPos = wToLocalRot * worldPos;
  1019. 209 localPos -= probePos.xyz;
  1020. 210 // compute normalized distance field
  1021. 211 vec3 localDir = abs(localPos);
  1022. 212 localDir /= scale;
  1023. 213 ndf = max(max(localDir.x, localDir.y), localDir.z);
  1024. 214 #endif
  1025. 215 // parallax fix
  1026. 216 vec3 rayLs = wToLocalRot * rv;
  1027. 217 rayLs /= scale;
  1028. 218
  1029. 219 vec3 positionLs = worldPos - probePos.xyz;
  1030. 220 positionLs = wToLocalRot * positionLs;
  1031. 221 positionLs /= scale;
  1032. 222
  1033. 223 vec3 unit = vec3(1.0);
  1034. 224 vec3 firstPlaneIntersect = (unit - positionLs) / rayLs;
  1035. 225 vec3 secondPlaneIntersect = (-unit - positionLs) / rayLs;
  1036. 226 vec3 furthestPlane = max(firstPlaneIntersect, secondPlaneIntersect);
  1037. 227 float distance = min(min(furthestPlane.x, furthestPlane.y), furthestPlane.z);
  1038. 228
  1039. 229 vec3 intersectPositionWs = worldPos + rv * distance;
  1040. 230 rv = intersectPositionWs - probePos.xyz;
  1041. 231
  1042. 232 } else {
  1043. 233 // spherical probe
  1044. 234 // paralax fix
  1045. 235 rv = invRadius * direction + rv;
  1046. 236
  1047. 237 #if NB_PROBES >= 2
  1048. 238 // probe blending
  1049. 239 float dist = sqrt(dot(direction, direction));
  1050. 240 ndf = dist * invRadius;
  1051. 241 #endif
  1052. 242 }
  1053. 243
  1054. 244 vec3 indirectDiffuse = vec3(0.0);
  1055. 245 vec3 indirectSpecular = vec3(0.0);
  1056. 246 indirectDiffuse = sphericalHarmonics(normal.xyz, shCoeffs) * diffuseColor.rgb;
  1057. 247 vec3 dominantR = getSpecularDominantDir( normal, rv.xyz, Roughness * Roughness );
  1058. 248 indirectSpecular = ApproximateSpecularIBLPolynomial(prefEnvMap, specularColor.rgb, Roughness, ndotv, dominantR, nbMipMaps);
  1059. 249
  1060. 250 #ifdef HORIZON_FADE
  1061. 251 //horizon fade from http://marmosetco.tumblr.com/post/81245981087
  1062. 252 float horiz = dot(rv, norm);
  1063. 253 float horizFadePower = 1.0 - Roughness;
  1064. 254 horiz = clamp( 1.0 + horizFadePower * horiz, 0.0, 1.0 );
  1065. 255 horiz *= horiz;
  1066. 256 indirectSpecular *= vec3(horiz);
  1067. 257 #endif
  1068. 258
  1069. 259 vec3 indirectLighting = (indirectDiffuse + indirectSpecular) * ao;
  1070. 260
  1071. 261 color = indirectLighting * step( 0.0, probePos.w);
  1072. 262 return ndf;
  1073. 263 }
  1074. 264
  1075. 265
  1076. 266
  1077. 267
  1078. 268
  1079. 269 // -- end import Common/ShaderLib/PBR.glsllib --
  1080. 270 // -- begin import Common/ShaderLib/Parallax.glsllib --
  1081. 271 #if (defined(PARALLAXMAP) || (defined(NORMALMAP_PARALLAX) && defined(NORMALMAP))) && !defined(VERTEX_LIGHTING)
  1082. 272 vec2 steepParallaxOffset(sampler2D parallaxMap, vec3 vViewDir,vec2 texCoord,float parallaxScale){
  1083. 273 vec2 vParallaxDirection = normalize( vViewDir.xy );
  1084. 274
  1085. 275 // The length of this vector determines the furthest amount of displacement: (Ati's comment)
  1086. 276 float fLength = length( vViewDir );
  1087. 277 float fParallaxLength = sqrt( fLength * fLength - vViewDir.z * vViewDir.z ) / vViewDir.z;
  1088. 278
  1089. 279 // Compute the actual reverse parallax displacement vector: (Ati's comment)
  1090. 280 vec2 vParallaxOffsetTS = vParallaxDirection * fParallaxLength;
  1091. 281
  1092. 282 // Need to scale the amount of displacement to account for different height ranges
  1093. 283 // in height maps. This is controlled by an artist-editable parameter: (Ati's comment)
  1094. 284 parallaxScale *=0.3;
  1095. 285 vParallaxOffsetTS *= parallaxScale;
  1096. 286
  1097. 287 vec3 eyeDir = normalize(vViewDir).xyz;
  1098. 288
  1099. 289 float nMinSamples = 6.0;
  1100. 290 float nMaxSamples = 1000.0 * parallaxScale;
  1101. 291 float nNumSamples = mix( nMinSamples, nMaxSamples, 1.0 - eyeDir.z ); //In reference shader: int nNumSamples = (int)(lerp( nMinSamples, nMaxSamples, dot( eyeDirWS, N ) ));
  1102. 292 float fStepSize = 1.0 / nNumSamples;
  1103. 293 float fCurrHeight = 0.0;
  1104. 294 float fPrevHeight = 1.0;
  1105. 295 float fNextHeight = 0.0;
  1106. 296 float nStepIndex = 0.0;
  1107. 297 vec2 vTexOffsetPerStep = fStepSize * vParallaxOffsetTS;
  1108. 298 vec2 vTexCurrentOffset = texCoord;
  1109. 299 float fCurrentBound = 1.0;
  1110. 300 float fParallaxAmount = 0.0;
  1111. 301
  1112. 302 while ( nStepIndex < nNumSamples && fCurrHeight <= fCurrentBound ) {
  1113. 303 vTexCurrentOffset -= vTexOffsetPerStep;
  1114. 304 fPrevHeight = fCurrHeight;
  1115. 305
  1116. 306
  1117. 307 #ifdef NORMALMAP_PARALLAX
  1118. 308 //parallax map is stored in the alpha channel of the normal map
  1119. 309 fCurrHeight = texture2D( parallaxMap, vTexCurrentOffset).a;
  1120. 310 #else
  1121. 311 //parallax map is a texture
  1122. 312 fCurrHeight = texture2D( parallaxMap, vTexCurrentOffset).r;
  1123. 313 #endif
  1124. 314
  1125. 315 fCurrentBound -= fStepSize;
  1126. 316 nStepIndex+=1.0;
  1127. 317 }
  1128. 318 vec2 pt1 = vec2( fCurrentBound, fCurrHeight );
  1129. 319 vec2 pt2 = vec2( fCurrentBound + fStepSize, fPrevHeight );
  1130. 320
  1131. 321 float fDelta2 = pt2.x - pt2.y;
  1132. 322 float fDelta1 = pt1.x - pt1.y;
  1133. 323
  1134. 324 float fDenominator = fDelta2 - fDelta1;
  1135. 325
  1136. 326 fParallaxAmount = (pt1.x * fDelta2 - pt2.x * fDelta1 ) / fDenominator;
  1137. 327
  1138. 328 vec2 vParallaxOffset = vParallaxOffsetTS * (1.0 - fParallaxAmount );
  1139. 329 return texCoord - vParallaxOffset;
  1140. 330 }
  1141. 331
  1142. 332 vec2 classicParallaxOffset(sampler2D parallaxMap, vec3 vViewDir,vec2 texCoord,float parallaxScale){
  1143. 333 float h;
  1144. 334 #ifdef NORMALMAP_PARALLAX
  1145. 335 //parallax map is stored in the alpha channel of the normal map
  1146. 336 h = texture2D(parallaxMap, texCoord).a;
  1147. 337 #else
  1148. 338 //parallax map is a texture
  1149. 339 h = texture2D(parallaxMap, texCoord).r;
  1150. 340 #endif
  1151. 341 float heightScale = parallaxScale;
  1152. 342 float heightBias = heightScale* -0.6;
  1153. 343 vec3 normView = normalize(vViewDir);
  1154. 344 h = (h * heightScale + heightBias) * normView.z;
  1155. 345 return texCoord + (h * normView.xy);
  1156. 346 }
  1157. 347 #endif
  1158. 348 // -- end import Common/ShaderLib/Parallax.glsllib --
  1159. 349 // -- begin import Common/ShaderLib/Lighting.glsllib --
  1160. 350 /*Common function for light calculations*/
  1161. 351
  1162. 352
  1163. 353 /*
  1164. 354 * Computes light direction
  1165. 355 * lightType should be 0.0,1.0,2.0, repectively for Directional, point and spot lights.
  1166. 356 * Outputs the light direction and the light half vector.
  1167. 357 */
  1168. 358 void lightComputeDir(in vec3 worldPos, in float lightType, in vec4 position, out vec4 lightDir, out vec3 lightVec){
  1169. 359 float posLight = step(0.5, lightType);
  1170. 360 vec3 tempVec = position.xyz * sign(posLight - 0.5) - (worldPos * posLight);
  1171. 361 lightVec = tempVec;
  1172. 362 float dist = length(tempVec);
  1173. 363 #ifdef SRGB
  1174. 364 lightDir.w = (1.0 - position.w * dist) / (1.0 + position.w * dist * dist);
  1175. 365 lightDir.w = clamp(lightDir.w, 1.0 - posLight, 1.0);
  1176. 366 #else
  1177. 367 lightDir.w = clamp(1.0 - position.w * dist * posLight, 0.0, 1.0);
  1178. 368 #endif
  1179. 369 lightDir.xyz = tempVec / vec3(dist);
  1180. 370 }
  1181. 371
  1182. 372 /*
  1183. 373 * Computes the spot falloff for a spotlight
  1184. 374 */
  1185. 375 float computeSpotFalloff(in vec4 lightDirection, in vec3 lightVector){
  1186. 376 vec3 L=normalize(lightVector);
  1187. 377 vec3 spotdir = normalize(lightDirection.xyz);
  1188. 378 float curAngleCos = dot(-L, spotdir);
  1189. 379 float innerAngleCos = floor(lightDirection.w) * 0.001;
  1190. 380 float outerAngleCos = fract(lightDirection.w);
  1191. 381 float innerMinusOuter = innerAngleCos - outerAngleCos;
  1192. 382 float falloff = clamp((curAngleCos - outerAngleCos) / innerMinusOuter, step(lightDirection.w, 0.001), 1.0);
  1193. 383
  1194. 384 #ifdef SRGB
  1195. 385 // Use quadratic falloff (notice the ^4)
  1196. 386 return pow(clamp((curAngleCos - outerAngleCos) / innerMinusOuter, 0.0, 1.0), 4.0);
  1197. 387 #else
  1198. 388 // Use linear falloff
  1199. 389 return falloff;
  1200. 390 #endif
  1201. 391 }
  1202. 392
  1203. 393 // -- end import Common/ShaderLib/Lighting.glsllib --
  1204. 394
  1205. 395 varying vec2 texCoord;
  1206. 396 #ifdef SEPARATE_TEXCOORD
  1207. 397 varying vec2 texCoord2;
  1208. 398 #endif
  1209. 399
  1210. 400 varying vec4 Color;
  1211. 401
  1212. 402 uniform vec4 g_LightData[NB_LIGHTS];
  1213. 403 uniform vec3 g_CameraPosition;
  1214. 404 uniform vec4 g_AmbientLightColor;
  1215. 405
  1216. 406 uniform float m_Roughness;
  1217. 407 uniform float m_Metallic;
  1218. 408
  1219. 409 varying vec3 wPosition;
  1220. 410
  1221. 411
  1222. 412 #if NB_PROBES >= 1
  1223. 413 uniform samplerCube g_PrefEnvMap;
  1224. 414 uniform vec3 g_ShCoeffs[9];
  1225. 415 uniform mat4 g_LightProbeData;
  1226. 416 #endif
  1227. 417 #if NB_PROBES >= 2
  1228. 418 uniform samplerCube g_PrefEnvMap2;
  1229. 419 uniform vec3 g_ShCoeffs2[9];
  1230. 420 uniform mat4 g_LightProbeData2;
  1231. 421 #endif
  1232. 422 #if NB_PROBES == 3
  1233. 423 uniform samplerCube g_PrefEnvMap3;
  1234. 424 uniform vec3 g_ShCoeffs3[9];
  1235. 425 uniform mat4 g_LightProbeData3;
  1236. 426 #endif
  1237. 427
  1238. 428 #ifdef BASECOLORMAP
  1239. 429 uniform sampler2D m_BaseColorMap;
  1240. 430 #endif
  1241. 431
  1242. 432 #ifdef USE_PACKED_MR
  1243. 433 uniform sampler2D m_MetallicRoughnessMap;
  1244. 434 #else
  1245. 435 #ifdef METALLICMAP
  1246. 436 uniform sampler2D m_MetallicMap;
  1247. 437 #endif
  1248. 438 #ifdef ROUGHNESSMAP
  1249. 439 uniform sampler2D m_RoughnessMap;
  1250. 440 #endif
  1251. 441 #endif
  1252. 442
  1253. 443 #ifdef EMISSIVE
  1254. 444 uniform vec4 m_Emissive;
  1255. 445 #endif
  1256. 446 #ifdef EMISSIVEMAP
  1257. 447 uniform sampler2D m_EmissiveMap;
  1258. 448 #endif
  1259. 449 #if defined(EMISSIVE) || defined(EMISSIVEMAP)
  1260. 450 uniform float m_EmissivePower;
  1261. 451 uniform float m_EmissiveIntensity;
  1262. 452 #endif
  1263. 453
  1264. 454 #ifdef SPECGLOSSPIPELINE
  1265. 455
  1266. 456 uniform vec4 m_Specular;
  1267. 457 uniform float m_Glossiness;
  1268. 458 #ifdef USE_PACKED_SG
  1269. 459 uniform sampler2D m_SpecularGlossinessMap;
  1270. 460 #else
  1271. 461 uniform sampler2D m_SpecularMap;
  1272. 462 uniform sampler2D m_GlossinessMap;
  1273. 463 #endif
  1274. 464 #endif
  1275. 465
  1276. 466 #ifdef PARALLAXMAP
  1277. 467 uniform sampler2D m_ParallaxMap;
  1278. 468 #endif
  1279. 469 #if (defined(PARALLAXMAP) || (defined(NORMALMAP_PARALLAX) && defined(NORMALMAP)))
  1280. 470 uniform float m_ParallaxHeight;
  1281. 471 #endif
  1282. 472
  1283. 473 #ifdef LIGHTMAP
  1284. 474 uniform sampler2D m_LightMap;
  1285. 475 #endif
  1286. 476
  1287. 477 #if defined(NORMALMAP) || defined(PARALLAXMAP)
  1288. 478 uniform sampler2D m_NormalMap;
  1289. 479 varying vec4 wTangent;
  1290. 480 #endif
  1291. 481 varying vec3 wNormal;
  1292. 482
  1293. 483 #ifdef DISCARD_ALPHA
  1294. 484 uniform float m_AlphaDiscardThreshold;
  1295. 485 #endif
  1296. 486
  1297. 487 void main(){
  1298. 488 vec2 newTexCoord;
  1299. 489 vec3 viewDir = normalize(g_CameraPosition - wPosition);
  1300. 490
  1301. 491 vec3 norm = normalize(wNormal);
  1302. 492 #if defined(NORMALMAP) || defined(PARALLAXMAP)
  1303. 493 vec3 tan = normalize(wTangent.xyz);
  1304. 494 mat3 tbnMat = mat3(tan, wTangent.w * cross( (norm), (tan)), norm);
  1305. 495 #endif
  1306. 496
  1307. 497 #if (defined(PARALLAXMAP) || (defined(NORMALMAP_PARALLAX) && defined(NORMALMAP)))
  1308. 498 vec3 vViewDir = viewDir * tbnMat;
  1309. 499 #ifdef STEEP_PARALLAX
  1310. 500 #ifdef NORMALMAP_PARALLAX
  1311. 501 //parallax map is stored in the alpha channel of the normal map
  1312. 502 newTexCoord = steepParallaxOffset(m_NormalMap, vViewDir, texCoord, m_ParallaxHeight);
  1313. 503 #else
  1314. 504 //parallax map is a texture
  1315. 505 newTexCoord = steepParallaxOffset(m_ParallaxMap, vViewDir, texCoord, m_ParallaxHeight);
  1316. 506 #endif
  1317. 507 #else
  1318. 508 #ifdef NORMALMAP_PARALLAX
  1319. 509 //parallax map is stored in the alpha channel of the normal map
  1320. 510 newTexCoord = classicParallaxOffset(m_NormalMap, vViewDir, texCoord, m_ParallaxHeight);
  1321. 511 #else
  1322. 512 //parallax map is a texture
  1323. 513 newTexCoord = classicParallaxOffset(m_ParallaxMap, vViewDir, texCoord, m_ParallaxHeight);
  1324. 514 #endif
  1325. 515 #endif
  1326. 516 #else
  1327. 517 newTexCoord = texCoord;
  1328. 518 #endif
  1329. 519
  1330. 520 #ifdef BASECOLORMAP
  1331. 521 vec4 albedo = texture2D(m_BaseColorMap, newTexCoord) * Color;
  1332. 522 #else
  1333. 523 vec4 albedo = Color;
  1334. 524 #endif
  1335. 525
  1336. 526 #ifdef USE_PACKED_MR
  1337. 527 vec2 rm = texture2D(m_MetallicRoughnessMap, newTexCoord).gb;
  1338. 528 float Roughness = rm.x * max(m_Roughness, 1e-4);
  1339. 529 float Metallic = rm.y * max(m_Metallic, 0.0);
  1340. 530 #else
  1341. 531 #ifdef ROUGHNESSMAP
  1342. 532 float Roughness = texture2D(m_RoughnessMap, newTexCoord).r * max(m_Roughness, 1e-4);
  1343. 533 #else
  1344. 534 float Roughness = max(m_Roughness, 1e-4);
  1345. 535 #endif
  1346. 536 #ifdef METALLICMAP
  1347. 537 float Metallic = texture2D(m_MetallicMap, newTexCoord).r * max(m_Metallic, 0.0);
  1348. 538 #else
  1349. 539 float Metallic = max(m_Metallic, 0.0);
  1350. 540 #endif
  1351. 541 #endif
  1352. 542
  1353. 543 float alpha = albedo.a;
  1354. 544
  1355. 545 #ifdef DISCARD_ALPHA
  1356. 546 if(alpha < m_AlphaDiscardThreshold){
  1357. 547 discard;
  1358. 548 }
  1359. 549 #endif
  1360. 550
  1361. 551 // ***********************
  1362. 552 // Read from textures
  1363. 553 // ***********************
  1364. 554 #if defined(NORMALMAP)
  1365. 555 vec4 normalHeight = texture2D(m_NormalMap, newTexCoord);
  1366. 556 //Note the -2.0 and -1.0. We invert the green channel of the normal map,
  1367. 557 //as it's complient with normal maps generated with blender.
  1368. 558 //see http://hub.jmonkeyengine.org/forum/topic/parallax-mapping-fundamental-bug/#post-256898
  1369. 559 //for more explanation.
  1370. 560 vec3 normal = normalize((normalHeight.xyz * vec3(2.0, NORMAL_TYPE * 2.0, 2.0) - vec3(1.0, NORMAL_TYPE * 1.0, 1.0)));
  1371. 561 normal = normalize(tbnMat * normal);
  1372. 562 //normal = normalize(normal * inverse(tbnMat));
  1373. 563 #else
  1374. 564 vec3 normal = norm;
  1375. 565 #endif
  1376. 566
  1377. 567 #ifdef SPECGLOSSPIPELINE
  1378. 568
  1379. 569 #ifdef USE_PACKED_SG
  1380. 570 vec4 specularColor = texture2D(m_SpecularGlossinessMap, newTexCoord);
  1381. 571 float glossiness = specularColor.a * m_Glossiness;
  1382. 572 specularColor *= m_Specular;
  1383. 573 #else
  1384. 574 #ifdef SPECULARMAP
  1385. 575 vec4 specularColor = texture2D(m_SpecularMap, newTexCoord);
  1386. 576 #else
  1387. 577 vec4 specularColor = vec4(1.0);
  1388. 578 #endif
  1389. 579 #ifdef GLOSSINESSMAP
  1390. 580 float glossiness = texture2D(m_GlossinessMap, newTexCoord).r * m_Glossiness;
  1391. 581 #else
  1392. 582 float glossiness = m_Glossiness;
  1393. 583 #endif
  1394. 584 specularColor *= m_Specular;
  1395. 585 #endif
  1396. 586 vec4 diffuseColor = albedo;// * (1.0 - max(max(specularColor.r, specularColor.g), specularColor.b));
  1397. 587 Roughness = 1.0 - glossiness;
  1398. 588 vec3 fZero = specularColor.xyz;
  1399. 589 #else
  1400. 590 float specular = 0.5;
  1401. 591 float nonMetalSpec = 0.08 * specular;
  1402. 592 vec4 specularColor = (nonMetalSpec - nonMetalSpec * Metallic) + albedo * Metallic;
  1403. 593 vec4 diffuseColor = albedo - albedo * Metallic;
  1404. 594 vec3 fZero = vec3(specular);
  1405. 595 #endif
  1406. 596
  1407. 597 gl_FragColor.rgb = vec3(0.0);
  1408. 598 vec3 ao = vec3(1.0);
  1409. 599
  1410. 600 #ifdef LIGHTMAP
  1411. 601 vec3 lightMapColor;
  1412. 602 #ifdef SEPARATE_TEXCOORD
  1413. 603 lightMapColor = texture2D(m_LightMap, texCoord2).rgb;
  1414. 604 #else
  1415. 605 lightMapColor = texture2D(m_LightMap, texCoord).rgb;
  1416. 606 #endif
  1417. 607 #ifdef AO_MAP
  1418. 608 lightMapColor.gb = lightMapColor.rr;
  1419. 609 ao = lightMapColor;
  1420. 610 #else
  1421. 611 gl_FragColor.rgb += diffuseColor.rgb * lightMapColor;
  1422. 612 #endif
  1423. 613 specularColor.rgb *= lightMapColor;
  1424. 614 #endif
  1425. 615
  1426. 616
  1427. 617 float ndotv = max( dot( normal, viewDir ),0.0);
  1428. 618 for( int i = 0;i < NB_LIGHTS; i+=3){
  1429. 619 vec4 lightColor = g_LightData[i];
  1430. 620 vec4 lightData1 = g_LightData[i+1];
  1431. 621 vec4 lightDir;
  1432. 622 vec3 lightVec;
  1433. 623 lightComputeDir(wPosition, lightColor.w, lightData1, lightDir, lightVec);
  1434. 624
  1435. 625 float fallOff = 1.0;
  1436. 626 #if __VERSION__ >= 110
  1437. 627 // allow use of control flow
  1438. 628 if(lightColor.w > 1.0){
  1439. 629 #endif
  1440. 630 fallOff = computeSpotFalloff(g_LightData[i+2], lightVec);
  1441. 631 #if __VERSION__ >= 110
  1442. 632 }
  1443. 633 #endif
  1444. 634 //point light attenuation
  1445. 635 fallOff *= lightDir.w;
  1446. 636
  1447. 637 lightDir.xyz = normalize(lightDir.xyz);
  1448. 638 vec3 directDiffuse;
  1449. 639 vec3 directSpecular;
  1450. 640
  1451. 641 float hdotv = PBR_ComputeDirectLight(normal, lightDir.xyz, viewDir,
  1452. 642 lightColor.rgb, fZero, Roughness, ndotv,
  1453. 643 directDiffuse, directSpecular);
  1454. 644
  1455. 645 vec3 directLighting = diffuseColor.rgb *directDiffuse + directSpecular;
  1456. 646
  1457. 647 gl_FragColor.rgb += directLighting * fallOff;
  1458. 648 }
  1459. 649
  1460. 650 #if NB_PROBES >= 1
  1461. 651 vec3 color1 = vec3(0.0);
  1462. 652 vec3 color2 = vec3(0.0);
  1463. 653 vec3 color3 = vec3(0.0);
  1464. 654 float weight1 = 1.0;
  1465. 655 float weight2 = 0.0;
  1466. 656 float weight3 = 0.0;
  1467. 657
  1468. 658 float ndf = renderProbe(viewDir, wPosition, normal, norm, Roughness, diffuseColor, specularColor, ndotv, ao, g_LightProbeData, g_ShCoeffs, g_PrefEnvMap, color1);
  1469. 659 #if NB_PROBES >= 2
  1470. 660 float ndf2 = renderProbe(viewDir, wPosition, normal, norm, Roughness, diffuseColor, specularColor, ndotv, ao, g_LightProbeData2, g_ShCoeffs2, g_PrefEnvMap2, color2);
  1471. 661 #endif
  1472. 662 #if NB_PROBES == 3
  1473. 663 float ndf3 = renderProbe(viewDir, wPosition, normal, norm, Roughness, diffuseColor, specularColor, ndotv, ao, g_LightProbeData3, g_ShCoeffs3, g_PrefEnvMap3, color3);
  1474. 664 #endif
  1475. 665
  1476. 666 #if NB_PROBES >= 2
  1477. 667 float invNdf = max(1.0 - ndf,0.0);
  1478. 668 float invNdf2 = max(1.0 - ndf2,0.0);
  1479. 669 float sumNdf = ndf + ndf2;
  1480. 670 float sumInvNdf = invNdf + invNdf2;
  1481. 671 #if NB_PROBES == 3
  1482. 672 float invNdf3 = max(1.0 - ndf3,0.0);
  1483. 673 sumNdf += ndf3;
  1484. 674 sumInvNdf += invNdf3;
  1485. 675 weight3 = ((1.0 - (ndf3 / sumNdf)) / (NB_PROBES - 1)) * (invNdf3 / sumInvNdf);
  1486. 676 #endif
  1487. 677
  1488. 678 weight1 = ((1.0 - (ndf / sumNdf)) / (NB_PROBES - 1)) * (invNdf / sumInvNdf);
  1489. 679 weight2 = ((1.0 - (ndf2 / sumNdf)) / (NB_PROBES - 1)) * (invNdf2 / sumInvNdf);
  1490. 680
  1491. 681 float weightSum = weight1 + weight2 + weight3;
  1492. 682
  1493. 683 weight1 /= weightSum;
  1494. 684 weight2 /= weightSum;
  1495. 685 weight3 /= weightSum;
  1496. 686 #endif
  1497. 687
  1498. 688 #ifdef USE_AMBIENT_LIGHT
  1499. 689 color1.rgb *= g_AmbientLightColor.rgb;
  1500. 690 color2.rgb *= g_AmbientLightColor.rgb;
  1501. 691 color3.rgb *= g_AmbientLightColor.rgb;
  1502. 692 #endif
  1503. 693 gl_FragColor.rgb += color1 * clamp(weight1,0.0,1.0) + color2 * clamp(weight2,0.0,1.0) + color3 * clamp(weight3,0.0,1.0);
  1504. 694
  1505. 695 #endif
  1506. 696
  1507. 697 #if defined(EMISSIVE) || defined (EMISSIVEMAP)
  1508. 698 #ifdef EMISSIVEMAP
  1509. 699 vec4 emissive = texture2D(m_EmissiveMap, newTexCoord);
  1510. 700 #else
  1511. 701 vec4 emissive = m_Emissive;
  1512. 702 #endif
  1513. 703 gl_FragColor += emissive * pow(emissive.a, m_EmissivePower) * m_EmissiveIntensity;
  1514. 704 #endif
  1515. 705 gl_FragColor.a = alpha;
  1516. 706
  1517. 707 }
  1518.  
  1519. BUILD SUCCESSFUL (total time: 14 seconds)
  1520.  
Advertisement
Add Comment
Please, Sign In to add comment