SHARE
TWEET

Godot iOS 10.11 log

Mux213 Jun 19th, 2017 (edited) 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 2017-07-12 11:39:03.249753+1000 godot_opt.iphone[10368:6535694] [DYMTLInitPlatform] platform initialization successful
  2. *********** main.m
  3. running app main
  4. **************** app delegate init
  5. after init super 0x139d0e6c0
  6. 2017-07-12 11:39:03.825856+1000 godot_opt.iphone[10368:6535493] Metal GPU Frame Capture Enabled
  7. 2017-07-12 11:39:03.828714+1000 godot_opt.iphone[10368:6535493] Metal API Validation Enabled
  8. ******** screen size 640, 1136
  9. after init gles 0x139d0e6c0
  10. ******** adding observer for sound routing changes
  11. glview is 0x139d0e6c0
  12. Path: /var/containers/Bundle/Application/2487BD9B-06FB-4928-95A5-6C70C8AB2F5A/godot_ios.app
  13. godot_iphone /var/containers/Bundle/Application/2487BD9B-06FB-4928-95A5-6C70C8AB2F5A/godot_ios.app/godot_opt.iphone
  14. cwd /private/var/containers/Bundle/Application/2487BD9B-06FB-4928-95A5-6C70C8AB2F5A/godot_ios.app
  15. os created
  16. setup 0
  17. cadisaplylink: 1start animation!
  18. ******** screen size 640, 1136
  19. ******** screen size 640, 1136
  20. setting data dir to /private/var/mobile/Containers/Data/Application/5A13CF83-D230-4DF2-830C-733F6AD474AB/Documents from /var/mobile/Containers/Data/Application/5A13CF83-D230-4DF2-830C-733F6AD474AB/Documents
  21. GLES3: max extensions: 19
  22. hdr supported: 0
  23. GLES3: max ubo light: 102
  24. GLES3: max ubo reflections: 113, ubo size: 144
  25. ERROR: bind_methodfi: Class GameCenter already has a method connect
  26.    At: core/class_db.cpp:1079.
  27. ERROR: bind_methodfi: Class GameCenter already has a method is_connected
  28.    At: core/class_db.cpp:1079.
  29. 2017-07-12 11:39:04.765181+1000 godot_opt.iphone[10368:6535493] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
  30. 2017-07-12 11:39:04.768599+1000 godot_opt.iphone[10368:6535493] [MC] Reading from public effective user settings.
  31. WARNING: not found: locale/translation_remaps
  32. 2017-07-12 11:39:05.170 godot_opt.iphone[10368:6535493] 506 error
  33. ERROR: _render_target_allocate: Condition ' status != 0x8CD5 ' is true.
  34.    At: drivers/gles3/rasterizer_storage_gles3.cpp:6124.
  35. ERROR: environment_set_tonemap: Condition ' !env ' is true.
  36.    At: drivers/gles3/rasterizer_scene_gles3.cpp:922.
  37. ERROR: environment_set_adjustment: Condition ' !env ' is true.
  38.    At: drivers/gles3/rasterizer_scene_gles3.cpp:937.
  39. ERROR: load_image: Condition ' p_image.is_null() ' is true. returned: ERR_INVALID_PARAMETER
  40.    At: core/io/image_loader.cpp:47.
  41. 1: #version 300 es
  42. 2: #define MAX_LIGHT_DATA_STRUCTS 102
  43. 3: #define MAX_FORWARD_LIGHTS 8
  44. 4: #define MAX_REFLECTION_DATA_STRUCTS 113
  45. 5: #define MAX_SKELETON_BONES 341
  46. 6: #define USE_LIGHT_DIRECTIONAL
  47. 7: #define USE_FORWARD_LIGHTING
  48. 8: #define SHADOW_MODE_PCF_5
  49. 9: #define VCT_QUALITY_HIGH
  50. 10: precision highp float;
  51. 11: precision highp int;
  52. 12:
  53. 13: /* texture unit usage, N is max_texture_unity-N
  54. 14:
  55. 15: 1-skeleton
  56. 16: 2-radiance
  57. 17: 3-reflection_atlas
  58. 18: 4-directional_shadow
  59. 19: 5-shadow_atlas
  60. 20: 6-decal_atlas
  61. 21: 7-screen
  62. 22: 8-depth
  63. 23: 9-probe1
  64. 24: 10-probe2
  65. 25:
  66. 26: */
  67. 27:
  68. 28: uniform highp mat4 world_transform;
  69. 29:
  70. 30: #define M_PI 3.14159265359
  71. 31:
  72. 32: /* Varyings */
  73. 33:
  74. 34: #if defined(ENABLE_COLOR_INTERP)
  75. 35: in vec4 color_interp;
  76. 36: #endif
  77. 37:
  78. 38: #if defined(ENABLE_UV_INTERP)
  79. 39: in vec2 uv_interp;
  80. 40: #endif
  81. 41:
  82. 42: #if defined(ENABLE_UV2_INTERP)
  83. 43: in vec2 uv2_interp;
  84. 44: #endif
  85. 45:
  86. 46: #if defined(ENABLE_TANGENT_INTERP) || defined(ENABLE_NORMALMAP) || defined(LIGHT_USE_ANISOTROPY)
  87. 47: in vec3 tangent_interp;
  88. 48: in vec3 binormal_interp;
  89. 49: #endif
  90. 50:
  91. 51: in highp vec3 vertex_interp;
  92. 52: in vec3 normal_interp;
  93. 53:
  94. 54:
  95. 55: /* PBR CHANNELS */
  96. 56:
  97. 57: //used on forward mainly
  98. 58: uniform bool no_ambient_light;
  99. 59:
  100. 60:
  101. 61: #ifdef USE_RADIANCE_MAP
  102. 62:
  103. 63:
  104. 64:
  105. 65: layout(std140) uniform Radiance { //ubo:2
  106. 66:
  107. 67:     mat4 radiance_inverse_xform;
  108. 68:     float radiance_ambient_contribution;
  109. 69:
  110. 70: };
  111. 71:
  112. 72: #define RADIANCE_MAX_LOD 5.0
  113. 73:
  114. 74: #ifdef USE_RADIANCE_MAP_ARRAY
  115. 75:
  116. 76: uniform sampler2DArray radiance_map; //texunit:-2
  117. 77:
  118. 78: vec3 textureDualParaboloid(sampler2DArray p_tex, vec3 p_vec,float p_roughness) {
  119. 79:
  120. 80:     vec3 norm = normalize(p_vec);
  121. 81:     norm.xy/=1.0+abs(norm.z);
  122. 82:     norm.xy=norm.xy * vec2(0.5,0.25) + vec2(0.5,0.25);
  123. 83:
  124. 84:     // we need to lie the derivatives (normg) and assume that DP side is always the same
  125. 85:     // to get proper texure filtering
  126. 86:     vec2 normg=norm.xy;
  127. 87:     if (norm.z>0) {
  128. 88:         norm.y=0.5-norm.y+0.5;
  129. 89:     }
  130. 90:
  131. 91:     // thanks to OpenGL spec using floor(layer + 0.5) for texture arrays,
  132. 92:     // it's easy to have precision errors using fract() to interpolate layers
  133. 93:     // as such, using fixed point to ensure it works.
  134. 94:
  135. 95:     float index = p_roughness * RADIANCE_MAX_LOD;
  136. 96:     int indexi = int(index * 256.0);
  137. 97:     vec3 base = textureGrad(p_tex, vec3(norm.xy, float(indexi/256)),dFdx(normg),dFdy(normg)).xyz;
  138. 98:     vec3 next = textureGrad(p_tex, vec3(norm.xy, float(indexi/256+1)),dFdx(normg),dFdy(normg)).xyz;
  139. 99:     return mix(base,next,float(indexi%256)/256.0);
  140. 100: }
  141. 101:
  142. 102: #else
  143. 103:
  144. 104: uniform sampler2D radiance_map; //texunit:-2
  145. 105:
  146. 106: vec3 textureDualParaboloid(sampler2D p_tex, vec3 p_vec,float p_roughness) {
  147. 107:
  148. 108:    vec3 norm = normalize(p_vec);
  149. 109:    norm.xy/=1.0+abs(norm.z);
  150. 110:    norm.xy=norm.xy * vec2(0.5,0.25) + vec2(0.5,0.25);
  151. 111:    if (norm.z>0) {
  152. 112:        norm.y=0.5-norm.y+0.5;
  153. 113:    }
  154. 114:    return textureLod(p_tex, norm.xy, p_roughness * RADIANCE_MAX_LOD).xyz;
  155. 115: }
  156. 116:
  157. 117: #endif
  158. 118:
  159. 119: #endif
  160. 120:
  161. 121: /* Material Uniforms */
  162. 122:
  163. 123:
  164. 124:
  165. 125: #if defined(USE_MATERIAL)
  166. 126:
  167. 127: layout(std140) uniform UniformData {
  168. 128:
  169. 129:
  170. 130: };
  171. 131:
  172. 132: #endif
  173. 133:
  174. 134:
  175. 135: layout(std140) uniform SceneData {
  176. 136:
  177. 137:    highp mat4 projection_matrix;
  178. 138:    highp mat4 camera_inverse_matrix;
  179. 139:    highp mat4 camera_matrix;
  180. 140:
  181. 141:    highp vec4 ambient_light_color;
  182. 142:    highp vec4 bg_color;
  183. 143:
  184. 144:    vec4 fog_color_enabled;
  185. 145:    vec4 fog_sun_color_amount;
  186. 146:
  187. 147:    float ambient_energy;
  188. 148:    float bg_energy;
  189. 149:
  190. 150:    float z_offset;
  191. 151:    float z_slope_scale;
  192. 152:    float shadow_dual_paraboloid_render_zfar;
  193. 153:    float shadow_dual_paraboloid_render_side;
  194. 154:
  195. 155:    highp vec2 screen_pixel_size;
  196. 156:    vec2 shadow_atlas_pixel_size;
  197. 157:    vec2 directional_shadow_pixel_size;
  198. 158:
  199. 159:    float time;
  200. 160:    float z_far;
  201. 161:    float reflection_multiplier;
  202. 162:    float subsurface_scatter_width;
  203. 163:    float ambient_occlusion_affect_light;
  204. 164:
  205. 165:    bool fog_depth_enabled;
  206. 166:    float fog_depth_begin;
  207. 167:    float fog_depth_curve;
  208. 168:    bool fog_transmit_enabled;
  209. 169:    float fog_transmit_curve;
  210. 170:    bool fog_height_enabled;
  211. 171:    float fog_height_min;
  212. 172:    float fog_height_max;
  213. 173:    float fog_height_curve;
  214. 174: };
  215. 175:
  216. 176: //directional light data
  217. 177:
  218. 178: #ifdef USE_LIGHT_DIRECTIONAL
  219. 179:
  220. 180: layout(std140) uniform DirectionalLightData {
  221. 181:
  222. 182:    highp vec4 light_pos_inv_radius;
  223. 183:    mediump vec4 light_direction_attenuation;
  224. 184:    mediump vec4 light_color_energy;
  225. 185:    mediump vec4 light_params; //cone attenuation, angle, specular, shadow enabled,
  226. 186:    mediump vec4 light_clamp;
  227. 187:    mediump vec4 shadow_color_contact;
  228. 188:    highp mat4 shadow_matrix1;
  229. 189:    highp mat4 shadow_matrix2;
  230. 190:    highp mat4 shadow_matrix3;
  231. 191:    highp mat4 shadow_matrix4;
  232. 192:    mediump vec4 shadow_split_offsets;
  233. 193: };
  234. 194:
  235. 195:
  236. 196: uniform highp sampler2DShadow directional_shadow; //texunit:-4
  237. 197:
  238. 198: #endif
  239. 199:
  240. 200: //omni and spot
  241. 201:
  242. 202: struct LightData {
  243. 203:
  244. 204:    highp vec4 light_pos_inv_radius;
  245. 205:    mediump vec4 light_direction_attenuation;
  246. 206:    mediump vec4 light_color_energy;
  247. 207:    mediump vec4 light_params; //cone attenuation, angle, specular, shadow enabled,
  248. 208:    mediump vec4 light_clamp;
  249. 209:    mediump vec4 shadow_color_contact;
  250. 210:    highp mat4 shadow_matrix;
  251. 211:
  252. 212: };
  253. 213:
  254. 214:
  255. 215: layout(std140) uniform OmniLightData { //ubo:4
  256. 216:
  257. 217:    LightData omni_lights[MAX_LIGHT_DATA_STRUCTS];
  258. 218: };
  259. 219:
  260. 220: layout(std140) uniform SpotLightData { //ubo:5
  261. 221:
  262. 222:    LightData spot_lights[MAX_LIGHT_DATA_STRUCTS];
  263. 223: };
  264. 224:
  265. 225:
  266. 226: uniform highp sampler2DShadow shadow_atlas; //texunit:-5
  267. 227:
  268. 228:
  269. 229: struct ReflectionData {
  270. 230:
  271. 231:    mediump vec4 box_extents;
  272. 232:    mediump vec4 box_offset;
  273. 233:    mediump vec4 params; // intensity, 0, interior , boxproject
  274. 234:    mediump vec4 ambient; //ambient color, energy
  275. 235:    mediump vec4 atlas_clamp;
  276. 236:    highp mat4 local_matrix; //up to here for spot and omni, rest is for directional
  277. 237:    //notes: for ambientblend, use distance to edge to blend between already existing global environment
  278. 238: };
  279. 239:
  280. 240: layout(std140) uniform ReflectionProbeData { //ubo:6
  281. 241:
  282. 242:    ReflectionData reflections[MAX_REFLECTION_DATA_STRUCTS];
  283. 243: };
  284. 244: uniform mediump sampler2D reflection_atlas; //texunit:-3
  285. 245:
  286. 246:
  287. 247: #ifdef USE_FORWARD_LIGHTING
  288. 248:
  289. 249: uniform int omni_light_indices[MAX_FORWARD_LIGHTS];
  290. 250: uniform int omni_light_count;
  291. 251:
  292. 252: uniform int spot_light_indices[MAX_FORWARD_LIGHTS];
  293. 253: uniform int spot_light_count;
  294. 254:
  295. 255: uniform int reflection_indices[MAX_FORWARD_LIGHTS];
  296. 256: uniform int reflection_count;
  297. 257:
  298. 258: #endif
  299. 259:
  300. 260:
  301. 261: #if defined(SCREEN_TEXTURE_USED)
  302. 262:
  303. 263: uniform highp sampler2D screen_texture; //texunit:-7
  304. 264:
  305. 265: #endif
  306. 266:
  307. 267: #ifdef USE_MULTIPLE_RENDER_TARGETS
  308. 268:
  309. 269: layout(location=0) out vec4 diffuse_buffer;
  310. 270: layout(location=1) out vec4 specular_buffer;
  311. 271: layout(location=2) out vec4 normal_mr_buffer;
  312. 272: #if defined(ENABLE_SSS)
  313. 273: layout(location=3) out float sss_buffer;
  314. 274: #endif
  315. 275:
  316. 276: #else
  317. 277:
  318. 278: layout(location=0) out vec4 frag_color;
  319. 279:
  320. 280: #endif
  321. 281:
  322. 282: in highp vec4 position_interp;
  323. 283: uniform highp sampler2D depth_buffer; //texunit:-8
  324. 284:
  325. 285: float contact_shadow_compute(vec3 pos, vec3 dir, float max_distance) {
  326. 286:
  327. 287:    if (abs(dir.z)>0.99)
  328. 288:        return 1.0;
  329. 289:
  330. 290:    vec3 endpoint = pos+dir*max_distance;
  331. 291:    vec4 source = position_interp;
  332. 292:    vec4 dest = projection_matrix * vec4(endpoint, 1.0);
  333. 293:
  334. 294:    vec2 from_screen = (source.xy / source.w) * 0.5 + 0.5;
  335. 295:    vec2 to_screen = (dest.xy / dest.w) * 0.5 + 0.5;
  336. 296:
  337. 297:    vec2 screen_rel = to_screen - from_screen;
  338. 298:
  339. 299:    /*float pixel_size; //approximate pixel size
  340. 300:
  341. 301:    if (screen_rel.x > screen_rel.y) {
  342. 302:
  343. 303:        pixel_size = abs((pos.x-endpoint.x)/(screen_rel.x/screen_pixel_size.x));
  344. 304:    } else {
  345. 305:        pixel_size = abs((pos.y-endpoint.y)/(screen_rel.y/screen_pixel_size.y));
  346. 306:
  347. 307:    }*/
  348. 308:    vec4 bias = projection_matrix * vec4(pos+vec3(0.0,0.0,0.04), 1.0); //todo un-harcode the 0.04
  349. 309:
  350. 310:
  351. 311:
  352. 312:    vec2 pixel_incr = normalize(screen_rel)*screen_pixel_size;
  353. 313:
  354. 314:    float steps = length(screen_rel) / length(pixel_incr);
  355. 315:
  356. 316:    //steps=10.0;
  357. 317:
  358. 318:    vec4 incr = (dest - source)/steps;
  359. 319:    float ratio=0.0;
  360. 320:    float ratio_incr = 1.0/steps;
  361. 321:
  362. 322:    do {
  363. 323:        source += incr*2.0;
  364. 324:        bias+=incr*2.0;
  365. 325:
  366. 326:        vec3 uv_depth = (source.xyz / source.w) * 0.5 + 0.5;
  367. 327:        float depth = texture(depth_buffer,uv_depth.xy).r;
  368. 328:
  369. 329:        if (depth < uv_depth.z) {
  370. 330:            if (depth > (bias.z/bias.w) * 0.5 + 0.5) {
  371. 331:                return min(pow(ratio,4.0),1.0);
  372. 332:            } else {
  373. 333:                return 1.0;
  374. 334:            }
  375. 335:        }
  376. 336:
  377. 337:
  378. 338:        ratio+=ratio_incr;
  379. 339:        steps-=1.0;
  380. 340:    } while (steps>0.0);
  381. 341:
  382. 342:    return 1.0;
  383. 343: }
  384. 344:
  385. 345: // GGX Specular
  386. 346: // Source: http://www.filmicworlds.com/images/ggx-opt/optimized-ggx.hlsl
  387. 347: float G1V(float dotNV, float k)
  388. 348: {
  389. 349:     return 1.0 / (dotNV * (1.0 - k) + k);
  390. 350: }
  391. 351:
  392. 352:
  393. 353: float SchlickFresnel(float u)
  394. 354: {
  395. 355:     float m = 1.0-u;
  396. 356:     float m2 = m*m;
  397. 357:     return m2*m2*m; // pow(m,5)
  398. 358: }
  399. 359:
  400. 360: float GTR1(float NdotH, float a)
  401. 361: {
  402. 362:     if (a >= 1.0) return 1.0/M_PI;
  403. 363:     float a2 = a*a;
  404. 364:     float t = 1.0 + (a2-1.0)*NdotH*NdotH;
  405. 365:     return (a2-1.0) / (M_PI*log(a2)*t);
  406. 366: }
  407. 367:
  408. 368:
  409. 369:
  410. 370: void light_compute(vec3 N, vec3 L,vec3 V,vec3 B, vec3 T,vec3 light_color,vec3 diffuse_color,  float specular_blob_intensity, float roughness, float rim,float rim_tint, float clearcoat, float clearcoat_gloss,float anisotropy,inout vec3 diffuse, inout vec3 specular) {
  411. 371:
  412. 372: #if defined(USE_LIGHT_SHADER_CODE)
  413. 373: //light is written by the light shader
  414. 374:
  415. 375:
  416. 376:
  417. 377:
  418. 378: #else
  419. 379:
  420. 380:    float dotNL = max(dot(N,L), 0.0 );
  421. 381:
  422. 382: #if defined(DIFFUSE_HALF_LAMBERT)
  423. 383:
  424. 384:    float hl = dot(N,L) * 0.5 + 0.5;
  425. 385:    diffuse += hl * light_color * diffuse_color;
  426. 386:
  427. 387: #elif defined(DIFFUSE_OREN_NAYAR)
  428. 388:
  429. 389:    {
  430. 390:        float LdotV = dot(L, V);
  431. 391:        float NdotL = dot(L, N);
  432. 392:        float NdotV = dot(N, V);
  433. 393:
  434. 394:        float s = LdotV - NdotL * NdotV;
  435. 395:        float t = mix(1.0, max(NdotL, NdotV), step(0.0, s));
  436. 396:
  437. 397:        float sigma2 = roughness * roughness;
  438. 398:        vec3 A = 1.0 + sigma2 * (diffuse_color / (sigma2 + 0.13) + 0.5 / (sigma2 + 0.33));
  439. 399:        float B = 0.45 * sigma2 / (sigma2 + 0.09);
  440. 400:
  441. 401:        diffuse += diffuse_color * max(0.0, NdotL) * (A + vec3(B) * s / t) / M_PI;
  442. 402:    }
  443. 403:
  444. 404: #elif defined(DIFFUSE_TOON)
  445. 405:
  446. 406:    diffuse += smoothstep(-roughness,max(roughness,0.01),dot(N,L)) * light_color * diffuse_color;
  447. 407:
  448. 408: #elif defined(DIFFUSE_BURLEY)
  449. 409:
  450. 410:    {
  451. 411:        float NdotL = dot(L, N);
  452. 412:        float NdotV = dot(N, V);
  453. 413:        float VdotH = dot(N, normalize(L+V));
  454. 414:        float energyBias = mix(roughness, 0.0, 0.5);
  455. 415:        float energyFactor = mix(roughness, 1.0, 1.0 / 1.51);
  456. 416:        float fd90 = energyBias + 2.0 * VdotH * VdotH * roughness;
  457. 417:        float f0 = 1.0;
  458. 418:        float lightScatter = f0 + (fd90 - f0) * pow(1.0 - NdotL, 5.0);
  459. 419:        float viewScatter = f0 + (fd90 - f0) * pow(1.0 - NdotV, 5.0);
  460. 420:
  461. 421:        diffuse+= light_color * diffuse_color * lightScatter * viewScatter * energyFactor;
  462. 422:    }
  463. 423: #else
  464. 424:    //lambert
  465. 425:    diffuse += dotNL * light_color * diffuse_color;
  466. 426: #endif
  467. 427:
  468. 428:
  469. 429:    float dotNV = max(dot(N,V), 0.0 );
  470. 430: #if defined(LIGHT_USE_RIM)
  471. 431:    float rim_light = pow(1.0-dotNV,(1.0-roughness)*16.0);
  472. 432:    diffuse += rim_light * rim * mix(vec3(1.0),diffuse_color,rim_tint) * light_color;
  473. 433: #endif
  474. 434:
  475. 435:
  476. 436:    if (roughness > 0.0) {
  477. 437:
  478. 438:
  479. 439:        // D
  480. 440:
  481. 441: #if defined(SPECULAR_BLINN)
  482. 442:
  483. 443:        vec3 H = normalize(V + L);
  484. 444:        float dotNH = max(dot(N,H), 0.0 );
  485. 445:        float intensity = pow( dotNH, (1.0-roughness) * 256.0);
  486. 446:        specular += light_color * intensity * specular_blob_intensity;
  487. 447:
  488. 448: #elif defined(SPECULAR_PHONG)
  489. 449:
  490. 450:         vec3 R = normalize(-reflect(L,N));
  491. 451:         float dotNV = max(0.0,dot(R,V));
  492. 452:         float intensity = pow( dotNV, (1.0-roughness) * 256.0);
  493. 453:         specular += light_color * intensity * specular_blob_intensity;
  494. 454:
  495. 455: #elif defined(SPECULAR_TOON)
  496. 456:
  497. 457:        vec3 R = normalize(-reflect(L,N));
  498. 458:        float dotNV = dot(R,V);
  499. 459:        float mid = 1.0-roughness;
  500. 460:        mid*=mid;
  501. 461:        float intensity = smoothstep(mid-roughness*0.5,mid+roughness*0.5,dotNV) * mid;
  502. 462:        diffuse += light_color * intensity * specular_blob_intensity; //write to diffuse, as in toon shading you generally want no reflection
  503. 463:
  504. 464: #elif defined(SPECULAR_DISABLED)
  505. 465:        //none..
  506. 466:
  507. 467: #else
  508. 468:        // shlick+ggx as default
  509. 469:        float alpha = roughness * roughness;
  510. 470:
  511. 471:        vec3 H = normalize(V + L);
  512. 472:
  513. 473:        float dotNH = max(dot(N,H), 0.0 );
  514. 474:        float dotLH = max(dot(L,H), 0.0 );
  515. 475:
  516. 476: #if defined(LIGHT_USE_ANISOTROPY)
  517. 477:
  518. 478:        float aspect = sqrt(1.0-anisotropy*0.9);
  519. 479:        float rx = roughness/aspect;
  520. 480:        float ry = roughness*aspect;
  521. 481:        float ax = rx*rx;
  522. 482:        float ay = ry*ry;
  523. 483:        float dotXH = dot( T, H );
  524. 484:        float dotYH = dot( B, H );
  525. 485:        float pi = M_PI;
  526. 486:        float denom = dotXH*dotXH / (ax*ax) + dotYH*dotYH / (ay*ay) + dotNH*dotNH;
  527. 487:        float D = 1.0 / ( pi * ax*ay * denom*denom );
  528. 488:
  529. 489: #else
  530. 490:        float alphaSqr = alpha * alpha;
  531. 491:        float pi = M_PI;
  532. 492:        float denom = dotNH * dotNH * (alphaSqr - 1.0) + 1.0;
  533. 493:        float D = alphaSqr / (pi * denom * denom);
  534. 494: #endif
  535. 495:        // F
  536. 496:        float F0 = 1.0;
  537. 497:        float dotLH5 = SchlickFresnel( dotLH );
  538. 498:        float F = F0 + (1.0 - F0) * (dotLH5);
  539. 499:
  540. 500:        // V
  541. 501:        float k = alpha / 2.0f;
  542. 502:        float vis = G1V(dotNL, k) * G1V(dotNV, k);
  543. 503:
  544. 504:        float speci = dotNL * D * F * vis;
  545. 505:
  546. 506:        specular += speci * light_color * specular_blob_intensity;
  547. 507: #endif
  548. 508:
  549. 509: #if defined(LIGHT_USE_CLEARCOAT)
  550. 510:        float Dr = GTR1(dotNH, mix(.1,.001,clearcoat_gloss));
  551. 511:        float Fr = mix(.04, 1.0, dotLH5);
  552. 512:        float Gr = G1V(dotNL, .25) * G1V(dotNV, .25);
  553. 513:
  554. 514:        specular += .25*clearcoat*Gr*Fr*Dr;
  555. 515: #endif
  556. 516:    }
  557. 517:
  558. 518:
  559. 519: #endif //defined(USE_LIGHT_SHADER_CODE)
  560. 520: }
  561. 521:
  562. 522:
  563. 523: float sample_shadow(highp sampler2DShadow shadow, vec2 shadow_pixel_size, vec2 pos, float depth, vec4 clamp_rect) {
  564. 524:
  565. 525: #ifdef SHADOW_MODE_PCF_13
  566. 526:
  567. 527:    float avg=textureProj(shadow,vec4(pos,depth,1.0));
  568. 528:    avg+=textureProj(shadow,vec4(pos+vec2(shadow_pixel_size.x,0.0),depth,1.0));
  569. 529:    avg+=textureProj(shadow,vec4(pos+vec2(-shadow_pixel_size.x,0.0),depth,1.0));
  570. 530:    avg+=textureProj(shadow,vec4(pos+vec2(0.0,shadow_pixel_size.y),depth,1.0));
  571. 531:    avg+=textureProj(shadow,vec4(pos+vec2(0.0,-shadow_pixel_size.y),depth,1.0));
  572. 532:    avg+=textureProj(shadow,vec4(pos+vec2(shadow_pixel_size.x,shadow_pixel_size.y),depth,1.0));
  573. 533:    avg+=textureProj(shadow,vec4(pos+vec2(-shadow_pixel_size.x,shadow_pixel_size.y),depth,1.0));
  574. 534:    avg+=textureProj(shadow,vec4(pos+vec2(shadow_pixel_size.x,-shadow_pixel_size.y),depth,1.0));
  575. 535:    avg+=textureProj(shadow,vec4(pos+vec2(-shadow_pixel_size.x,-shadow_pixel_size.y),depth,1.0));
  576. 536:    avg+=textureProj(shadow,vec4(pos+vec2(shadow_pixel_size.x*2.0,0.0),depth,1.0));
  577. 537:    avg+=textureProj(shadow,vec4(pos+vec2(-shadow_pixel_size.x*2.0,0.0),depth,1.0));
  578. 538:    avg+=textureProj(shadow,vec4(pos+vec2(0.0,shadow_pixel_size.y*2.0),depth,1.0));
  579. 539:    avg+=textureProj(shadow,vec4(pos+vec2(0.0,-shadow_pixel_size.y*2.0),depth,1.0));
  580. 540:    return avg*(1.0/13.0);
  581. 541:
  582. 542: #endif
  583. 543:
  584. 544: #ifdef SHADOW_MODE_PCF_5
  585. 545:
  586. 546:    float avg=textureProj(shadow,vec4(pos,depth,1.0));
  587. 547:    avg+=textureProj(shadow,vec4(pos+vec2(shadow_pixel_size.x,0.0),depth,1.0));
  588. 548:    avg+=textureProj(shadow,vec4(pos+vec2(-shadow_pixel_size.x,0.0),depth,1.0));
  589. 549:    avg+=textureProj(shadow,vec4(pos+vec2(0.0,shadow_pixel_size.y),depth,1.0));
  590. 550:    avg+=textureProj(shadow,vec4(pos+vec2(0.0,-shadow_pixel_size.y),depth,1.0));
  591. 551:    return avg*(1.0/5.0);
  592. 552: #endif
  593. 553:
  594. 554: #if !defined(SHADOW_MODE_PCF_5) && !defined(SHADOW_MODE_PCF_13)
  595. 555:
  596. 556:    return textureProj(shadow,vec4(pos,depth,1.0));
  597. 557: #endif
  598. 558:
  599. 559: }
  600. 560:
  601. 561: #ifdef RENDER_DEPTH_DUAL_PARABOLOID
  602. 562:
  603. 563: in highp float dp_clip;
  604. 564:
  605. 565: #endif
  606. 566:
  607. 567:
  608. 568:
  609. 569: #if 0
  610. 570: //need to save texture depth for this
  611. 571:
  612. 572: vec3 light_transmittance(float translucency,vec3 light_vec, vec3 normal, vec3 pos, float distance) {
  613. 573:
  614. 574:    float scale = 8.25 * (1.0 - translucency) / subsurface_scatter_width;
  615. 575:    float d = scale * distance;
  616. 576:
  617. 577:     /**
  618. 578:      * Armed with the thickness, we can now calculate the color by means of the
  619. 579:      * precalculated transmittance profile.
  620. 580:      * (It can be precomputed into a texture, for maximum performance):
  621. 581:      */
  622.  
  623. 582:    float dd = -d * d;
  624. 583:    vec3 profile = vec3(0.233, 0.455, 0.649) * exp(dd / 0.0064) +
  625. 584:             vec3(0.1,   0.336, 0.344) * exp(dd / 0.0484) +
  626. 585:             vec3(0.118, 0.198, 0.0)   * exp(dd / 0.187)  +
  627. 586:             vec3(0.113, 0.007, 0.007) * exp(dd / 0.567)  +
  628. 587:             vec3(0.358, 0.004, 0.0)   * exp(dd / 1.99)   +
  629. 588:             vec3(0.078, 0.0,   0.0)   * exp(dd / 7.41);
  630. 589:
  631. 590:     /**
  632. 591:      * Using the profile, we finally approximate the transmitted lighting from
  633. 592:      * the back of the object:
  634. 593:      */
  635. 594:     return profile * clamp(0.3 + dot(light_vec, normal),0.0,1.0);
  636. 595: }
  637. 596: #endif
  638. 597:
  639. 598: void light_process_omni(int idx, vec3 vertex, vec3 eye_vec,vec3 normal,vec3 binormal, vec3 tangent, vec3 albedo, float roughness, float rim, float rim_tint, float clearcoat, float clearcoat_gloss,float anisotropy,float p_blob_intensity,inout vec3 diffuse_light, inout vec3 specular_light) {
  640. 599:
  641. 600:    vec3 light_rel_vec = omni_lights[idx].light_pos_inv_radius.xyz-vertex;
  642. 601:    float light_length = length( light_rel_vec );
  643. 602:    float normalized_distance = light_length*omni_lights[idx].light_pos_inv_radius.w;
  644. 603:    vec3 light_attenuation = vec3(pow( max(1.0 - normalized_distance, 0.0), omni_lights[idx].light_direction_attenuation.w ));
  645. 604:
  646. 605:    if (omni_lights[idx].light_params.w>0.5) {
  647. 606:        //there is a shadowmap
  648. 607:
  649. 608:        highp vec3 splane=(omni_lights[idx].shadow_matrix * vec4(vertex,1.0)).xyz;
  650. 609:        float shadow_len=length(splane);
  651. 610:        splane=normalize(splane);
  652. 611:        vec4 clamp_rect=omni_lights[idx].light_clamp;
  653. 612:
  654. 613:        if (splane.z>=0.0) {
  655. 614:
  656. 615:            splane.z+=1.0;
  657. 616:
  658. 617:            clamp_rect.y+=clamp_rect.w;
  659. 618:
  660. 619:        } else {
  661. 620:
  662. 621:            splane.z=1.0 - splane.z;
  663. 622:
  664. 623:            /*
  665. 624:            if (clamp_rect.z<clamp_rect.w) {
  666. 625:                clamp_rect.x+=clamp_rect.z;
  667. 626:            } else {
  668. 627:                clamp_rect.y+=clamp_rect.w;
  669. 628:            }
  670. 629:            */
  671. 630:
  672. 631:        }
  673. 632:
  674. 633:        splane.xy/=splane.z;
  675. 634:        splane.xy=splane.xy * 0.5 + 0.5;
  676. 635:        splane.z = shadow_len * omni_lights[idx].light_pos_inv_radius.w;
  677. 636:
  678. 637:        splane.xy = clamp_rect.xy+splane.xy*clamp_rect.zw;
  679. 638:        float shadow = sample_shadow(shadow_atlas,shadow_atlas_pixel_size,splane.xy,splane.z,clamp_rect);
  680. 639:        if (shadow>0.01 && omni_lights[idx].shadow_color_contact.a>0.0) {
  681. 640:
  682. 641:            float contact_shadow = contact_shadow_compute(vertex,normalize(light_rel_vec),min(light_length,omni_lights[idx].shadow_color_contact.a));
  683. 642:            shadow=min(shadow,contact_shadow);
  684. 643:
  685. 644:
  686. 645:        }
  687. 646:        light_attenuation*=mix(omni_lights[idx].shadow_color_contact.rgb,vec3(1.0),shadow);
  688. 647:    }
  689. 648:
  690. 649:    light_compute(normal,normalize(light_rel_vec),eye_vec,binormal,tangent,omni_lights[idx].light_color_energy.rgb*light_attenuation,albedo,omni_lights[idx].light_params.z*p_blob_intensity,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,diffuse_light,specular_light);
  691. 650:
  692. 651: }
  693. 652:
  694. 653: void light_process_spot(int idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 binormal, vec3 tangent,vec3 albedo, float roughness, float rim,float rim_tint, float clearcoat, float clearcoat_gloss,float anisotropy,float p_blob_intensity, inout vec3 diffuse_light, inout vec3 specular_light) {
  695. 654:
  696. 655:    vec3 light_rel_vec = spot_lights[idx].light_pos_inv_radius.xyz-vertex;
  697. 656:    float light_length = length( light_rel_vec );
  698. 657:    float normalized_distance = light_length*spot_lights[idx].light_pos_inv_radius.w;
  699. 658:    vec3 light_attenuation = vec3(pow( max(1.0 - normalized_distance, 0.001), spot_lights[idx].light_direction_attenuation.w ));
  700. 659:    vec3 spot_dir = spot_lights[idx].light_direction_attenuation.xyz;
  701. 660:    float spot_cutoff=spot_lights[idx].light_params.y;
  702. 661:    float scos = max(dot(-normalize(light_rel_vec), spot_dir),spot_cutoff);
  703. 662:    float spot_rim = (1.0 - scos) / (1.0 - spot_cutoff);
  704. 663:    light_attenuation *= 1.0 - pow( max(spot_rim,0.001), spot_lights[idx].light_params.x);
  705. 664:
  706. 665:    if (spot_lights[idx].light_params.w>0.5) {
  707. 666:        //there is a shadowmap
  708. 667:        highp vec4 splane=(spot_lights[idx].shadow_matrix * vec4(vertex,1.0));
  709. 668:        splane.xyz/=splane.w;
  710. 669:
  711. 670:        float shadow = sample_shadow(shadow_atlas,shadow_atlas_pixel_size,splane.xy,splane.z,spot_lights[idx].light_clamp);
  712. 671:
  713. 672:        if (shadow>0.01 && spot_lights[idx].shadow_color_contact.a>0.0) {
  714. 673:
  715. 674:            float contact_shadow = contact_shadow_compute(vertex,normalize(light_rel_vec),min(light_length,spot_lights[idx].shadow_color_contact.a));
  716. 675:            shadow=min(shadow,contact_shadow);
  717. 676:
  718. 677:        }
  719. 678:
  720. 679:        light_attenuation*=mix(spot_lights[idx].shadow_color_contact.rgb,vec3(1.0),shadow);
  721. 680:    }
  722. 681:
  723. 682:    light_compute(normal,normalize(light_rel_vec),eye_vec,binormal,tangent,spot_lights[idx].light_color_energy.rgb*light_attenuation,albedo,spot_lights[idx].light_params.z*p_blob_intensity,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,diffuse_light,specular_light);
  724. 683:
  725. 684: }
  726. 685:
  727. 686: void reflection_process(int idx, vec3 vertex, vec3 normal,vec3 binormal, vec3 tangent,float roughness,float anisotropy,vec3 ambient,vec3 skybox, inout highp vec4 reflection_accum,inout highp vec4 ambient_accum) {
  728. 687:
  729. 688:    vec3 ref_vec = normalize(reflect(vertex,normal));
  730. 689:    vec3 local_pos = (reflections[idx].local_matrix * vec4(vertex,1.0)).xyz;
  731. 690:    vec3 box_extents = reflections[idx].box_extents.xyz;
  732. 691:
  733. 692:    if (any(greaterThan(abs(local_pos),box_extents))) { //out of the reflection box
  734. 693:        return;
  735. 694:    }
  736. 695:
  737. 696:    vec3 inner_pos = abs(local_pos / box_extents);
  738. 697:    float blend = max(inner_pos.x,max(inner_pos.y,inner_pos.z));
  739. 698:    //make blend more rounded
  740. 699:    blend=mix(length(inner_pos),blend,blend);
  741. 700:    blend*=blend;
  742. 701:    blend=1.001-blend;
  743. 702:
  744. 703:    if (reflections[idx].params.x>0.0){// compute reflection
  745. 704:
  746. 705:        vec3 local_ref_vec = (reflections[idx].local_matrix * vec4(ref_vec,0.0)).xyz;
  747. 706:
  748. 707:        if (reflections[idx].params.w > 0.5) { //box project
  749. 708:
  750. 709:            vec3 nrdir = normalize(local_ref_vec);
  751. 710:            vec3 rbmax = (box_extents - local_pos)/nrdir;
  752. 711:            vec3 rbmin = (-box_extents - local_pos)/nrdir;
  753. 712:
  754. 713:
  755. 714:            vec3 rbminmax = mix(rbmin,rbmax,greaterThan(nrdir,vec3(0.0,0.0,0.0)));
  756. 715:
  757. 716:            float fa = min(min(rbminmax.x, rbminmax.y), rbminmax.z);
  758. 717:            vec3 posonbox = local_pos + nrdir * fa;
  759. 718:            local_ref_vec = posonbox - reflections[idx].box_offset.xyz;
  760. 719:        }
  761. 720:
  762. 721:
  763. 722:
  764. 723:        vec3 splane=normalize(local_ref_vec);
  765. 724:        vec4 clamp_rect=reflections[idx].atlas_clamp;
  766. 725:
  767. 726:        splane.z*=-1.0;
  768. 727:        if (splane.z>=0.0) {
  769. 728:            splane.z+=1.0;
  770. 729:            clamp_rect.y+=clamp_rect.w;
  771. 730:        } else {
  772. 731:            splane.z=1.0 - splane.z;
  773. 732:            splane.y=-splane.y;
  774. 733:        }
  775. 734:
  776. 735:        splane.xy/=splane.z;
  777. 736:        splane.xy=splane.xy * 0.5 + 0.5;
  778. 737:
  779. 738:        splane.xy = splane.xy * clamp_rect.zw + clamp_rect.xy;
  780. 739:        splane.xy = clamp(splane.xy,clamp_rect.xy,clamp_rect.xy+clamp_rect.zw);
  781. 740:
  782. 741:        highp vec4 reflection;
  783. 742:        reflection.rgb = textureLod(reflection_atlas,splane.xy,roughness*5.0).rgb;
  784. 743:
  785. 744:        if (reflections[idx].params.z < 0.5) {
  786. 745:            reflection.rgb = mix(skybox,reflection.rgb,blend);
  787. 746:        }
  788. 747:        reflection.rgb*=reflections[idx].params.x;
  789. 748:        reflection.a = blend;
  790. 749:        reflection.rgb*=reflection.a;
  791. 750:
  792. 751:        reflection_accum+=reflection;
  793. 752:    }
  794. 753:
  795. 754:    if (reflections[idx].ambient.a>0.0) { //compute ambient using skybox
  796. 755:
  797. 756:
  798. 757:        vec3 local_amb_vec = (reflections[idx].local_matrix * vec4(normal,0.0)).xyz;
  799. 758:
  800. 759:        vec3 splane=normalize(local_amb_vec);
  801. 760:        vec4 clamp_rect=reflections[idx].atlas_clamp;
  802. 761:
  803. 762:        splane.z*=-1.0;
  804. 763:        if (splane.z>=0.0) {
  805. 764:            splane.z+=1.0;
  806. 765:            clamp_rect.y+=clamp_rect.w;
  807. 766:        } else {
  808. 767:            splane.z=1.0 - splane.z;
  809. 768:            splane.y=-splane.y;
  810. 769:        }
  811. 770:
  812. 771:        splane.xy/=splane.z;
  813. 772:        splane.xy=splane.xy * 0.5 + 0.5;
  814. 773:
  815. 774:        splane.xy = splane.xy * clamp_rect.zw + clamp_rect.xy;
  816. 775:        splane.xy = clamp(splane.xy,clamp_rect.xy,clamp_rect.xy+clamp_rect.zw);
  817. 776:
  818. 777:        highp vec4 ambient_out;
  819. 778:        ambient_out.a=blend;
  820. 779:        ambient_out.rgb = textureLod(reflection_atlas,splane.xy,5.0).rgb;
  821. 780:        ambient_out.rgb=mix(reflections[idx].ambient.rgb,ambient_out.rgb,reflections[idx].ambient.a);
  822. 781:        if (reflections[idx].params.z < 0.5) {
  823. 782:            ambient_out.rgb = mix(ambient,ambient_out.rgb,blend);
  824. 783:        }
  825. 784:
  826. 785:        ambient_out.rgb *= ambient_out.a;
  827. 786:        ambient_accum+=ambient_out;
  828. 787:    } else {
  829. 788:
  830. 789:        highp vec4 ambient_out;
  831. 790:        ambient_out.a=blend;
  832. 791:        ambient_out.rgb=reflections[idx].ambient.rgb;
  833. 792:        if (reflections[idx].params.z < 0.5) {
  834. 793:            ambient_out.rgb = mix(ambient,ambient_out.rgb,blend);
  835. 794:        }
  836. 795:        ambient_out.rgb *= ambient_out.a;
  837. 796:        ambient_accum+=ambient_out;
  838. 797:
  839. 798:    }
  840. 799: }
  841. 800:
  842. 801: #ifdef USE_GI_PROBES
  843. 802:
  844. 803: uniform mediump sampler3D gi_probe1; //texunit:-9
  845. 804: uniform highp mat4 gi_probe_xform1;
  846. 805: uniform highp vec3 gi_probe_bounds1;
  847. 806: uniform highp vec3 gi_probe_cell_size1;
  848. 807: uniform highp float gi_probe_multiplier1;
  849. 808: uniform highp float gi_probe_bias1;
  850. 809: uniform bool gi_probe_blend_ambient1;
  851. 810:
  852. 811: uniform mediump sampler3D gi_probe2; //texunit:-10
  853. 812: uniform highp mat4 gi_probe_xform2;
  854. 813: uniform highp vec3 gi_probe_bounds2;
  855. 814: uniform highp vec3 gi_probe_cell_size2;
  856. 815: uniform highp float gi_probe_multiplier2;
  857. 816: uniform highp float gi_probe_bias2;
  858. 817: uniform bool gi_probe2_enabled;
  859. 818: uniform bool gi_probe_blend_ambient2;
  860. 819:
  861. 820: vec3 voxel_cone_trace(sampler3D probe, vec3 cell_size, vec3 pos, vec3 ambient, bool blend_ambient, vec3 direction, float tan_half_angle, float max_distance, float p_bias) {
  862. 821:
  863. 822:
  864. 823:    float dist = p_bias;//1.0; //dot(direction,mix(vec3(-1.0),vec3(1.0),greaterThan(direction,vec3(0.0))))*2.0;
  865. 824:    float alpha=0.0;
  866. 825:    vec3 color = vec3(0.0);
  867. 826:
  868. 827:    while(dist < max_distance && alpha < 0.95) {
  869. 828:        float diameter = max(1.0, 2.0 * tan_half_angle * dist);
  870. 829:        vec4 scolor = textureLod(probe, (pos + dist * direction) * cell_size, log2(diameter) );
  871. 830:        float a = (1.0 - alpha);
  872. 831:        color += scolor.rgb * a;
  873. 832:        alpha += a * scolor.a;
  874. 833:        dist += diameter * 0.5;
  875. 834:    }
  876. 835:
  877. 836:    if (blend_ambient) {
  878. 837:        color.rgb = mix(ambient,color.rgb,min(1.0,alpha/0.95));
  879. 838:    }
  880. 839:
  881. 840:    return color;
  882. 841: }
  883. 842:
  884. 843: void gi_probe_compute(sampler3D probe, mat4 probe_xform, vec3 bounds,vec3 cell_size,vec3 pos, vec3 ambient, vec3 environment, bool blend_ambient,float multiplier, mat3 normal_mtx,vec3 ref_vec, float roughness,float p_bias, out vec4 out_spec, out vec4 out_diff) {
  885. 844:
  886. 845:
  887. 846:
  888. 847:    vec3 probe_pos = (probe_xform * vec4(pos,1.0)).xyz;
  889. 848:    vec3 ref_pos = (probe_xform * vec4(pos+ref_vec,1.0)).xyz;
  890. 849:
  891. 850:    ref_vec = normalize(ref_pos - probe_pos);
  892. 851:
  893. 852: /* out_diff.rgb = voxel_cone_trace(probe,cell_size,probe_pos,normalize((probe_xform * vec4(ref_vec,0.0)).xyz),0.0 ,100.0);
  894. 853:    out_diff.a = 1.0;
  895. 854:    return;*/
  896. 855:    //out_diff = vec4(textureLod(probe,probe_pos*cell_size,3.0).rgb,1.0);
  897. 856:    //return;
  898. 857:
  899. 858:    if (any(bvec2(any(lessThan(probe_pos,vec3(0.0))),any(greaterThan(probe_pos,bounds)))))
  900. 859:        return;
  901. 860:
  902. 861:    vec3 blendv = probe_pos/bounds * 2.0 - 1.0;
  903. 862:    float blend = 1.001-max(blendv.x,max(blendv.y,blendv.z));
  904. 863:    blend=1.0;
  905. 864:
  906. 865:    float max_distance = length(bounds);
  907. 866:
  908. 867:    //radiance
  909. 868: #ifdef VCT_QUALITY_HIGH
  910. 869:
  911. 870: #define MAX_CONE_DIRS 6
  912. 871:    vec3 cone_dirs[MAX_CONE_DIRS] = vec3[] (
  913. 872:        vec3(0, 0, 1),
  914. 873:        vec3(0.866025, 0, 0.5),
  915. 874:        vec3(0.267617, 0.823639, 0.5),
  916. 875:        vec3(-0.700629, 0.509037, 0.5),
  917. 876:        vec3(-0.700629, -0.509037, 0.5),
  918. 877:        vec3(0.267617, -0.823639, 0.5)
  919. 878:    );
  920. 879:
  921. 880:    float cone_weights[MAX_CONE_DIRS] = float[](0.25, 0.15, 0.15, 0.15, 0.15, 0.15);
  922. 881:    float cone_angle_tan = 0.577;
  923. 882:    float min_ref_tan = 0.0;
  924. 883: #else
  925. 884:
  926. 885: #define MAX_CONE_DIRS 4
  927. 886:
  928. 887:    vec3 cone_dirs[MAX_CONE_DIRS] = vec3[] (
  929. 888:            vec3(0.707107, 0, 0.707107),
  930. 889:            vec3(0, 0.707107, 0.707107),
  931. 890:            vec3(-0.707107, 0, 0.707107),
  932. 891:            vec3(0, -0.707107, 0.707107)
  933. 892:    );
  934. 893:
  935. 894:    float cone_weights[MAX_CONE_DIRS] = float[](0.25, 0.25, 0.25, 0.25);
  936. 895:    float cone_angle_tan = 0.98269;
  937. 896:    max_distance*=0.5;
  938. 897:    float min_ref_tan = 0.2;
  939. 898:
  940. 899: #endif
  941. 900:    vec3 light=vec3(0.0);
  942. 901:    for(int i=0;i<MAX_CONE_DIRS;i++) {
  943. 902:
  944. 903:        vec3 dir = normalize( (probe_xform * vec4(pos + normal_mtx * cone_dirs[i],1.0)).xyz - probe_pos);
  945. 904:        light+=cone_weights[i] * voxel_cone_trace(probe,cell_size,probe_pos,ambient,blend_ambient,dir,cone_angle_tan,max_distance,p_bias);
  946. 905:
  947. 906:    }
  948. 907:
  949. 908:    light*=multiplier;
  950. 909:
  951. 910:    out_diff = vec4(light*blend,blend);
  952. 911:
  953. 912:    //irradiance
  954. 913:
  955. 914:    vec3 irr_light =  voxel_cone_trace(probe,cell_size,probe_pos,environment,blend_ambient,ref_vec,max(min_ref_tan,tan(roughness * 0.5 * M_PI)) ,max_distance,p_bias);
  956. 915:
  957. 916:    irr_light *= multiplier;
  958. 917:    //irr_light=vec3(0.0);
  959. 918:
  960. 919:    out_spec = vec4(irr_light*blend,blend);
  961. 920: }
  962. 921:
  963. 922:
  964. 923: void gi_probes_compute(vec3 pos, vec3 normal, float roughness, inout vec3 out_specular, inout vec3 out_ambient) {
  965. 924:
  966. 925:    roughness = roughness * roughness;
  967. 926:
  968. 927:    vec3 ref_vec = normalize(reflect(normalize(pos),normal));
  969. 928:
  970. 929:    //find arbitrary tangent and bitangent, then build a matrix
  971. 930:    vec3 v0 = abs(normal.z) < 0.999 ? vec3(0, 0, 1) : vec3(0, 1, 0);
  972. 931:    vec3 tangent = normalize(cross(v0, normal));
  973. 932:    vec3 bitangent = normalize(cross(tangent, normal));
  974. 933:    mat3 normal_mat = mat3(tangent,bitangent,normal);
  975. 934:
  976. 935:    vec4 diff_accum = vec4(0.0);
  977. 936:    vec4 spec_accum = vec4(0.0);
  978. 937:
  979. 938:    vec3 ambient = out_ambient;
  980. 939:    out_ambient = vec3(0.0);
  981. 940:
  982. 941:    vec3 environment = out_specular;
  983. 942:
  984. 943:    out_specular = vec3(0.0);
  985. 944:
  986. 945:    gi_probe_compute(gi_probe1,gi_probe_xform1,gi_probe_bounds1,gi_probe_cell_size1,pos,ambient,environment,gi_probe_blend_ambient1,gi_probe_multiplier1,normal_mat,ref_vec,roughness,gi_probe_bias1,spec_accum,diff_accum);
  987. 946:
  988. 947:    if (gi_probe2_enabled) {
  989. 948:
  990. 949:        gi_probe_compute(gi_probe2,gi_probe_xform2,gi_probe_bounds2,gi_probe_cell_size2,pos,ambient,environment,gi_probe_blend_ambient2,gi_probe_multiplier2,normal_mat,ref_vec,roughness,gi_probe_bias2,spec_accum,diff_accum);
  991. 950:    }
  992. 951:
  993. 952:    if (diff_accum.a>0.0) {
  994. 953:        diff_accum.rgb/=diff_accum.a;
  995. 954:    }
  996. 955:
  997. 956:    if (spec_accum.a>0.0) {
  998. 957:        spec_accum.rgb/=spec_accum.a;
  999. 958:    }
  1000. 959:
  1001. 960:    out_specular+=spec_accum.rgb;
  1002. 961:    out_ambient+=diff_accum.rgb;
  1003. 962:
  1004. 963: }
  1005. 964:
  1006. 965: #endif
  1007. 966:
  1008. 967:
  1009. 968:
  1010. 969: void main() {
  1011. 970:
  1012. 971: #ifdef RENDER_DEPTH_DUAL_PARABOLOID
  1013. 972:
  1014. 973:    if (dp_clip>0.0)
  1015. 974:        discard;
  1016. 975: #endif
  1017. 976:
  1018. 977:    //lay out everything, whathever is unused is optimized away anyway
  1019. 978:    highp vec3 vertex = vertex_interp;
  1020. 979:    vec3 albedo = vec3(0.8,0.8,0.8);
  1021. 980:    float metallic = 0.0;
  1022. 981:    float specular = 0.5;
  1023. 982:    vec3 emission = vec3(0.0,0.0,0.0);
  1024. 983:    float roughness = 1.0;
  1025. 984:    float rim = 0.0;
  1026. 985:    float rim_tint = 0.0;
  1027. 986:    float clearcoat=0.0;
  1028. 987:    float clearcoat_gloss=0.0;
  1029. 988:    float anisotropy = 1.0;
  1030. 989:    vec2 anisotropy_flow = vec2(1.0,0.0);
  1031. 990:
  1032. 991: #if defined(ENABLE_AO)
  1033. 992:    float ao=1.0;
  1034. 993: #endif
  1035. 994:
  1036. 995:    float alpha = 1.0;
  1037. 996:
  1038. 997: #ifdef METERIAL_DOUBLESIDED
  1039. 998:    float side=float(gl_FrontFacing)*2.0-1.0;
  1040. 999: #else
  1041. 1000:   float side=1.0;
  1042. 1001: #endif
  1043. 1002:
  1044. 1003:
  1045. 1004: #if defined(ENABLE_TANGENT_INTERP) || defined(ENABLE_NORMALMAP) || defined(LIGHT_USE_ANISOTROPY)
  1046. 1005:   vec3 binormal = normalize(binormal_interp)*side;
  1047. 1006:   vec3 tangent = normalize(tangent_interp)*side;
  1048. 1007: #else
  1049. 1008:   vec3 binormal = vec3(0.0);
  1050. 1009:   vec3 tangent = vec3(0.0);
  1051. 1010: #endif
  1052. 1011:   vec3 normal = normalize(normal_interp)*side;
  1053. 1012:
  1054. 1013: #if defined(ENABLE_UV_INTERP)
  1055. 1014:   vec2 uv = uv_interp;
  1056. 1015: #endif
  1057. 1016:
  1058. 1017: #if defined(ENABLE_UV2_INTERP)
  1059. 1018:   vec2 uv2 = uv2_interp;
  1060. 1019: #endif
  1061. 1020:
  1062. 1021: #if defined(ENABLE_COLOR_INTERP)
  1063. 1022:   vec4 color = color_interp;
  1064. 1023: #endif
  1065. 1024:
  1066. 1025: #if defined(ENABLE_NORMALMAP)
  1067. 1026:
  1068. 1027:   vec3 normalmap = vec3(0.0);
  1069. 1028: #endif
  1070. 1029:
  1071. 1030:   float normaldepth=1.0;
  1072. 1031:
  1073. 1032: #if defined(SCREEN_UV_USED)
  1074. 1033:   vec2 screen_uv = gl_FragCoord.xy*screen_pixel_size;
  1075. 1034: #endif
  1076. 1035:
  1077. 1036: #if defined(ENABLE_DISCARD)
  1078. 1037:   bool discard_=false;
  1079. 1038: #endif
  1080. 1039:
  1081. 1040: #if defined (ENABLE_SSS)
  1082. 1041:   float sss_strength=0.0;
  1083. 1042: #endif
  1084. 1043:
  1085. 1044: {
  1086. 1045:
  1087. 1046:
  1088. 1047:
  1089. 1048: }
  1090. 1049:
  1091. 1050:
  1092. 1051:
  1093. 1052: #if defined(ENABLE_NORMALMAP)
  1094. 1053:
  1095. 1054:   normalmap.xy=normalmap.xy*2.0-1.0;
  1096. 1055:   normalmap.z=sqrt(1.0-dot(normalmap.xy,normalmap.xy)); //always ignore Z, as it can be RG packed, Z may be pos/neg, etc.
  1097. 1056:
  1098. 1057:   normal = normalize( mix(normal_interp,tangent * normalmap.x + binormal * normalmap.y + normal * normalmap.z,normaldepth) ) * side;
  1099. 1058:
  1100. 1059: #endif
  1101. 1060:
  1102. 1061: #if defined(LIGHT_USE_ANISOTROPY)
  1103. 1062:
  1104. 1063:   if (anisotropy>0.01) {
  1105. 1064:       //rotation matrix
  1106. 1065:       mat3 rot = mat3( tangent, binormal, normal );
  1107. 1066:       //make local to space
  1108. 1067:       tangent = normalize(rot * vec3(anisotropy_flow.x,anisotropy_flow.y,0.0));
  1109. 1068:       binormal = normalize(rot * vec3(-anisotropy_flow.y,anisotropy_flow.x,0.0));
  1110. 1069:   }
  1111. 1070:
  1112. 1071: #endif
  1113. 1072:
  1114. 1073: #if defined(ENABLE_DISCARD)
  1115. 1074:   if (discard_) {
  1116. 1075:   //easy to eliminate dead code
  1117. 1076:       discard;
  1118. 1077:   }
  1119. 1078: #endif
  1120. 1079:
  1121. 1080: #ifdef ENABLE_CLIP_ALPHA
  1122. 1081:   if (albedo.a<0.99) {
  1123. 1082:       //used for doublepass and shadowmapping
  1124. 1083:       discard;
  1125. 1084:   }
  1126. 1085: #endif
  1127. 1086:
  1128. 1087: /////////////////////// LIGHTING //////////////////////////////
  1129. 1088:
  1130. 1089:   //apply energy conservation
  1131. 1090:
  1132. 1091:   vec3 specular_light = vec3(0.0,0.0,0.0);
  1133. 1092:   vec3 ambient_light;
  1134. 1093:   vec3 diffuse_light = vec3(0.0,0.0,0.0);
  1135. 1094:
  1136. 1095:   vec3 eye_vec = -normalize( vertex_interp );
  1137. 1096:
  1138. 1097:
  1139. 1098:
  1140. 1099: #ifdef USE_RADIANCE_MAP
  1141. 1100:
  1142. 1101:   if (no_ambient_light) {
  1143. 1102:       ambient_light=vec3(0.0,0.0,0.0);
  1144. 1103:   } else {
  1145. 1104:       {
  1146. 1105:
  1147. 1106:           { //read radiance from dual paraboloid
  1148. 1107:
  1149. 1108:               vec3 ref_vec = reflect(-eye_vec,normal); //2.0 * ndotv * normal - view; // reflect(v, n);
  1150. 1109:               ref_vec=normalize((radiance_inverse_xform * vec4(ref_vec,0.0)).xyz);
  1151. 1110:               vec3 radiance = textureDualParaboloid(radiance_map,ref_vec,roughness) * bg_energy;
  1152. 1111:               specular_light = radiance;
  1153. 1112:
  1154. 1113:           }
  1155. 1114:           //no longer a cubemap
  1156. 1115:           //vec3 radiance = textureLod(radiance_cube, r, lod).xyz * ( brdf.x + brdf.y);
  1157. 1116:
  1158. 1117:       }
  1159. 1118:
  1160. 1119:       {
  1161. 1120:
  1162. 1121:           vec3 ambient_dir=normalize((radiance_inverse_xform * vec4(normal,0.0)).xyz);
  1163. 1122:           vec3 env_ambient=textureDualParaboloid(radiance_map,ambient_dir,1.0) * bg_energy;
  1164. 1123:
  1165. 1124:           ambient_light=mix(ambient_light_color.rgb,env_ambient,radiance_ambient_contribution);
  1166. 1125:           //ambient_light=vec3(0.0,0.0,0.0);
  1167. 1126:       }
  1168. 1127:   }
  1169. 1128:
  1170. 1129: #else
  1171. 1130:
  1172. 1131:   if (no_ambient_light){
  1173. 1132:       ambient_light=vec3(0.0,0.0,0.0);
  1174. 1133:   } else {
  1175. 1134:       ambient_light=ambient_light_color.rgb;
  1176. 1135:   }
  1177. 1136: #endif
  1178. 1137:
  1179. 1138:   ambient_light*=ambient_energy;
  1180. 1139:
  1181. 1140:   float specular_blob_intensity=1.0;
  1182. 1141: #if defined(SPECULAR_TOON)
  1183. 1142:   specular_blob_intensity*=specular * 2.0;
  1184. 1143: #endif
  1185. 1144:
  1186. 1145: #ifdef USE_LIGHT_DIRECTIONAL
  1187. 1146:
  1188. 1147:   vec3 light_attenuation=vec3(1.0);
  1189. 1148:
  1190. 1149: #ifdef LIGHT_DIRECTIONAL_SHADOW
  1191. 1150:
  1192. 1151:   if (gl_FragCoord.w > shadow_split_offsets.w) {
  1193. 1152:
  1194. 1153:   vec3 pssm_coord;
  1195. 1154:
  1196. 1155: #ifdef LIGHT_USE_PSSM_BLEND
  1197. 1156:   float pssm_blend;
  1198. 1157:   vec3 pssm_coord2;
  1199. 1158:   bool use_blend=true;
  1200. 1159:   vec3 light_pssm_split_inv = 1.0/shadow_split_offsets.xyz;
  1201. 1160:   float w_inv = 1.0/gl_FragCoord.w;
  1202. 1161: #endif
  1203. 1162:
  1204. 1163:
  1205. 1164: #ifdef LIGHT_USE_PSSM4
  1206. 1165:
  1207. 1166:
  1208. 1167:   if (gl_FragCoord.w > shadow_split_offsets.y) {
  1209. 1168:
  1210. 1169:       if (gl_FragCoord.w > shadow_split_offsets.x) {
  1211. 1170:
  1212. 1171:           highp vec4 splane=(shadow_matrix1 * vec4(vertex,1.0));
  1213. 1172:           pssm_coord=splane.xyz/splane.w;
  1214. 1173:
  1215. 1174:
  1216. 1175: #if defined(LIGHT_USE_PSSM_BLEND)
  1217. 1176:
  1218. 1177:           splane=(shadow_matrix2 * vec4(vertex,1.0));
  1219. 1178:           pssm_coord2=splane.xyz/splane.w;
  1220. 1179:           pssm_blend=smoothstep(0.0,light_pssm_split_inv.x,w_inv);
  1221. 1180: #endif
  1222. 1181:
  1223. 1182:       } else {
  1224. 1183:
  1225. 1184:           highp vec4 splane=(shadow_matrix2 * vec4(vertex,1.0));
  1226. 1185:           pssm_coord=splane.xyz/splane.w;
  1227. 1186:
  1228. 1187: #if defined(LIGHT_USE_PSSM_BLEND)
  1229. 1188:           splane=(shadow_matrix3 * vec4(vertex,1.0));
  1230. 1189:           pssm_coord2=splane.xyz/splane.w;
  1231. 1190:           pssm_blend=smoothstep(light_pssm_split_inv.x,light_pssm_split_inv.y,w_inv);
  1232. 1191: #endif
  1233. 1192:
  1234. 1193:       }
  1235. 1194:   } else {
  1236. 1195:
  1237. 1196:
  1238. 1197:       if (gl_FragCoord.w > shadow_split_offsets.z) {
  1239. 1198:
  1240. 1199:           highp vec4 splane=(shadow_matrix3 * vec4(vertex,1.0));
  1241. 1200:           pssm_coord=splane.xyz/splane.w;
  1242. 1201:
  1243. 1202: #if defined(LIGHT_USE_PSSM_BLEND)
  1244. 1203:           splane=(shadow_matrix4 * vec4(vertex,1.0));
  1245. 1204:           pssm_coord2=splane.xyz/splane.w;
  1246. 1205:           pssm_blend=smoothstep(light_pssm_split_inv.y,light_pssm_split_inv.z,w_inv);
  1247. 1206: #endif
  1248. 1207:
  1249. 1208:       } else {
  1250. 1209:           highp vec4 splane=(shadow_matrix4 * vec4(vertex,1.0));
  1251. 1210:           pssm_coord=splane.xyz/splane.w;
  1252. 1211:
  1253. 1212: #if defined(LIGHT_USE_PSSM_BLEND)
  1254. 1213:           use_blend=false;
  1255. 1214:
  1256. 1215: #endif
  1257. 1216:
  1258. 1217:       }
  1259. 1218:   }
  1260. 1219:
  1261. 1220:
  1262. 1221:
  1263. 1222: #endif //LIGHT_USE_PSSM4
  1264. 1223:
  1265. 1224: #ifdef LIGHT_USE_PSSM2
  1266. 1225:
  1267. 1226:   if (gl_FragCoord.w > shadow_split_offsets.x) {
  1268. 1227:
  1269. 1228:       highp vec4 splane=(shadow_matrix1 * vec4(vertex,1.0));
  1270. 1229:       pssm_coord=splane.xyz/splane.w;
  1271. 1230:
  1272. 1231:
  1273. 1232: #if defined(LIGHT_USE_PSSM_BLEND)
  1274. 1233:
  1275. 1234:       splane=(shadow_matrix2 * vec4(vertex,1.0));
  1276. 1235:       pssm_coord2=splane.xyz/splane.w;
  1277. 1236:       pssm_blend=smoothstep(0.0,light_pssm_split_inv.x,w_inv);
  1278. 1237: #endif
  1279. 1238:
  1280. 1239:   } else {
  1281. 1240:       highp vec4 splane=(shadow_matrix2 * vec4(vertex,1.0));
  1282. 1241:       pssm_coord=splane.xyz/splane.w;
  1283. 1242: #if defined(LIGHT_USE_PSSM_BLEND)
  1284. 1243:       use_blend=false;
  1285. 1244:
  1286. 1245: #endif
  1287. 1246:
  1288. 1247:   }
  1289. 1248:
  1290. 1249: #endif //LIGHT_USE_PSSM2
  1291. 1250:
  1292. 1251: #if !defined(LIGHT_USE_PSSM4) && !defined(LIGHT_USE_PSSM2)
  1293. 1252:   { //regular orthogonal
  1294. 1253:       highp vec4 splane=(shadow_matrix1 * vec4(vertex,1.0));
  1295. 1254:       pssm_coord=splane.xyz/splane.w;
  1296. 1255:   }
  1297. 1256: #endif
  1298. 1257:
  1299. 1258:
  1300. 1259:   //one one sample
  1301. 1260:
  1302. 1261:   float shadow = sample_shadow(directional_shadow,directional_shadow_pixel_size,pssm_coord.xy,pssm_coord.z,light_clamp);
  1303. 1262:
  1304. 1263: #if defined(LIGHT_USE_PSSM_BLEND)
  1305. 1264:
  1306. 1265:   if (use_blend) {
  1307. 1266:       shadow=mix(shadow, sample_shadow(directional_shadow,directional_shadow_pixel_size,pssm_coord2.xy,pssm_coord2.z,light_clamp),pssm_blend);
  1308. 1267:   }
  1309. 1268: #endif
  1310. 1269:
  1311. 1270:   if (shadow>0.01 && shadow_color_contact.a>0.0) {
  1312. 1271:
  1313. 1272:       float contact_shadow = contact_shadow_compute(vertex,-light_direction_attenuation.xyz,shadow_color_contact.a);
  1314. 1273:       shadow=min(shadow,contact_shadow);
  1315. 1274:
  1316. 1275:   }
  1317. 1276:
  1318. 1277:   light_attenuation=mix(shadow_color_contact.rgb,vec3(1.0),shadow);
  1319. 1278:
  1320. 1279:
  1321. 1280:   }
  1322. 1281:
  1323. 1282: #endif //LIGHT_DIRECTIONAL_SHADOW
  1324. 1283:
  1325. 1284:   light_compute(normal,-light_direction_attenuation.xyz,eye_vec,binormal,tangent,light_color_energy.rgb*light_attenuation,albedo,light_params.z*specular_blob_intensity,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,diffuse_light,specular_light);
  1326. 1285:
  1327. 1286:
  1328. 1287: #endif //#USE_LIGHT_DIRECTIONAL
  1329. 1288:
  1330. 1289: #ifdef USE_GI_PROBES
  1331. 1290:   gi_probes_compute(vertex,normal,roughness,specular_light,ambient_light);
  1332. 1291:
  1333. 1292: #endif
  1334. 1293:
  1335. 1294:
  1336. 1295: #ifdef USE_FORWARD_LIGHTING
  1337. 1296:
  1338. 1297:   highp vec4 reflection_accum = vec4(0.0,0.0,0.0,0.0);
  1339. 1298:   highp vec4 ambient_accum = vec4(0.0,0.0,0.0,0.0);
  1340. 1299:
  1341. 1300:   for(int i=0;i<reflection_count;i++) {
  1342. 1301:       reflection_process(reflection_indices[i],vertex,normal,binormal,tangent,roughness,anisotropy,ambient_light,specular_light,reflection_accum,ambient_accum);
  1343. 1302:   }
  1344. 1303:
  1345. 1304:   if (reflection_accum.a>0.0) {
  1346. 1305:       specular_light+=reflection_accum.rgb/reflection_accum.a;
  1347. 1306:   }
  1348. 1307:   if (ambient_accum.a>0.0) {
  1349. 1308:       ambient_light+=ambient_accum.rgb/ambient_accum.a;
  1350. 1309:   }
  1351. 1310:
  1352. 1311:   for(int i=0;i<omni_light_count;i++) {
  1353. 1312:       light_process_omni(omni_light_indices[i],vertex,eye_vec,normal,binormal,tangent,albedo,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,specular_blob_intensity,diffuse_light,specular_light);
  1354. 1313:   }
  1355. 1314:
  1356. 1315:   for(int i=0;i<spot_light_count;i++) {
  1357. 1316:       light_process_spot(spot_light_indices[i],vertex,eye_vec,normal,binormal,tangent,albedo,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,specular_blob_intensity,diffuse_light,specular_light);
  1358. 1317:   }
  1359. 1318:
  1360. 1319:
  1361. 1320:
  1362. 1321: #endif
  1363. 1322:
  1364. 1323:
  1365. 1324:
  1366. 1325:
  1367. 1326:
  1368. 1327:
  1369. 1328: #ifdef RENDER_DEPTH
  1370. 1329: //nothing happens, so a tree-ssa optimizer will result in no fragment shader :)
  1371. 1330: #else
  1372. 1331:
  1373. 1332:   specular_light*=reflection_multiplier;
  1374. 1333:   ambient_light*=albedo; //ambient must be multiplied by albedo at the end
  1375. 1334:
  1376. 1335: #if defined(ENABLE_AO)
  1377. 1336:   ambient_light*=ao;
  1378. 1337: #endif
  1379. 1338:
  1380. 1339:
  1381. 1340:
  1382. 1341:
  1383. 1342:
  1384. 1343:
  1385. 1344:   //energu conservation
  1386. 1345:   diffuse_light=mix(diffuse_light,vec3(0.0),metallic);
  1387. 1346:   ambient_light=mix(ambient_light,vec3(0.0),metallic);
  1388. 1347:   {
  1389. 1348:
  1390. 1349: #if defined(DIFFUSE_TOON)
  1391. 1350:       //simplify for toon, as
  1392. 1351:       specular_light *= specular * metallic * albedo * 2.0;
  1393. 1352: #else
  1394. 1353:       //brdf approximation (Lazarov 2013)
  1395. 1354:       float ndotv = clamp(dot(normal,eye_vec),0.0,1.0);
  1396. 1355:       vec3 dielectric = vec3(0.034) * specular * 2.0;
  1397. 1356:       //energy conservation
  1398. 1357:       vec3 f0 = mix(dielectric, albedo, metallic);
  1399. 1358:       const vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022);
  1400. 1359:       const vec4 c1 = vec4( 1.0, 0.0425, 1.04, -0.04);
  1401. 1360:       vec4 r = roughness * c0 + c1;
  1402. 1361:       float a004 = min( r.x * r.x, exp2( -9.28 * ndotv ) ) * r.x + r.y;
  1403. 1362:       vec2 brdf = vec2( -1.04, 1.04 ) * a004 + r.zw;
  1404. 1363:
  1405. 1364:       specular_light *= min(1.0,50.0 * f0.g) * brdf.y + brdf.x * f0;
  1406. 1365: #endif
  1407. 1366:
  1408. 1367:   }
  1409. 1368:
  1410. 1369:   if (fog_color_enabled.a > 0.5) {
  1411. 1370:
  1412. 1371:       float fog_amount=0;
  1413. 1372:
  1414. 1373:
  1415. 1374:
  1416. 1375: #ifdef USE_LIGHT_DIRECTIONAL
  1417. 1376:
  1418. 1377:       vec3 fog_color = mix( fog_color_enabled.rgb, fog_sun_color_amount.rgb,fog_sun_color_amount.a * pow(max( dot(normalize(vertex),-light_direction_attenuation.xyz), 0.0),8.0) );
  1419. 1378: #else
  1420. 1379:
  1421. 1380:       vec3 fog_color = fog_color_enabled.rgb;
  1422. 1381: #endif
  1423. 1382:
  1424. 1383:       //apply fog
  1425. 1384:
  1426. 1385:       if (fog_depth_enabled) {
  1427. 1386:
  1428. 1387:           float fog_z = smoothstep(fog_depth_begin,z_far,-vertex.z);
  1429. 1388:
  1430. 1389:           fog_amount = pow(fog_z,fog_depth_curve);
  1431. 1390:           if (fog_transmit_enabled) {
  1432. 1391:               vec3 total_light = emission + ambient_light + specular_light + diffuse_light;
  1433. 1392:               float transmit = pow(fog_z,fog_transmit_curve);
  1434. 1393:               fog_color = mix(max(total_light,fog_color),fog_color,transmit);
  1435. 1394:           }
  1436. 1395:       }
  1437. 1396:
  1438. 1397:       if (fog_height_enabled) {
  1439. 1398:           float y = (camera_matrix * vec4(vertex,1.0)).y;
  1440. 1399:           fog_amount = max(fog_amount,pow(1.0-smoothstep(fog_height_min,fog_height_max,y),fog_height_curve));
  1441. 1400:       }
  1442. 1401:
  1443. 1402:       float rev_amount = 1.0 - fog_amount;
  1444. 1403:
  1445. 1404:
  1446. 1405:       emission = emission * rev_amount + fog_color * fog_amount;
  1447. 1406:       ambient_light*=rev_amount;
  1448. 1407:       specular_light*rev_amount;
  1449. 1408:       diffuse_light*=rev_amount;
  1450. 1409:
  1451. 1410:   }
  1452. 1411:
  1453. 1412: #ifdef USE_MULTIPLE_RENDER_TARGETS
  1454. 1413:
  1455. 1414: #if defined(ENABLE_AO)
  1456. 1415:
  1457. 1416:   float ambient_scale=0.0; // AO is supplied by material
  1458. 1417: #else
  1459. 1418:   //approximate ambient scale for SSAO, since we will lack full ambient
  1460. 1419:   float max_emission=max(emission.r,max(emission.g,emission.b));
  1461. 1420:   float max_ambient=max(ambient_light.r,max(ambient_light.g,ambient_light.b));
  1462. 1421:   float max_diffuse=max(diffuse_light.r,max(diffuse_light.g,diffuse_light.b));
  1463. 1422:   float total_ambient = max_ambient+max_diffuse+max_emission;
  1464. 1423:   float ambient_scale = (total_ambient>0.0) ? (max_ambient+ambient_occlusion_affect_light*max_diffuse)/total_ambient : 0.0;
  1465. 1424: #endif //ENABLE_AO
  1466. 1425:
  1467. 1426:   diffuse_buffer=vec4(emission+diffuse_light+ambient_light,ambient_scale);
  1468. 1427:   specular_buffer=vec4(specular_light,metallic);
  1469. 1428:
  1470. 1429:
  1471. 1430:   normal_mr_buffer=vec4(normalize(normal)*0.5+0.5,roughness);
  1472. 1431:
  1473. 1432: #if defined (ENABLE_SSS)
  1474. 1433:   sss_buffer = sss_strength;
  1475. 1434: #endif
  1476. 1435:
  1477. 1436: #else //USE_MULTIPLE_RENDER_TARGETS
  1478. 1437:
  1479. 1438:
  1480. 1439: #ifdef SHADELESS
  1481. 1440:   frag_color=vec4(albedo,alpha);
  1482. 1441: #else
  1483. 1442:   frag_color=vec4(emission+ambient_light+diffuse_light+specular_light,alpha);
  1484. 1443: #endif //SHADELESS
  1485. 1444:
  1486. 1445:
  1487. 1446: #endif //USE_MULTIPLE_RENDER_TARGETS
  1488. 1447:
  1489. 1448:
  1490. 1449:
  1491. 1450: #endif //RENDER_DEPTH
  1492. 1451:
  1493. 1452:
  1494. 1453: }
  1495. 1454:
  1496. 1455:
  1497. 1456:
  1498. ERROR: _display_error_with_code: SceneShaderGLES3: Fragment Program Compilation Failed:
  1499. ERROR: 0:1371: Incompatible types in initialization (and no available implicit conversion)
  1500. ERROR: 0:1389: Use of undeclared identifier 'fog_amount'
  1501. ERROR: 0:1399: Use of undeclared identifier 'fog_amount'
  1502. ERROR: 0:1399: Use of undeclared identifier 'fog_amount'
  1503. ERROR: 0:1402: Use of undeclared identifier 'fog_amount'
  1504. ERROR: 0:1405: Use of undeclared identifier 'rev_amount'
  1505. ERROR: 0:1405: Use of undeclared identifier 'fog_amount'
  1506. ERROR: 0:1406: Use of undeclared identifier 'rev_amount'
  1507. ERROR: 0:1407: Use of undeclared identifier 'rev_amount'
  1508. ERROR: 0:1408: Use of undeclared identifier 'rev_amount'
  1509.  
  1510.    At: drivers/gles3/shader_gles3.cpp:167.
  1511. ERROR: get_current_version: SceneShaderGLES3: Fragment Program Compilation Failed:
  1512. ERROR: 0:1371: Incompatible types in initialization (and no available implicit conversion)
  1513. ERROR: 0:1389: Use of undeclared identifier 'fog_amount'
  1514. ERROR: 0:1399: Use of undeclared identifier 'fog_amount'
  1515. ERROR: 0:1399: Use of undeclared identifier 'fog_amount'
  1516. ERROR: 0:1402: Use of undeclared identifier 'fog_amount'
  1517. ERROR: 0:1405: Use of undeclared identifier 'rev_amount'
  1518. ERROR: 0:1405: Use of undeclared identifier 'fog_amount'
  1519. ERROR: 0:1406: Use of undeclared identifier 'rev_amount'
  1520. ERROR: 0:1407: Use of undeclared identifier 'rev_amount'
  1521. ERROR: 0:1408: Use of undeclared identifier 'rev_amount'
  1522.  
  1523.    At: drivers/gles3/shader_gles3.cpp:459.
  1524. ERROR: get_current_version: Method/Function Failed, returning: __null
  1525.    At: drivers/gles3/shader_gles3.cpp:467.
  1526. ERROR: bind: Condition ' !version ' is true. returned: false
  1527.    At: drivers/gles3/shader_gles3.cpp:122.
  1528. ERROR: _get_uniform: Condition ' !version ' is true. returned: -1
  1529.    At: drivers/gles3/shader_gles3.h:376.
  1530. ERROR: _get_uniform: Condition ' !version ' is true. returned: -1
  1531.    At: drivers/gles3/shader_gles3.h:376.
  1532. ERROR: _get_uniform: Condition ' !version ' is true. returned: -1
  1533.    At: drivers/gles3/shader_gles3.h:376.
  1534. ERROR: _get_uniform: Condition ' !version ' is true. returned: -1
  1535.    At: drivers/gles3/shader_gles3.h:376.
  1536. ERROR: _get_uniform: Condition ' !version ' is true. returned: -1
  1537.    At: drivers/gles3/shader_gles3.h:376.
  1538. ERROR: operator[]: FATAL: Index p_index out of size (size()).
  1539.    At: core/vector.h:137.
  1540. (lldb)
  1541.  
  1542.  
  1543. --> Crash at vector.h/137 CRASH_BAD_INDEX(p_index, size());
  1544. Coming from RasterizerSceneGLES3.cpp/3415 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, storage->frame.current_rt->effects.mip_maps[0].sizes[0].fbo);
RAW Paste Data
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top