Advertisement
Guest User

base.shader_source

a guest
Aug 27th, 2013
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 104.12 KB | None | 0 0
  1. // in this context include refers to another shader file
  2. includes = [ "core/rendering/common.shader_source", "core/rendering/base_dx11.shader_source", "core/rendering/base_mobile.shader_source", "core/rendering/base_voxelizer.shader_source" ]
  3.  
  4. render_states = {
  5. outline = {
  6. inherits = "opacity"
  7. states = {
  8. //fill_mode = "fill_wireframe"
  9. z_write_enable = "true"
  10. z_enable = "true"
  11. cull_mode = "cull_ccw"
  12.  
  13. blend_enable = "true"
  14. blend_op = "blend_op_add"
  15. //dest_blend = "blend_one"
  16. //src_blend = "blend_one"
  17. }
  18. }
  19.  
  20.  
  21.  
  22. wireframe = {
  23. inherits = "opacity"
  24. states = {
  25. fill_mode = "fill_wireframe"
  26. z_write_enable = "true"
  27. z_func = "less"
  28. defined_D3D11 = {
  29. depth_bias = "-1"
  30. depth_bias_clamp = "-0.00015"
  31. slope_scale_depth_bias = "-2.0"
  32. }
  33. }
  34. }
  35.  
  36. ambient_no_depth_write = {
  37. inherits = "ambient"
  38. states = {
  39. z_write_enable = "false"
  40. }
  41. }
  42.  
  43. depth_only = {
  44. inherits = "default"
  45. states = {
  46. write_mask0 = "0x0"
  47. write_mask1 = "0x0"
  48. write_mask2 = "0x0"
  49. write_mask3 = "0x0"
  50. }
  51. }
  52.  
  53. shadow_caster = {
  54. inherits = "depth_only"
  55. states = {
  56. defined_D3D11 = {
  57. depth_bias = "0xff"
  58. slope_scale_depth_bias = "1.0"
  59. }
  60. defined_GCM = {
  61. offset_units = "5.0"
  62. offset_factor = "1.0"
  63. }
  64. defined_GL2 = {
  65. offset_units = "255.0"
  66. offset_factor = "2.0"
  67. depth_bias_enable = "true"
  68. }
  69. defined_X360 = {
  70. depth_bias = "0.0002"
  71. slope_scale_depth_bias = "2.5"
  72. }
  73. }
  74. }
  75.  
  76. gbuffer_double_sided = {
  77. inherits = "default"
  78. states = {
  79. cull_mode = "cull_none"
  80. }
  81. }
  82.  
  83. gbuffer_ambient_zequal_add = {
  84. inherits = "default"
  85. states = {
  86. z_func = "equal"
  87. blend_enable = "true"
  88. blend_op = "blend_op_add"
  89. dest_blend = "blend_one"
  90. src_blend = "blend_one"
  91. }
  92. }
  93.  
  94. water_mask = {
  95. inherits = "ambient"
  96. states = {
  97. defined_ALWAYS = {
  98. z_enable="false"
  99. }
  100. ndefined_ALWAYS = {
  101. z_write_enable="false"
  102. }
  103. write_mask0 = "alpha"
  104. cull_mode = "cull_none"
  105. }
  106. }
  107.  
  108. fog_plane = {
  109. inherits = "opacity"
  110. states = {
  111. defined_INVERTED = {
  112. z_func = "greater"
  113. }
  114. }
  115. }
  116.  
  117. pvs_bake = {
  118. inherits = "ambient"
  119. states = {
  120. defined_DOUBLE_SIDED = {
  121. cull_mode = "cull_none"
  122. }
  123. ndefined_DOUBLE_SIDED = {
  124. cull_mode = "cull_ccw"
  125. }
  126. }
  127. }
  128.  
  129. pvs_bake_no_depth_write = {
  130. inherits = "pvs_bake"
  131. states = {
  132. z_write_enable = "false"
  133. }
  134. }
  135.  
  136. ao_bake = {
  137. inherits = "ambient"
  138. states = {
  139. cull_mode = "cull_none"
  140. }
  141. }
  142. }
  143.  
  144. hlsl_shaders = {
  145. outline = {
  146. includes = [ "common", "gbuffer_access" ]
  147.  
  148. code="""
  149. #if defined(VEGETATION_BENDING) && !defined(OES2)
  150. struct VS_INPUT {
  151. float4 position : POSITION;
  152. float3 normal : NORMAL0;
  153. };
  154.  
  155. struct PS_INPUT {
  156. float4 position : SV_POSITION;
  157. };
  158.  
  159. CBUFFER_START(c0)
  160. float4x4 world_view_proj;
  161. float line_thickness; // exports={ name="Line Thickness" type="scalar" value=0.000000 min=0.000000 max=10 step=0.0001 sort_tag="Thickness of the ouline" }
  162. float line_opacity; // exports={ name="Line Opacity" type="scalar" value=0.000000 min=0.000000 max=1 step=0.0001 sort_tag="Opacity of the outline" }
  163. float3 line_color; // exports={ name="Line Color" type="vector3" value=[1.0 0.0 0.0] min=[0 0 0] max=[1 1 1] step=[0.001 0.001 0.001] }
  164. CBUFFER_END
  165.  
  166. PS_INPUT vs_main(VS_INPUT input) {
  167. PS_INPUT o;
  168. float4 original = mul(input.position, world_view_proj);
  169. float4 normal = mul(input.normal, world_view_proj);
  170.  
  171.  
  172. o.position = original + mul(normal, line_thickness);
  173. //o.position.z = original.z - line_opacity;
  174. return o;
  175. }
  176.  
  177. float4 ps_main(PS_INPUT input) : SV_TARGET0
  178. {
  179. return float4(line_color, line_opacity);
  180. }
  181. #endif
  182. """
  183. }
  184.  
  185.  
  186. vegetation_bending = {
  187. code="""
  188. #if defined(VEGETATION_BENDING) && !defined(OES2)
  189. // Vegetation vertex animation (based on GPUGems 3 chapter by Tiago Sousa / Crytek)
  190. CBUFFER_START(c_vegetation_bending)
  191. float speed; // exports = { name="Vegetation Speed" type="scalar" value=0.5 min=0.0 max=10 step=0.001 }
  192. float2 branch_settings; // exports = { name="Branch Bending Amplitude / Frequency" type="vector2" min=[0 0] max=[10 2] step=[0.01 0.001] value=[0.3 0.1] }
  193. float2 detail_settings; // exports = { name="Detail Bending Amplitude / Frequency" type="vector2" min=[0 0] max=[1 5] step=[0.001 0.001] value=[0.05 0.5] }
  194. CBUFFER_END
  195.  
  196. // sine waves approximation by smoothing a number of triangle waves using bicubic interpolation.
  197. float4 smooth_curve( float4 x ) {
  198. return x * x * (3.0 - 2.0 * x);
  199. }
  200.  
  201. float4 triangle_wave( float4 x ) {
  202. return abs(frac(x + 0.5) * 2.0 - 1.0);
  203. }
  204.  
  205. float4 smooth_triangle_wave( float4 x ) {
  206. return smooth_curve(triangle_wave(x));
  207. }
  208.  
  209. static const float4 freq = float4(1.975, 0.793, 0.375, 0.193);
  210. float4 vegetation_bending(float3 opos, float4 wpos, float3 vnormal, float4 vdata, float4 vpos) {
  211. float detail_amp = detail_settings.x;
  212. float detail_freq = detail_settings.y;
  213.  
  214. float branch_amp = branch_settings.x;
  215. float branch_freq = branch_settings.y;
  216.  
  217. float edge_attenuation = vdata.x * vdata.z;
  218. float branch_phase = vdata.y * 2 - 1;
  219. float branch_attenuation = vdata.z;
  220.  
  221. float obj_phase = dot(opos, 1);
  222. //float detail_phase = branch_phase;
  223. //branch_phase += obj_phase;
  224. float detail_phase = dot(vpos.xyz, branch_phase);
  225.  
  226. float2 waves_in = time + float2(detail_phase, branch_phase);
  227.  
  228. float4 waves = (frac(waves_in.xyxy * freq * float2(detail_freq, branch_freq).xyxy * speed) * 2.0 - 1.0);
  229. waves = smooth_triangle_wave(waves);
  230.  
  231. float2 waves_sum = (waves.xz + waves.yw);
  232. return float4(wpos.xyz + waves_sum.xxy * float3(edge_attenuation * detail_amp * vnormal.xy, branch_attenuation * branch_amp), wpos.w);
  233. }
  234. #endif
  235. """
  236. }
  237.  
  238. uv_management = {
  239. code="""
  240. #if defined(DIFFUSE_MAP) || defined(NORMAL_MAP) || defined(MATERIAL_MAP) || defined(SELF_ILLUMINATION_MAP) || defined(AMBIENT_OCCLUSION_MAP) || defined(SUBSURFACE_SCATTERING_MAP)
  241. #define HAS_UV
  242.  
  243. #if defined(DIFFUSE_UV_ANIM) || defined(NORMAL_UV_ANIM) || defined(SELF_ILLUMINATION_UV_ANIM) || defined(MATERIAL_UV_ANIM)
  244. #define UV_ANIM
  245. #endif
  246. #if defined(DIFFUSE_UV_OFFSET) || defined(NORMAL_UV_OFFSET) || defined(SELF_ILLUMINATION_UV_OFFSET) || defined(MATERIAL_UV_OFFSET)
  247. #define UV_OFFSET
  248. #endif
  249. #if defined(DIFFUSE_UV_ROTATION_ANIM) || defined(SELF_ILLUMINATION_UV_ROTATION_ANIM) || defined(MATERIAL_UV_ROTATION)
  250. #define UV_ROTATION_ANIM
  251. #endif
  252.  
  253. #if defined(UV_ANIM) || defined(UV_OFFSET) || defined(UV_ROTATION_ANIM)
  254. CBUFFER_START(c_uv_manipulation)
  255. #ifdef UV_ANIM
  256. float2 uv_speed; // exports={ name="UV Speed" type="vector2" value=[0.1 0.1] min=[-10.0 -10.0] max=[10.0 10.0] step=[0.001 0.001] }
  257. #endif
  258. #ifdef UV_OFFSET
  259. float2 uv_offset; // exports={ name="UV Offset" type="vector2" value=[0.0 0.0] min=[0.0 0.0] max=[10.0 10.0] step=[0.001 0.001] }
  260. #endif
  261. #ifdef UV_ROTATION_ANIM
  262. float2 uv_rotation_pivot; // exports={ name="UV Rotation Pivot" type="vector2" value=[0.5 0.5] min=[-1.0 -1.0] max=[1.0 1.0] step=[0.001 0.001] }
  263. float2 uv_rotation_speed; // exports={ name="UV Rotation Speed" type="scalar" value=1.57 min=-6.28 max=6.28 step=0.001 }
  264. #endif
  265. CBUFFER_END
  266. #endif
  267.  
  268. float2 uv_pass_through_modifier(float2 uv) {
  269. return uv;
  270. }
  271. #if defined(UV_OFFSET)
  272. float2 uv_offset_modifier(float2 uv) {
  273. #if defined(GL2)
  274. return uv + float2(uv_offset.x, -uv_offset.y);
  275. #else
  276. return uv + uv_offset;
  277. #endif
  278. }
  279. #endif
  280. #if defined(UV_ANIM)
  281. float2 uv_anim_modifier(float2 uv) {
  282. #if defined(GL2)
  283. return uv + float2(uv_speed.x, -uv_speed.y) * time;
  284. #else
  285. return uv + uv_speed * time;
  286. #endif
  287. }
  288. #endif
  289. #if defined(UV_ROTATION_ANIM)
  290. float2 uv_rotation_anim_modifier(float2 uv) {
  291. float a = uv_rotation_speed * time;
  292. float c = cos(a);
  293. float s = sin(a);
  294. float2 center = uv - uv_rotation_pivot;
  295. float2 result = float2( (center.x * c + center.y * s) + uv_rotation_pivot.x,
  296. (center.y * c - center.x * s) + uv_rotation_pivot.y);
  297. #if defined(GL2)
  298. return float2(result.x, -result.y);
  299. #else
  300. return result;
  301. #endif
  302. }
  303. #endif
  304.  
  305. #if defined(DIFFUSE_UV_ANIM)
  306. #define diffuse_uv_modifier uv_anim_modifier
  307. #elif defined(DIFFUSE_UV_OFFSET)
  308. #define diffuse_uv_modifier uv_offset_modifier
  309. #elif defined(DIFFUSE_UV_ROTATION_ANIM)
  310. #define diffuse_uv_modifier uv_rotation_anim_modifier
  311. #else
  312. #define diffuse_uv_modifier uv_pass_through_modifier
  313. #endif
  314.  
  315. #if defined(NORMAL_UV_ANIM)
  316. #define normal_uv_modifier uv_anim_modifier
  317. #elif defined(NORMAL_UV_OFFSET)
  318. #define normal_uv_modifier uv_offset_modifier
  319. //#elif defined(NORMAL_UV_ROTATION_ANIM) -- supporting uv rotation for normal channel forces us to rotate the tangent space as well..
  320. // #define normal_uv_modifier uv_rotation_anim_modifier
  321. #else
  322. #define normal_uv_modifier uv_pass_through_modifier
  323. #endif
  324.  
  325. #if defined(SELF_ILLUMINATION_UV_ANIM)
  326. #define self_illumination_uv_modifier uv_anim_modifier
  327. #elif defined(SELF_ILLUMINATION_UV_OFFSET)
  328. #define self_illumination_uv_modifier uv_offset_modifier
  329. #elif defined(SELF_ILLUMINATION_UV_ROTATION_ANIM)
  330. #define self_illumination_uv_modifier uv_rotation_anim_modifier
  331. #else
  332. #define self_illumination_uv_modifier uv_pass_through_modifier
  333. #endif
  334.  
  335. #if defined(MATERIAL_UV_ANIM)
  336. #define material_uv_modifier uv_anim_modifier
  337. #elif defined(MATERIAL_UV_OFFSET)
  338. #define material_uv_modifier uv_offset_modifier
  339. #elif defined(MATERIAL_UV_ROTATION_ANIM)
  340. #define material_uv_modifier uv_rotation_anim_modifier
  341. #else
  342. #define material_uv_modifier uv_pass_through_modifier
  343. #endif
  344. #endif
  345. """
  346. }
  347.  
  348. gbuffer_base = {
  349. includes = [ "common", "gbuffer_access", "skinning", "vegetation_bending", "uv_management" ]
  350.  
  351. samplers = {
  352. defined_DIFFUSE_MAP = {
  353. diffuse_map = { sampler_states = "wrap_anisotropic_srgb" }
  354. }
  355. defined_NORMAL_MAP = {
  356. normal_map = { sampler_states = "wrap_anisotropic" }
  357. }
  358. defined_MATERIAL_MAP = {
  359. material_map = { sampler_states = "wrap_anisotropic_srgb" }
  360. }
  361. defined_SELF_ILLUMINATION_MAP = {
  362. self_illumination_map = { sampler_states = "wrap_anisotropic_srgb" }
  363. }
  364.  
  365. defined_MASKED_VC_BLEND = {
  366. blend_diffuse_map = { sampler_states = "wrap_anisotropic_srgb" }
  367. blend_material_map = { sampler_states = "wrap_anisotropic_srgb" }
  368. defined_NORMAL_MAP = {
  369. blend_normal_map = { sampler_states = "wrap_anisotropic" }
  370. }
  371. }
  372.  
  373. defined_DETAIL_DIFFUSE_MAP = {
  374. detail_diffuse_map = { sampler_states = "wrap_anisotropic" }
  375. }
  376. defined_DETAIL_MATERIAL_MAP = {
  377. detail_material_map = { sampler_states = "wrap_anisotropic" }
  378. }
  379. defined_DETAIL_NORMAL_MAP = {
  380. detail_normal_map = { sampler_states = "wrap_anisotropic" }
  381. }
  382.  
  383. defined_HIQUALITY_GBUFFER_NORMALS = {
  384. nft = { sampler_states = "clamp_point" }
  385. }
  386.  
  387. defined_AMBIENT_OCCLUSION_MAP = {
  388. ambient_occlusion_map = { sampler_states = "wrap_anisotropic" }
  389. }
  390.  
  391. defined_SUBSURFACE_SCATTERING_MAP = {
  392. subsurface_scattering_map = { sampler_states = "wrap_anisotropic" }
  393. }
  394. defined_COLORED_SPECULAR= {
  395. specular_map = { sampler_states = "wrap_anisotropic_srgb" }
  396. }
  397. }
  398.  
  399. instance_data = {
  400. defined_INSTANCED = {
  401. world = { type = "matrix4x4" }
  402. defined_MATERIAL_TINT_RGB = {
  403. tint_rgb = { type = "vector3" }
  404. }
  405. defined_DRAW_WIREFRAME = {
  406. dev_wireframe_color = { type = "vector4" }
  407. }
  408. }
  409. }
  410.  
  411. code="""
  412. #if defined(MASKED_VC_BLEND) || defined(VC_TINT_RGB) || defined(CLOTH_SHADING_VC_MASK)
  413. #define VERTEX_COLOR
  414. #endif
  415.  
  416. #if defined(DETAIL_DIFFUSE_MAP) || defined(DETAIL_MATERIAL_MAP) || defined(DETAIL_NORMAL_MAP)
  417. #define DETAIL_MAPPING
  418. #endif
  419.  
  420. #if defined(VEGETATION_BENDING) || defined(DISSOLVE_ALPHA_OVER_DISTANCE) || defined(INSTANCED) || defined(CLOTH_SHADING)
  421. #define NEEDS_WORLD_SPACE
  422. #endif
  423.  
  424. #if defined(CLOTH_SHADING)
  425. #define PS_NEEDS_WP
  426. #endif
  427.  
  428. struct VS_INPUT {
  429. float4 position : POSITION;
  430. float3 normal : NORMAL0;
  431. SKIN_INPUT
  432. #if defined(NORMAL_MAP)
  433. float3 tangent : TANGENT;
  434. float3 binormal : BINORMAL;
  435. #endif
  436. #if defined(VERTEX_COLOR) || defined(VEGETATION_BENDING)
  437. float4 color : COLOR0;
  438. #endif
  439.  
  440. #if defined(HAS_UV)
  441. float2 vs_default_uv : TEXCOORD0;
  442. #if defined(DIFFUSE_MAP_UNIQUE_UV)
  443. float2 vs_diffuse_uv : TEXCOORD1;
  444. #else
  445. #define vs_diffuse_uv vs_default_uv
  446. #endif
  447. #if defined(SELF_ILLUMINATION_MAP_UNIQUE_UV)
  448. float2 vs_self_illumination_uv : TEXCOORD2;
  449. #else
  450. #define vs_self_illumination_uv vs_default_uv
  451. #endif
  452. #if defined(NORMAL_MAP)
  453. #define vs_normal_uv vs_default_uv
  454. #endif
  455. #if defined(MATERIAL_MAP_UNIQUE_UV)
  456. float2 vs_material_uv : TEXCOORD3;
  457. #else
  458. #define vs_material_uv vs_default_uv
  459. #endif
  460. #endif
  461.  
  462. #if defined(BAKED_VERTEX_AMBIENT_OCCLUSION)
  463. float4 baked_ambient_occlusion : COLOR1;
  464. #endif
  465.  
  466. #if defined(BRUSH_INSTANCED) && defined(GL2)
  467. float4 instance_data0 : TEXCOORD4;
  468. float4 instance_data1 : TEXCOORD5;
  469. float4 instance_data2 : TEXCOORD6;
  470.  
  471. #if defined(MATERIAL_TINT_RGB)
  472. float4 instance_data3 : TEXCOORD7;
  473. #endif
  474. #endif
  475. };
  476.  
  477. struct PS_INPUT {
  478. float4 position : SV_POSITION;
  479. #if defined(NORMAL_MAP)
  480. float3 tsm0 : TEXCOORD1;
  481. float3 tsm1 : TEXCOORD2;
  482. float3 tsm2 : TEXCOORD3;
  483. #else
  484. float3 normal : TEXCOORD1;
  485. #endif
  486. #if defined(USE_DEPTH_RT)
  487. float depth : TEXCOORD7;
  488. #endif
  489. #if defined(VERTEX_COLOR)
  490. float4 color : COLOR0;
  491. #endif
  492.  
  493. #if defined(DIFFUSE_MAP)
  494. #if defined(NORMAL_MAP)
  495. float4 uv0 : TEXCOORD0;
  496. #define diffuse_uv uv0.xy
  497. #define normal_uv uv0.zw
  498. #else
  499. float2 diffuse_uv : TEXCOORD0;
  500. #endif
  501. #else
  502. #if defined(NORMAL_MAP)
  503. float2 normal_uv : TEXCOORD0;
  504. #endif
  505. #endif
  506.  
  507. #if defined(MATERIAL_MAP)
  508. #if defined(SELF_ILLUMINATION_MAP)
  509. float4 uv1 : TEXCOORD5;
  510. #define material_uv uv1.xy
  511. #define self_illumination_uv uv1.zw
  512. #else
  513. float2 material_uv : TEXCOORD5;
  514. #endif
  515. #elif defined(SELF_ILLUMINATION_MAP)
  516. float2 self_illumination_uv : TEXCOORD5;
  517. #endif
  518.  
  519. #if defined(BLEND_NORMAL_OBJECT_POSITIVE_Z)
  520. #if defined(DISSOLVE_ALPHA_OVER_DISTANCE)
  521. float4 user_data : TEXCOORD6;
  522. #define object_z user_data.xyz
  523. #define dissolve_alpha user_data.w
  524. #else
  525. float3 object_z : TEXCOORD6;
  526. #endif
  527. #else
  528. #if defined(DISSOLVE_ALPHA_OVER_DISTANCE)
  529. float user_data : TEXCOORD6;
  530. #define dissolve_alpha user_data.x
  531. #endif
  532. #endif
  533.  
  534. #if defined(PS_NEEDS_WP)
  535. float3 wp : TEXCOORD7;
  536. #endif
  537.  
  538. #if defined(INSTANCED) && (defined(D3D11) || defined(GL2))
  539. #if defined(DRAW_WIREFRAME)
  540. float4 instance_wireframe_color : TEXCOORD4;
  541. #elif defined(MATERIAL_TINT_RGB)
  542. float3 material_instance_tint : TEXCOORD4;
  543. #endif
  544.  
  545. #endif
  546.  
  547. #if defined(BAKED_VERTEX_AMBIENT_OCCLUSION)
  548. float4 baked_ambient_occlusion : TEXCOORD4;
  549. #endif
  550. };
  551.  
  552. CBUFFER_START(c_per_object)
  553. #if defined(NEEDS_WORLD_SPACE)
  554. float4x4 view_proj;
  555. #else
  556. float4x4 world_view_proj;
  557. #endif
  558. float4x4 world;
  559. #ifndef MATERIAL_MAP
  560. float glossiness; // exports={ name="Glossiness Amount" type="scalar" value=0.5 min=0.0 max=1.0 step=0.001 sort_tag="1_MATERIAL_MAP_0" }
  561. float specular; // exports={ name="Specular Mask" type="scalar" value=0.8 min=0.0 max=1.0 step=0.001 sort_tag="1_MATERIAL_MAP_1" }
  562. #endif
  563. #ifdef MASKED_VC_BLEND
  564. float masked_blend_smoothing; // exports={ name="Masked Blend Smoothing" type="scalar" value=0.2 min=0.001 max=1.0 step=0.001 sort_tag="3_MASKED_VC_BLEND4" }
  565. #endif
  566. #ifdef SELF_ILLUMINATION_MAP
  567. float self_illumination_multiplier; // exports={ name="Self Illumination Multiplier" type="scalar" value=1.0 min=0.0 max=10.0 step=0.01 sort_tag="5_SELF_ILLUMINATION1" }
  568. float emissive_material_intensity;
  569. #endif
  570. #if defined(BLEND_NORMAL_WORLD_POSITIVE_Z)
  571. float normal_world_positive_z_blend; // exports={ name="Normal To World Z+ Blend" type="scalar" value=0.0 min=0.0 max=1.0 step=0.01 }
  572. #endif
  573. #if defined(BLEND_NORMAL_OBJECT_POSITIVE_Z)
  574. float normal_object_positive_z_blend; // exports={ name="Normal To Object Z+ Blend" type="scalar" value=0.0 min=0.0 max=1.0 step=0.01 }
  575. #endif
  576. #if defined(ONE_BIT_ALPHA) && defined(EXTERNAL_ALPHA_REF)
  577. float external_alpha_ref; // exports={ name="Alpha Mask Clip" type="scalar" value=0.5 min=0.0 max=1.0 step=0.001 }
  578. #endif
  579. #if defined(DETAIL_MAPPING)
  580. float2 detail_uv_scale; // exports={ name="Detail UV Scale" type="vector2" value=[5.0 5.0] min=[1 1] max=[20 20] step=[0.01 0.01] sort_tag="4_DETAIL_MAPPING3" }
  581. #endif
  582. #if defined(MATERIAL_TINT_RGB)
  583. float3 tint_rgb; // exports={ name="Material Tint Color (x2)" type="vector3" value=[0.5 0.5 0.5] min=[0 0 0] max=[1 1 1] step=[0.001 0.001 0.001] }
  584. #endif
  585. #if defined(JITTERED_TRANSPARENCY)
  586. float transparency; // exports={ name="Transparency" type="scalar" value=0.5 min=0.0 max=1 step=0.001 }
  587. #endif
  588. #if !defined(DIFFUSE_MAP)
  589. float3 diffuse_rgb; // exports={ name="Diffuse RGB" type="vector3" value=[0.5 0.5 0.5] min=[0 0 0] max=[1 1 1] step=[0.001 0.001 0.001] }
  590. #endif
  591. #if defined(CLOTH_SHADING)
  592. float2 rim_lobe_settings; // exports={ name="Rim Lobe Scale/Exp" type="vector2" value=[0.33 2] min=[0.001 0.001] max=[5.0 20.0] step=[0.01 0.01] }
  593. float2 inner_lobe_settings; // exports={ name="Inner Lobe Scale/Exp" type="vector2" value=[0.33 2] min=[0.001 0.001] max=[5.0 20.0] step=[0.01 0.01] }
  594. float lambert_scale; // exports={ name="Lambert Scale" type="scalar" value=0.33 min=0.0 max=2 step=0.001 }
  595. #endif
  596. #if defined(SKIN) && !defined(SUBSURFACE_SCATTERING_MAP)
  597. float sss_strength; // exports={ name="SSS Strength" type="scalar" value=0.8 min=0.0 max=1.0 step=0.001 sort_tag="1_MATERIAL_MAP_2" }
  598. #endif
  599. #if defined(DISSOLVE_ALPHA_OVER_DISTANCE)
  600. float2 dissolve_distance_range; // exports={ name="Dissolve Distance Range [start, distance]" type="vector2" value=[32 5] min=[0 0.1] max=[100 100] step=[0.01 0.01] }
  601. #endif
  602. #if defined(INSTANCED) && defined(GL2)
  603. float4 instance_buffer[100];
  604. #endif
  605. float4 dev_wireframe_color;
  606. CBUFFER_END
  607.  
  608. #if defined(DIFFUSE_MAP)
  609. sampler2D diffuse_map; // exports={ name="Diffuse Map" type="resource" sort_tag="0_DIFFUSE_MAP"}
  610. #endif
  611.  
  612. #if defined(NORMAL_MAP)
  613. sampler2D normal_map; // exports={ name="Normal Map" type="resource" sort_tag="2_NORMAL_MAP" }
  614. #endif
  615.  
  616. #if defined(MATERIAL_MAP)
  617. sampler2D material_map; // exports={ name="Glossiness/Specular/Mask Map" type="resource" sort_tag="1_MATERIAL_MAP"}
  618. #endif
  619.  
  620. #if defined(SELF_ILLUMINATION_MAP)
  621. sampler2D self_illumination_map; // exports={ name="Self Illumination Map" type="resource" sort_tag="5_SELF_ILLUMINATION" }
  622. #endif
  623.  
  624. #if defined(MASKED_VC_BLEND)
  625. sampler2D blend_diffuse_map; // exports={ name="Blend Diffuse Map" type="resource" sort_tag="3_MASKED_VC_BLEND0" }
  626. sampler2D blend_material_map; // exports={ name="Blend Material Map" type="resource" sort_tag="3_MASKED_VC_BLEND1" }
  627. #if defined(NORMAL_MAP)
  628. sampler2D blend_normal_map; // exports={ name="Blend Normal Map" type="resource" sort_tag="3_MASKED_VC_BLEND2" }
  629. #endif
  630. #endif
  631.  
  632. #if defined(DETAIL_DIFFUSE_MAP)
  633. sampler2D detail_diffuse_map; // exports={ name="Detail Diffuse Map" type="resource" sort_tag="4_DETAIL_MAPPING0" }
  634. #endif
  635.  
  636. #if defined(DETAIL_NORMAL_MAP)
  637. sampler2D detail_normal_map; // exports={ name="Detail Normal Map" type="resource" sort_tag="4_DETAIL_MAPPING2" }
  638. #endif
  639.  
  640. #if defined(DETAIL_MATERIAL_MAP)
  641. sampler2D detail_material_map; // exports={ name="Detail Glossiness/Specular/Mask Map" type="resource" sort_tag="4_DETAIL_MAPPING1"}
  642. #endif
  643.  
  644. #if defined(HIQUALITY_GBUFFER_NORMALS)
  645. sampler2D nft;
  646. #endif
  647.  
  648. #if defined(BRUSH_INSTANCED) && defined(D3D11)
  649. Buffer<float4> instance_data;
  650. float instance_offset;
  651. #endif
  652.  
  653. #if defined(INSTANCED) && defined(D3D11)
  654. Buffer<float4> idata;
  655. float ioffset;
  656. #endif
  657.  
  658. #if defined(AMBIENT_OCCLUSION_MAP)
  659. sampler2D ambient_occlusion_map; // exports={ name="Ambient Occlusion Map" type="resource" sort_tag="5_AMBIENT_OCCLUSION" }
  660. #endif
  661.  
  662. #if defined(SUBSURFACE_SCATTERING_MAP)
  663. sampler2D subsurface_scattering_map; // exports={ name="Subsurface Scattering Map" type="resource" sort_tag="5_AMBIENT_OCCLUSION" }
  664. #endif
  665.  
  666. #if defined(COLORED_SPECULAR)
  667. sampler2D specular_map; // exports={ name="Specular Map" type="resource" sort_tag="0_SPECULAR_MASK" }
  668. #endif
  669.  
  670. PS_INPUT vs_main(VS_INPUT input
  671. #if (defined(INSTANCED) || defined(BRUSH_INSTANCED)) && (defined(D3D11) || defined(GL2))
  672. , uint instance_id : SV_InstanceId
  673. #endif
  674. )
  675. {
  676. PS_INPUT o;
  677.  
  678. float4 position;
  679. float3 normal;
  680. #ifdef NORMAL_MAP
  681. float3 tangent;
  682. float3 binormal;
  683. #endif
  684.  
  685. #ifdef SKINNED
  686. position = float4(skin_point(input.position, input.blendindices, input.blendweights), 1);
  687. normal = skin_vector(input.normal, input.blendindices, input.blendweights);
  688. #ifdef NORMAL_MAP
  689. tangent = skin_vector(input.tangent, input.blendindices, input.blendweights);
  690. binormal = skin_vector(input.binormal, input.blendindices, input.blendweights);
  691. #endif
  692. #else
  693. position = input.position;
  694. normal = input.normal;
  695. #ifdef NORMAL_MAP
  696. tangent = input.tangent;
  697. binormal = input.binormal;
  698. #endif
  699. #endif
  700.  
  701. #if defined(BRUSH_INSTANCED) && defined(D3D11)
  702. uint offset = (uint)instance_offset;
  703. world[0] = instance_data.Load((offset+instance_id) * 3 + 0);
  704. world[1] = instance_data.Load((offset+instance_id) * 3 + 1);
  705. world[2] = instance_data.Load((offset+instance_id) * 3 + 2);
  706. world[3][0] = world[0][3]; world[0][3] = 0;
  707. world[3][1] = world[1][3]; world[1][3] = 0;
  708. world[3][2] = world[2][3]; world[2][3] = 0;
  709. #endif
  710.  
  711. #if defined(INSTANCED) && defined(D3D11)
  712. uint offset = (uint)ioffset;
  713. world[0] = idata.Load(offset + (instance_id*IDATA_STRIDE + IDATA_world + 0));
  714. world[1] = idata.Load(offset + (instance_id*IDATA_STRIDE + IDATA_world + 1));
  715. world[2] = idata.Load(offset + (instance_id*IDATA_STRIDE + IDATA_world + 2));
  716. world[3] = idata.Load(offset + (instance_id*IDATA_STRIDE + IDATA_world + 3));
  717.  
  718. #if defined(DRAW_WIREFRAME)
  719. o.instance_wireframe_color = idata.Load(offset + (instance_id*IDATA_STRIDE + IDATA_dev_wireframe_color));
  720. #elif defined(MATERIAL_TINT_RGB)
  721. o.material_instance_tint = idata.Load(offset + (instance_id*IDATA_STRIDE + IDATA_tint_rgb)).rgb;
  722. #endif
  723. #endif
  724.  
  725. #if defined(BRUSH_INSTANCED) && defined(GL2)
  726. world = float4x4(input.instance_data0, input.instance_data1, input.instance_data2, float4(0, 0, 0, 1));
  727. world._m30_m31_m32 = world._m03_m13_m23;
  728. world._m03_m13_m23 = float3(0, 0, 0);
  729. #endif
  730.  
  731. #if defined(INSTANCED) && defined(GL2)
  732. world = float4x4(instance_buffer[instance_id*IDATA_STRIDE + IDATA_world + 0],
  733. instance_buffer[instance_id*IDATA_STRIDE + IDATA_world + 1],
  734. instance_buffer[instance_id*IDATA_STRIDE + IDATA_world + 2],
  735. instance_buffer[instance_id*IDATA_STRIDE + IDATA_world + 3]);
  736.  
  737. #if defined(DRAW_WIREFRAME)
  738. o.instance_wireframe_color = instance_buffer[instance_id*IDATA_STRIDE + IDATA_dev_wireframe_color];
  739. #elif defined(MATERIAL_TINT_RGB)
  740. o.material_instance_tint = instance_buffer[instance_id*IDATA_STRIDE + IDATA_tint_rgb];
  741. #endif
  742. #endif
  743.  
  744. float4 p;
  745. #if defined(NEEDS_WORLD_SPACE)
  746. float4 wp = mul(position, world);
  747. #if defined(VEGETATION_BENDING)
  748. float3 op = world._m30_m31_m32;
  749. float3 wnormal = mul(normal, (float3x3)world);
  750. wp = vegetation_bending(op, wp, wnormal, input.color, input.position); //TODO: decode_vertex_color(input.color);
  751. #endif
  752. p = mul(wp, view_proj);
  753.  
  754. #ifdef PS_NEEDS_WP
  755. o.wp = wp;
  756. #endif
  757. #else
  758. #if defined(BRUSH_INSTANCED) && (defined(D3D11) || defined(GL2))
  759. position = mul(position, world);
  760. #endif
  761. p = mul(position, world_view_proj);
  762. #endif
  763.  
  764. #ifdef DIFFUSE_MAP
  765. o.diffuse_uv = diffuse_uv_modifier(input.vs_diffuse_uv);
  766. #endif
  767.  
  768. #ifdef NORMAL_MAP
  769. o.normal_uv = normal_uv_modifier(input.vs_normal_uv);
  770. #endif
  771.  
  772. #ifdef MATERIAL_MAP
  773. o.material_uv = material_uv_modifier(input.vs_material_uv);
  774. #endif
  775.  
  776. #ifdef SELF_ILLUMINATION_MAP
  777. o.self_illumination_uv = self_illumination_uv_modifier(input.vs_self_illumination_uv);
  778. #endif
  779.  
  780. #ifdef NORMAL_MAP
  781. tspace_transform_transpose(o.tsm0, o.tsm1, o.tsm2, tangent, binormal, normal, (float3x3)world);
  782. #else
  783. o.normal = mul(normal, (float3x3)world);
  784. #endif
  785.  
  786. #ifdef VERTEX_COLOR
  787. // TODO: color remapping needed when vertex compression in place.
  788. #ifdef VC_COMPRESSED
  789. o.color = decode_vertex_color(input.color);
  790. #else
  791. o.color = input.color; //decode_vertex_color(input.color);
  792. #endif
  793. #endif
  794.  
  795. o.position = p;
  796. #if defined(USE_DEPTH_RT)
  797. #if defined(GL2)
  798. o.depth = linearize_depth(p.z*0.5 / p.w + 0.5);
  799. #else
  800. o.depth = linearize_depth(p.z / p.w);
  801. #endif
  802. #endif
  803.  
  804. #if defined(BLEND_NORMAL_OBJECT_POSITIVE_Z)
  805. o.object_z = world._m20_m21_m22;
  806. #endif
  807.  
  808. #if defined(DISSOLVE_ALPHA_OVER_DISTANCE)
  809. float d = distance(wp.xyz, camera_world._m30_m31_m32);
  810. o.dissolve_alpha = (d < dissolve_distance_range.x) ? 0 : saturate((d - dissolve_distance_range.x) / dissolve_distance_range.y);
  811. #endif
  812.  
  813.  
  814. #if defined(BAKED_VERTEX_AMBIENT_OCCLUSION)
  815. o.baked_ambient_occlusion = input.baked_ambient_occlusion.zzzz;
  816. #endif
  817.  
  818. return o;
  819. }
  820.  
  821. #ifdef DRAW_WIREFRAME
  822. float4 ps_main(PS_INPUT input) : SV_TARGET0 {
  823. #if defined(INSTANCED) && (defined(D3D11) || defined(GL2))
  824. dev_wireframe_color = input.instance_wireframe_color;
  825. #endif
  826. return dev_wireframe_color;
  827. }
  828. #else
  829. GBUFFER_OUT ps_main(
  830. PS_INPUT input
  831. #if defined(DOUBLE_SIDED)
  832. ,float vface : VFACE
  833. #endif
  834. #if (defined(SEMI_TRANSPARENCY) || defined(JITTERED_TRANSPARENCY))
  835. #if defined(GCM)
  836. , float4 wpos : WPOS
  837. #elif defined(X360) || defined(GL2)
  838. , float4 wpos : VPOS
  839. #endif
  840. #endif
  841. )
  842. {
  843. GBUFFER_OUT o;
  844.  
  845. #ifdef SEMI_TRANSPARENCY
  846. #if defined(GCM) || defined(X360) || defined(GL2)
  847. int2 pos = int2(wpos.x, wpos.y);
  848. #else
  849. int2 pos = input.position.xy;
  850. #endif
  851. int idx = (pos.x + pos.y) % 2;
  852. if (idx == 0)
  853. discard;
  854. #endif
  855.  
  856. #ifdef JITTERED_TRANSPARENCY
  857. #if defined(GCM) || defined(X360) || defined(GL2)
  858. int2 pos = int2(wpos.x, back_buffer_size.y-wpos.y);
  859. #else
  860. int2 pos = input.position.xy;
  861. #endif
  862.  
  863. float alpha = (float)((pos.x%2) + 2*(pos.y%2)) * 0.25;
  864. if (alpha >= transparency)
  865. discard;
  866. #endif
  867.  
  868. #if defined(USE_DEPTH_RT)
  869. DEPTH(o) = gbuffer_encode_depth(input.depth);
  870. #endif
  871.  
  872. #ifdef MATERIAL_MAP
  873. half4 gsm = tex2D(material_map, input.material_uv);
  874. half2 specular_glossiness = float2(gsm.g, gsm.r);
  875. #else
  876. half2 specular_glossiness = float2(specular, glossiness);
  877. #endif
  878.  
  879. #ifdef SKIN
  880. #ifdef SUBSURFACE_SCATTERING_MAP
  881. half sss_strength = tex2D(subsurface_scattering_map, input.diffuse_uv).g;
  882. #endif
  883. #endif
  884.  
  885. #ifdef SEMI_TRANSPARENCY
  886. half4 diffuse = half4(1,1,1,1);
  887. #elif defined(DIFFUSE_MAP)
  888. half4 diffuse = tex2D(diffuse_map, input.diffuse_uv);
  889. #else
  890. half4 diffuse = half4(diffuse_rgb, 1);
  891. #endif
  892. half3 albedo = diffuse.rgb;
  893.  
  894. #if defined(ONE_BIT_ALPHA)
  895. #if defined(EXTERNAL_ALPHA_REF)
  896. half alpha_ref = external_alpha_ref;
  897. #else
  898. half alpha_ref = ONE_BIT_ALPHA_REF;
  899. #endif
  900.  
  901. #if defined(DISSOLVE_ALPHA_OVER_DISTANCE)
  902. alpha_ref = lerp(alpha_ref, 1, input.dissolve_alpha);
  903. #endif
  904.  
  905. #if defined(ONE_BIT_ALPHA_FROM_MATERIAL_B)
  906. one_bit_alpha_mask(gsm.b, alpha_ref);
  907. #else
  908. one_bit_alpha_mask(diffuse.a, alpha_ref);
  909. #endif
  910. #endif
  911.  
  912. #ifdef DETAIL_MAPPING
  913. float2 detail_uv = input.normal_uv * detail_uv_scale;
  914.  
  915. #ifdef DETAIL_MATERIAL_MAP
  916. float3 detail_gsm = tex2D(detail_material_map, detail_uv).rgb * 2;
  917. specular_glossiness *= float2(detail_gsm.g, detail_gsm.r);
  918. #endif
  919. #endif
  920.  
  921. #ifdef VERTEX_COLOR
  922. #if defined(MASKED_VC_BLEND)
  923. half3 layer0_gsm = tex2D(blend_material_map, input.material_uv);
  924. half first_layer_blend = smoothstep(saturate(gsm.b - masked_blend_smoothing), gsm.b, input.color.a);
  925. albedo = lerp(albedo, tex2D(blend_diffuse_map, input.diffuse_uv), first_layer_blend);
  926. specular_glossiness = lerp(specular_glossiness, layer0_gsm.gr, first_layer_blend);
  927. #endif
  928. #endif
  929.  
  930. #ifdef DETAIL_DIFFUSE_MAP
  931. half3 detail_diffuse = tex2D(detail_diffuse_map, detail_uv).rgb * 2;
  932. albedo *= detail_diffuse;
  933. #endif
  934.  
  935. #ifdef VC_TINT_RGB
  936. albedo *= fast_gamma_to_linear_rgb(input.color.rgb);
  937. #endif
  938.  
  939. #ifdef MATERIAL_TINT_RGB
  940. #if defined(INSTANCED) && (defined(D3D11) || defined(GL2))
  941. tint_rgb = input.material_instance_tint;
  942. #endif
  943.  
  944. albedo *= tint_rgb * 2;
  945. #endif
  946.  
  947. half a;
  948. half ao = 1;
  949. #ifdef AMBIENT_OCCLUSION_MATERIAL_MAP
  950. ao = gsm.a;
  951. #elif defined(AMBIENT_OCCLUSION_MAP)
  952. ao = tex2D(ambient_occlusion_map, input.normal_uv).r;
  953. #endif
  954.  
  955. #if defined(BAKED_VERTEX_AMBIENT_OCCLUSION)
  956. ao *= input.baked_ambient_occlusion.b;
  957. #endif
  958.  
  959. ALBEDO(o) = gbuffer_encode_albedo(albedo);
  960.  
  961. half3 world_space_normal = half3(0,0,0);
  962. #ifdef NORMAL_MAP
  963. half3 tnormal = decode_normal_map(tex2D(normal_map, input.normal_uv));
  964. #if defined(MASKED_VC_BLEND)
  965. half3 first_layer_tnormal = decode_normal_map(tex2D(blend_normal_map, input.normal_uv));
  966. tnormal = lerp(tnormal, first_layer_tnormal, first_layer_blend);
  967. #endif
  968. #ifdef DETAIL_NORMAL_MAP
  969. half3 detail_tnormal = decode_normal_map(tex2D(detail_normal_map, detail_uv));
  970. tnormal = half3(tnormal.xy + detail_tnormal.xy, tnormal.z * detail_tnormal.z);
  971. #endif
  972.  
  973. #if defined(DOUBLE_SIDED)
  974. if (vface < 0) {
  975. input.tsm0.z = -input.tsm0.z;
  976. input.tsm1.z = -input.tsm1.z;
  977. input.tsm2.z = -input.tsm2.z;
  978. }
  979. #endif
  980.  
  981. world_space_normal = rotate_vector3(tnormal, (half3)input.tsm0, (half3)input.tsm1, (half3)input.tsm2);
  982. #else
  983. world_space_normal = normalize((half3)input.normal);
  984. #if defined(DOUBLE_SIDED)
  985. world_space_normal = vface < 0 ? -world_space_normal : world_space_normal;
  986. #endif
  987. #endif
  988.  
  989. #if defined(BLEND_NORMAL_WORLD_POSITIVE_Z)
  990. #if defined(MASK_BLEND_NORMAL_WITH_MATERIAL)
  991. normal_world_positive_z_blend *= gsm.b;
  992. #endif
  993.  
  994. world_space_normal = normalize(lerp(world_space_normal, half3(0,0,1), normal_world_positive_z_blend));
  995. #endif
  996.  
  997. #if defined(BLEND_NORMAL_OBJECT_POSITIVE_Z)
  998. #if defined(MASK_BLEND_NORMAL_WITH_MATERIAL)
  999. normal_object_positive_z_blend *= gsm.b;
  1000. #endif
  1001.  
  1002. world_space_normal = normalize(lerp(world_space_normal, input.object_z, normal_object_positive_z_blend));
  1003. #endif
  1004.  
  1005. #if defined(HIQUALITY_GBUFFER_NORMALS)
  1006. NORMAL(o) = gbuffer_encode_normal_hiquality(world_space_normal, nft);
  1007. #else
  1008. NORMAL(o) = gbuffer_encode_normal(world_space_normal);
  1009. #endif
  1010.  
  1011. SPECULAR(o) = gbuffer_encode_specular_mask(specular_glossiness.x);
  1012. GLOSSINESS(o) = gbuffer_encode_glossiness(specular_glossiness.y);
  1013.  
  1014. #ifdef SELF_ILLUMINATION_MAP
  1015. half4 il = tex2D(self_illumination_map, input.self_illumination_uv);
  1016. #if defined(MATERIAL_TINT_RGB) && defined(SELF_ILLUMINATION_TINT_MATERIAL)
  1017. il.rgb *= tint_rgb;
  1018. #endif
  1019.  
  1020. il.rgb *= self_illumination_multiplier * emissive_material_intensity;
  1021.  
  1022. #ifndef X360
  1023. LIGHT_ACCUMULATION(o) = gbuffer_encode_self_illumination(il.rgb);
  1024. #endif
  1025. #endif
  1026.  
  1027. #if defined(CLOTH_SHADING)
  1028. half4 lobe_settings = half4(inner_lobe_settings.xy, rim_lobe_settings.xy);
  1029. #if defined(CLOTH_SHADING_VC_MASK)
  1030. lobe_settings *= input.color;
  1031. #endif
  1032. half v_dot_n = saturate(dot(world_space_normal, normalize(camera_pos - input.wp)));
  1033. half rim_lobe = lobe_settings.z * pow(1-v_dot_n, lobe_settings.w);
  1034. half inner_lobe = lobe_settings.x * pow(v_dot_n, lobe_settings.y);
  1035. half diffuse_multiplier = saturate((lambert_scale + rim_lobe + inner_lobe) * 0.5);
  1036.  
  1037. GBUFFER_AUX(o) = half4(0, CLOTH_MATERIAL, diffuse_multiplier, ao);
  1038. #elif defined(SKIN)
  1039. GBUFFER_AUX(o) = half4(0, SKIN_MATERIAL, sss_strength, ao);
  1040. #elif defined(COLORED_SPECULAR)
  1041. half3 spec_col = tex2D(specular_map, input.diffuse_uv).rgb;
  1042. spec_col = sqrt(spec_col);
  1043. GBUFFER_AUX(o) = half4(0, COLORED_SPECULAR_MATERIAL + spec_col.r, spec_col.g, ao);
  1044. SPECULAR(o) = spec_col.b;
  1045. #else
  1046. GBUFFER_AUX(o) = half4(0, DEFAULT_MATERIAL, 0, ao);
  1047. #endif
  1048.  
  1049. return o;
  1050. }
  1051. #endif
  1052. """
  1053. }
  1054.  
  1055. depth_only = {
  1056. includes = [ "common", "skinning", "vegetation_bending" ]
  1057.  
  1058. samplers = {
  1059. defined_ONE_BIT_ALPHA = {
  1060. defined_ONE_BIT_ALPHA_FROM_MATERIAL_B = {
  1061. material_map = { sampler_states = "wrap_linear_srgb" }
  1062. }
  1063. ndefined_ONE_BIT_ALPHA_FROM_MATERIAL_B = {
  1064. diffuse_map = { sampler_states = "wrap_linear_srgb" }
  1065. }
  1066. }
  1067. }
  1068.  
  1069. instance_data = {
  1070. defined_INSTANCED = {
  1071. world = { type = "matrix4x4" }
  1072. }
  1073. }
  1074.  
  1075. code="""
  1076. #if defined(VEGETATION_BENDING) || defined(INSTANCED)
  1077. #define NEEDS_WORLD_SPACE
  1078. #endif
  1079.  
  1080. struct VS_INPUT {
  1081. float4 position : POSITION;
  1082. #if defined(ONE_BIT_ALPHA)
  1083. float2 uv : TEXCOORD0;
  1084. #endif
  1085. SKIN_INPUT
  1086. #if defined(VEGETATION_BENDING)
  1087. float4 color : COLOR0;
  1088. float3 normal : NORMAL;
  1089. #endif
  1090. };
  1091. /*
  1092. struct PS_INPUT {
  1093. float4 position : SV_POSITION;
  1094. uint rt_index : SV_RenderTargetArrayIndex;
  1095. };
  1096. */
  1097.  
  1098. struct PS_INPUT {
  1099. float4 position : SV_POSITION;
  1100. #if defined(ONE_BIT_ALPHA)
  1101. float2 uv : TEXCOORD0;
  1102. #endif
  1103. };
  1104.  
  1105. CBUFFER_START(c0)
  1106. #if defined(NEEDS_WORLD_SPACE)
  1107. float4x4 world;
  1108. float4x4 view_proj;
  1109. #else
  1110. float4x4 world_view_proj;
  1111. #endif
  1112. #if defined(ONE_BIT_ALPHA) && defined(EXTERNAL_ALPHA_REF)
  1113. float external_alpha_ref;
  1114. #endif
  1115. //float rt_index;
  1116.  
  1117. #if defined(INSTANCED) && defined(GL2)
  1118. float4 instance_buffer[100];
  1119. #endif
  1120. CBUFFER_END
  1121.  
  1122. #if defined(ONE_BIT_ALPHA)
  1123. #if defined(ONE_BIT_ALPHA_FROM_MATERIAL_B)
  1124. sampler2D material_map;
  1125. #else
  1126. sampler2D diffuse_map;
  1127. #endif
  1128. #endif
  1129.  
  1130. #if defined(INSTANCED) && defined(D3D11)
  1131. Buffer<float4> idata;
  1132. float ioffset;
  1133. #endif
  1134.  
  1135. PS_INPUT vs_main(VS_INPUT input
  1136. #if defined(INSTANCED) && (defined(D3D11) || defined(GL2))
  1137. , uint instance_id : SV_InstanceId
  1138. #endif
  1139. )
  1140. {
  1141. PS_INPUT o;
  1142.  
  1143. float4 position;
  1144. #ifdef SKINNED
  1145. position = float4(skin_point(input.position, input.blendindices, input.blendweights), 1);
  1146. #else
  1147. position = input.position;
  1148. #endif
  1149.  
  1150. #if defined(INSTANCED) && defined(D3D11)
  1151. uint offset = (uint)ioffset;
  1152. world[0] = idata.Load(offset + (instance_id*IDATA_STRIDE + IDATA_world + 0));
  1153. world[1] = idata.Load(offset + (instance_id*IDATA_STRIDE + IDATA_world + 1));
  1154. world[2] = idata.Load(offset + (instance_id*IDATA_STRIDE + IDATA_world + 2));
  1155. world[3] = idata.Load(offset + (instance_id*IDATA_STRIDE + IDATA_world + 3));
  1156. #endif
  1157.  
  1158. #if defined(INSTANCED) && defined(GL2)
  1159. world = float4x4(instance_buffer[instance_id*IDATA_STRIDE + IDATA_world + 0],
  1160. instance_buffer[instance_id*IDATA_STRIDE + IDATA_world + 1],
  1161. instance_buffer[instance_id*IDATA_STRIDE + IDATA_world + 2],
  1162. instance_buffer[instance_id*IDATA_STRIDE + IDATA_world + 3]);
  1163. #endif
  1164.  
  1165. float4 p;
  1166. #if defined(NEEDS_WORLD_SPACE)
  1167. float4 wp = mul(position, world);
  1168. #if defined(VEGETATION_BENDING)
  1169. float3 op = world._m30_m31_m32;
  1170. float3 wnormal = mul(input.normal, (float3x3)world);
  1171. wp = vegetation_bending(op, wp, wnormal, input.color, input.position); //TODO: decode_vertex_color(input.color);
  1172. #endif
  1173. p = mul(wp, view_proj);
  1174. #else
  1175. p = mul(position, world_view_proj);
  1176. #endif
  1177.  
  1178. o.position = p;
  1179.  
  1180. #ifdef ONE_BIT_ALPHA
  1181. o.uv = input.uv;
  1182. #endif
  1183. return o;
  1184. }
  1185. /*
  1186. [maxvertexcount(3)]
  1187. void gss_main(triangle GS_INPUT input[3], inout TriangleStream<PS_INPUT> output) {
  1188. PS_INPUT o;
  1189. o.rt_index = (uint)rt_index;
  1190. [unroll]
  1191. for (int v = 0; v < 3; ++v) {
  1192. o.position = input[v].position;
  1193. output.Append(o);
  1194. }
  1195. }
  1196. */
  1197.  
  1198. #if !defined(X360) || defined(ONE_BIT_ALPHA)
  1199. float4 ps_main(PS_INPUT input) : SV_TARGET0 {
  1200. #if defined(ONE_BIT_ALPHA)
  1201. #if defined(EXTERNAL_ALPHA_REF)
  1202. half alpha_ref = external_alpha_ref;
  1203. #else
  1204. half alpha_ref = ONE_BIT_ALPHA_REF;
  1205. #endif
  1206.  
  1207. #if defined(ONE_BIT_ALPHA_FROM_MATERIAL_B)
  1208. one_bit_alpha_mask(tex2D(material_map, input.uv).b, alpha_ref);
  1209. #else
  1210. one_bit_alpha_mask(tex2D(diffuse_map, input.uv).a, alpha_ref);
  1211. #endif
  1212. #endif
  1213.  
  1214.  
  1215. return float4(1,1,1,1);
  1216. }
  1217. #endif
  1218. """
  1219. }
  1220.  
  1221. forward_base = {
  1222. includes = [ "common", "gbuffer_access", "skinning", "vegetation_bending", "uv_management" ]
  1223.  
  1224. samplers = {
  1225. defined_SKYDOME = {
  1226. defined_DIFFUSE_MAP = {
  1227. diffuse_map = { sampler_states = "wrap_anisotropic" }
  1228. }
  1229. }
  1230. ndefined_SKYDOME = {
  1231. defined_DIFFUSE_MAP = {
  1232. diffuse_map = { sampler_states = "wrap_anisotropic_srgb" }
  1233. }
  1234. }
  1235.  
  1236. defined_SEMI_TRANSPARENCY_RESOLVE = {
  1237. light_accumulation = { sampler_states = "clamp_point" }
  1238. }
  1239. defined_SOFT_ALPHA_TEST_TANGENT = {
  1240. light_accumulation = { sampler_states = "clamp_linear" }
  1241. }
  1242. defined_CUBE_ENVIRONMENT_MAPPING = {
  1243. defined_CUBE_FROM_SHADING_ENV = {
  1244. shading_environment_reflection_map = { sampler_states = "clamp_anisotropic" }
  1245. }
  1246. ndefined_CUBE_FROM_SHADING_ENV = {
  1247. defined_CUBE_AS_RGBM = {
  1248. reflection_map = { sampler_states = "clamp_anisotropic" }
  1249. }
  1250. ndefined_CUBE_AS_RGBM = {
  1251. reflection_map = { sampler_states = "clamp_anisotropic_srgb" }
  1252. }
  1253. }
  1254.  
  1255. albedo = { sampler_states = "clamp_point" }
  1256. normal = { sampler_states = "clamp_point" }
  1257. mask = { sampler_states = "clamp_point" }
  1258. }
  1259.  
  1260. // Emissive pass is currently only used on X360 where all self illumination/emissive is
  1261. // rendered as a separate pass to reduce MRT memory footprint on X360 during G-buffer population
  1262. defined_EMISSIVE_PASS = {
  1263. defined_SELF_ILLUMINATION_MAP = {
  1264. self_illumination_map = { sampler_states = "wrap_anisotropic_srgb" }
  1265. }
  1266. }
  1267. }
  1268.  
  1269. instance_data = {
  1270. defined_INSTANCED = {
  1271. world = { type = "matrix4x4" }
  1272. }
  1273. }
  1274.  
  1275. code="""
  1276. #if defined(DIFFUSE_MAP) || defined(SELF_ILLUMINATION_MAP)
  1277. #define UV0
  1278. #endif
  1279.  
  1280. sampler2D light_accumulation;
  1281. #if defined(DIFFUSE_MAP)
  1282. sampler2D diffuse_map; // exports={ name="Diffuse Map" type="resource" }
  1283. #endif
  1284.  
  1285. #if defined(EMISSIVE_PASS) && defined(SELF_ILLUMINATION_MAP)
  1286. sampler2D self_illumination_map; // exports={ name="Self Illumination Map" type="resource" sort_tag="5_SELF_ILLUMINATION" }
  1287. #endif
  1288.  
  1289. #if defined(CUBE_ENVIRONMENT_MAPPING)
  1290. #if defined(CUBE_FROM_SHADING_ENV)
  1291. samplerCUBE shading_environment_reflection_map;
  1292. #else
  1293. samplerCUBE reflection_map; // exports={ name="Reflection Map" type="resource" }
  1294. #endif
  1295. sampler2D normal;
  1296. sampler2D albedo;
  1297. sampler2D mask;
  1298. #endif
  1299.  
  1300. #if defined(VEGETATION_BENDING) || defined(CUBE_ENVIRONMENT_MAPPING) || defined(INSTANCED)
  1301. #define NEEDS_WORLD_SPACE
  1302. #endif
  1303.  
  1304. struct VS_INPUT {
  1305. float4 position : POSITION;
  1306. SKIN_INPUT
  1307. #if defined(UV0)
  1308. float2 uv : TEXCOORD0;
  1309.  
  1310. #if defined(EMISSIVE_PASS)
  1311. #if defined(SELF_ILLUMINATION_MAP_UNIQUE_UV)
  1312. float2 vs_self_illumination_uv : TEXCOORD2;
  1313. #else
  1314. #define vs_self_illumination_uv uv
  1315. #endif
  1316. #endif
  1317. #endif
  1318.  
  1319. #if defined(VEGETATION_BENDING)
  1320. float4 color : COLOR0;
  1321. float3 normal : NORMAL;
  1322. #endif
  1323. #if defined(SOFT_ALPHA_TEST_TANGENT)
  1324. float3 tangent : TANGENT;
  1325. #endif
  1326. };
  1327.  
  1328. struct PS_INPUT {
  1329. float4 position : SV_POSITION;
  1330. #if defined(UV0)
  1331. float2 uv : TEXCOORD0;
  1332. #endif
  1333. #if defined(CUBE_ENVIRONMENT_MAPPING)
  1334. float3 camera_vector : TEXCOORD1;
  1335. #endif
  1336. #if defined(SOFT_ALPHA_TEST_TANGENT)
  1337. float3 tangent : TEXCOORD2;
  1338. #endif
  1339. #if defined(EMISSIVE_PASS)
  1340. #if defined(SELF_ILLUMINATION_MAP)
  1341. float2 self_illumination_uv : TEXCOORD3;
  1342. #endif
  1343. #endif
  1344. };
  1345.  
  1346. CBUFFER_START(c0)
  1347. #ifdef CAMERA_LOCK_XY
  1348. float4x4 world;
  1349. float4x4 view;
  1350. float4x4 proj;
  1351. #elif defined(NEEDS_WORLD_SPACE)
  1352. float4x4 world;
  1353. float4x4 view_proj;
  1354. #endif
  1355. float4x4 world_view_proj;
  1356. #ifdef SKYDOME
  1357. float intensity; // exports={ name="Skydome Intensity Multiplier" type="scalar" value=1.0 min=0.0 max=10.0 step=0.1 }
  1358. #endif
  1359. #ifdef SEMI_TRANSPARENCY_RESOLVE
  1360. float transparency; // exports={ name="Transparency" type="scalar" value=0.5 min=0.0 max=1 step=0.001 }
  1361. #endif
  1362. #if defined(CUBE_ENVIRONMENT_MAPPING)
  1363. float cube_environment_intensity_sun;
  1364. float cube_environment_intensity_shadow;
  1365. float3 sun_direction;
  1366. #endif
  1367.  
  1368. #if defined(INSTANCED) && defined(GL2)
  1369. float4 instance_buffer[100];
  1370. #endif
  1371.  
  1372. #if defined(EMISSIVE_PASS)
  1373. #ifdef SELF_ILLUMINATION_MAP
  1374. float self_illumination_multiplier; // exports={ name="Self Illumination Multiplier" type="scalar" value=1.0 min=0.0 max=10.0 step=0.01 sort_tag="5_SELF_ILLUMINATION1" }
  1375. float emissive_material_intensity;
  1376. #endif
  1377.  
  1378. #if defined(MATERIAL_TINT_RGB) && defined(SELF_ILLUMINATION_TINT_MATERIAL)
  1379. float3 tint_rgb;
  1380. #endif
  1381. #endif
  1382. CBUFFER_END
  1383.  
  1384. #if defined(INSTANCED) && defined(D3D11)
  1385. Buffer<float4> idata;
  1386. float ioffset;
  1387. #endif
  1388.  
  1389. PS_INPUT vs_main(VS_INPUT input
  1390. #if defined(INSTANCED) && (defined(D3D11) || defined(GL2))
  1391. , uint instance_id : SV_InstanceId
  1392. #endif
  1393. )
  1394. {
  1395. PS_INPUT o;
  1396.  
  1397. float4 position;
  1398. #ifdef SKINNED
  1399. position = float4(skin_point(input.position, input.blendindices, input.blendweights), 1);
  1400. #else
  1401. position = input.position;
  1402. #endif
  1403.  
  1404. #if defined(SOFT_ALPHA_TEST_TANGENT)
  1405. #ifdef SKINNED
  1406. float3 tangent = skin_vector(input.tangent, input.blendindices, input.blendweights);
  1407. #else
  1408. float3 tangent = input.tangent;
  1409. #endif
  1410. o.tangent = mul(tangent, (float3x3)world_view_proj);
  1411. #endif
  1412.  
  1413. #if defined(INSTANCED) && defined(D3D11)
  1414. uint offset = (uint)ioffset;
  1415. world[0] = idata.Load(offset + (instance_id*IDATA_STRIDE + IDATA_world + 0));
  1416. world[1] = idata.Load(offset + (instance_id*IDATA_STRIDE + IDATA_world + 1));
  1417. world[2] = idata.Load(offset + (instance_id*IDATA_STRIDE + IDATA_world + 2));
  1418. world[3] = idata.Load(offset + (instance_id*IDATA_STRIDE + IDATA_world + 3));
  1419. #endif
  1420.  
  1421. #if defined(INSTANCED) && defined(GL2)
  1422. world = float4x4(instance_buffer[instance_id*IDATA_STRIDE + IDATA_world + 0],
  1423. instance_buffer[instance_id*IDATA_STRIDE + IDATA_world + 1],
  1424. instance_buffer[instance_id*IDATA_STRIDE + IDATA_world + 2],
  1425. instance_buffer[instance_id*IDATA_STRIDE + IDATA_world + 3]);
  1426. #endif
  1427.  
  1428. float4 p;
  1429. #if defined(NEEDS_WORLD_SPACE)
  1430. float4 wp = mul(position, world);
  1431. #if defined(VEGETATION_BENDING)
  1432. float3 op = world._m30_m31_m32;
  1433. float3 normal;
  1434. #ifdef SKINNED
  1435. normal = skin_vector(input.normal, input.blendindices, input.blendweights);
  1436. #else
  1437. normal = input.normal;
  1438. #endif
  1439. float3 wnormal = mul(normal, (float3x3)world);
  1440. wp = vegetation_bending(op, wp, wnormal, input.color, input.position); //TODO: decode_vertex_color(input.color);
  1441. #endif
  1442. #if defined(CAMERA_LOCK_XY)
  1443. #ifdef CAMERA_LOCK_Z
  1444. view._m30_m31_m32 = float3(0,0,0);
  1445. #else
  1446. view._m30_m31 = float2(0,0);
  1447. #endif
  1448. p = mul(mul(float4(wp,1),view), proj);
  1449. #else
  1450. #if defined(CUBE_ENVIRONMENT_MAPPING) && !defined(VEGETATION_BENDING) && !defined(INSTANCED)
  1451. p = mul(position, world_view_proj);
  1452. #else
  1453. p = mul(wp, view_proj);
  1454. #endif
  1455. #endif
  1456. #else
  1457. #if defined(CAMERA_LOCK_XY)
  1458. float3 wp = mul(position, world);
  1459. #ifdef CAMERA_LOCK_Z
  1460. view._m30_m31_m32 = float3(0,0,0);
  1461. #else
  1462. view._m30_m31 = float2(0,0);
  1463. #endif
  1464. p = mul(mul(float4(wp,1),view), proj);
  1465. #else
  1466. p = mul(position, world_view_proj);
  1467. #endif
  1468. #endif
  1469.  
  1470. o.position = p;
  1471.  
  1472. #if defined(PROJECT_TO_FAR_PLANE)
  1473. o.position.z = o.position.w;
  1474. #endif
  1475.  
  1476. #if defined(UV0)
  1477. o.uv = input.uv;
  1478. #endif
  1479.  
  1480. #if defined(CUBE_ENVIRONMENT_MAPPING)
  1481. o.camera_vector = normalize(camera_pos - wp);
  1482. #endif
  1483.  
  1484. #if defined(EMISSIVE_PASS) && defined(SELF_ILLUMINATION_MAP)
  1485. o.self_illumination_uv = self_illumination_uv_modifier(input.vs_self_illumination_uv);
  1486. #endif
  1487.  
  1488. return o;
  1489. }
  1490.  
  1491. half4 ps_main(PS_INPUT input
  1492. #if defined(SEMI_TRANSPARENCY_RESOLVE) || defined(CUBE_ENVIRONMENT_MAPPING) || defined(SOFT_ALPHA_TEST_TANGENT)
  1493. #if defined(GCM)
  1494. , float4 wpos : WPOS
  1495. #elif defined(X360) || defined(GL2)
  1496. , float4 wpos : VPOS
  1497. #endif
  1498. #endif
  1499. ) : SV_TARGET0
  1500. {
  1501. #ifdef SEMI_TRANSPARENCY_RESOLVE
  1502. #if defined(GCM) || defined(X360) || defined(GL2)
  1503. half2 screen_uv = wpos.xy / back_buffer_size;
  1504. #else
  1505. half2 screen_uv = input.position.xy / back_buffer_size;
  1506. #endif
  1507.  
  1508. float4 cross_uv = half4(1.0, 0.0, 0.0, 1.0) / back_buffer_size.xyxy;
  1509. float4 center = tex2D(light_accumulation, screen_uv);
  1510. float4 corners = (
  1511. tex2D(light_accumulation, screen_uv + cross_uv.xy) +
  1512. tex2D(light_accumulation, screen_uv - cross_uv.xy) +
  1513. tex2D(light_accumulation, screen_uv + cross_uv.zw) +
  1514. tex2D(light_accumulation, screen_uv - cross_uv.zw) ) * 0.25;
  1515.  
  1516. #ifdef DIFFUSE_MAP
  1517. half4 albedo = tex2D(diffuse_map, input.uv);
  1518. #else
  1519. half4 albedo = float4(0.6, 0.6, 0.6, 1);
  1520. #endif
  1521.  
  1522. #if defined(GCM) || defined(X360) || defined(GL2)
  1523. int2 pos = int2(wpos.x, wpos.y);
  1524. #else
  1525. int2 pos = input.position.xy;
  1526. #endif
  1527. int idx = (pos.x + pos.y) % 2;
  1528.  
  1529. if (idx == 0)
  1530. return lerp(center, corners*albedo, transparency * albedo.a);
  1531. else
  1532. return lerp(corners, center*albedo, transparency * albedo.a);
  1533. #elif defined(SOFT_ALPHA_TEST_TANGENT)
  1534. #if defined(GCM) || defined(X360) || defined(GL2)
  1535. half2 screen_uv = wpos.xy / back_buffer_size;
  1536. #else
  1537. half2 screen_uv = input.position.xy / back_buffer_size;
  1538. #endif
  1539.  
  1540. float2 streak_dir = normalize(input.tangent.xy) / back_buffer_size.xy;
  1541.  
  1542. float4 center = tex2D(light_accumulation, screen_uv);
  1543. float4 streak_blur = (
  1544. tex2D(light_accumulation, screen_uv + streak_dir.xy) +
  1545. tex2D(light_accumulation, screen_uv + streak_dir.xy*2) +
  1546. tex2D(light_accumulation, screen_uv - streak_dir.xy) +
  1547. tex2D(light_accumulation, screen_uv - streak_dir.xy*2) ) * 0.25;
  1548.  
  1549. float a = tex2D(diffuse_map, input.uv).a;
  1550. return lerp(center, streak_blur, a);
  1551. #else
  1552. half4 c = half4(0,0,0,0);
  1553. #if defined(CUBE_ENVIRONMENT_MAPPING)
  1554. #if defined(GCM) || defined(X360) || defined(GL2)
  1555. half2 screen_uv = wpos.xy / back_buffer_size;
  1556. #else
  1557. half2 screen_uv = input.position.xy / back_buffer_size;
  1558. #endif
  1559.  
  1560. half4 normal_glossiness = tex2D(normal, screen_uv);
  1561. half specular_mask = gbuffer_decode_specular_mask(tex2D(albedo, screen_uv));
  1562. half3 wn = normalize(gbuffer_decode_normal(normal_glossiness));
  1563.  
  1564. half3 e = normalize(input.camera_vector);
  1565. half3 reflection = reflect(e, wn);
  1566.  
  1567. // TODO: need to feed number of mip-levels to shader
  1568. #if defined(CUBE_FROM_SHADING_ENV)
  1569. half4 cube = texCUBElod(shading_environment_reflection_map, half4(reflection, (1.0 - normal_glossiness.a) * 8));
  1570. #else
  1571. half4 cube = texCUBElod(reflection_map, half4(reflection, (1.0 - normal_glossiness.a) * 8));
  1572. #endif
  1573. #ifdef CUBE_AS_RGBM
  1574. cube.rgb = rgbm_decode(cube);
  1575. #endif
  1576.  
  1577. half3 s_dir = normalize(-sun_direction);
  1578.  
  1579. half4 gbuffer_mask = tex2D(mask, screen_uv);
  1580. half2 shadow_ao_mask = gbuffer_mask.ra;
  1581. half cube_intensity = lerp(cube_environment_intensity_shadow * shadow_ao_mask.g, cube_environment_intensity_sun, shadow_ao_mask.r * saturate(dot(s_dir, wn)));
  1582.  
  1583. half material_idx = gbuffer_mask.g;
  1584. half4 specular_col = (material_idx >= COLORED_SPECULAR_MATERIAL) ? half4(gbuffer_mask.gb * gbuffer_mask.gb, specular_mask, 1) : specular_mask.rrrr;
  1585.  
  1586. c += cube * specular_col * cube_intensity;
  1587. #endif
  1588.  
  1589. #if defined(EMISSIVE_PASS)
  1590. #if defined(SELF_ILLUMINATION_MAP)
  1591. half4 il = tex2D(self_illumination_map, input.self_illumination_uv);
  1592. #if defined(MATERIAL_TINT_RGB) && defined(SELF_ILLUMINATION_TINT_MATERIAL)
  1593. il.rgb *= tint_rgb;
  1594. #endif
  1595.  
  1596. il.rgb *= self_illumination_multiplier * emissive_material_intensity;
  1597. c += il;
  1598. #endif
  1599. #endif
  1600.  
  1601. #if !defined(CUBE_ENVIRONMENT_MAPPING) && !defined(CUBE_ENVIRONMENT_MAPPING)
  1602. #if defined(DIFFUSE_MAP)
  1603. c = tex2D(diffuse_map, input.uv);
  1604. #endif
  1605.  
  1606. #if defined(SKYDOME)
  1607. #if defined(DIFFUSE_AS_RGBM)
  1608. c.rgb = rgbm_decode(c);
  1609. #else
  1610. c.rgb *= intensity;
  1611. #endif
  1612. #endif
  1613. #endif
  1614.  
  1615. return c;
  1616. #endif
  1617. }
  1618. """
  1619. }
  1620.  
  1621. water = {
  1622. includes = [ "common", "gbuffer_access", "fog" ]
  1623.  
  1624. samplers = {
  1625. normal_map = { sampler_states = "wrap_anisotropic" }
  1626. defined_X360 = {
  1627. blend_normal_map = { sampler_states = "wrap_point" }
  1628. }
  1629. ndefined_X360 = {
  1630. blend_normal_map = { sampler_states = "wrap_anisotropic" }
  1631. }
  1632. light_accumulation = { sampler_states = "clamp_point" }
  1633. mask = { sampler_states = "clamp_point" }
  1634. depth = { sampler_states = "clamp_point" }
  1635. defined_CUBE_ENVIRONMENT_MAPPING = {
  1636. defined_CUBE_FROM_SHADING_ENV = {
  1637. shading_environment_reflection_map = { sampler_states = "clamp_anisotropic" }
  1638. }
  1639. ndefined_CUBE_FROM_SHADING_ENV = {
  1640. defined_CUBE_AS_RGBM = {
  1641. reflection_map = { sampler_states = "clamp_anisotropic" }
  1642. }
  1643. ndefined_CUBE_AS_RGBM = {
  1644. reflection_map = { sampler_states = "clamp_anisotropic_srgb" }
  1645. }
  1646. }
  1647. }
  1648.  
  1649. defined_FOAM = {
  1650. diffuse_map = { sampler_states = "wrap_anisotropic" }
  1651. }
  1652. }
  1653.  
  1654. code="""
  1655. #ifndef MASK
  1656. sampler2D normal_map; // exports={ name="Normal Map" type="resource" }
  1657. sampler2D blend_normal_map; // exports={ name="Perlin Noise Map" type="resource" }
  1658. sampler2D light_accumulation;
  1659. sampler2D depth;
  1660. sampler2D mask;
  1661. #if defined(CUBE_ENVIRONMENT_MAPPING)
  1662. #if defined(CUBE_FROM_SHADING_ENV)
  1663. samplerCUBE shading_environment_reflection_map;
  1664. #else
  1665. samplerCUBE reflection_map; // exports={ name="Reflection Map" type="resource" }
  1666. #endif
  1667. #endif
  1668. #if defined(FOAM)
  1669. sampler2D diffuse_map; // exports={ name="Foam Map" type="resource" }
  1670. #endif
  1671. #endif
  1672.  
  1673. struct VS_INPUT {
  1674. float4 position : POSITION;
  1675. #ifndef MASK
  1676. float3 normal : NORMAL0;
  1677. #ifndef WORLD_XY_AS_UV
  1678. float3 tangent : TANGENT;
  1679. float3 binormal : BINORMAL;
  1680. float2 uv : TEXCOORD0;
  1681. #endif
  1682. #endif
  1683. };
  1684.  
  1685. // TEXCOORD6 is defined to ATTR4 for input to Vertex Programs to avoid conflicting with TANGENT,
  1686. // ATTR not allowed to be used in output semantic from VP. Need to come up with a cleaner solution for this.
  1687. #if defined(GCM) && defined(TEXCOORD6)
  1688. #undef TEXCOORD6
  1689. #endif
  1690.  
  1691. struct PS_INPUT {
  1692. float4 position : SV_POSITION;
  1693. #ifndef MASK
  1694. float4 uv : TEXCOORD0;
  1695. float3 tsm0 : TEXCOORD1;
  1696. float3 tsm1 : TEXCOORD2;
  1697. float3 tsm2 : TEXCOORD3;
  1698. float4 wp : TEXCOORD4;
  1699. float4 w : TEXCOORD5;
  1700.  
  1701. #ifdef FOAM
  1702. #ifdef BLEND_TO_PERLIN_NOISE
  1703. float4 perlin_uv : TEXCOORD6;
  1704. #define foam_uv perlin_uv.zw
  1705. #else
  1706. float2 foam_uv : TEXCOORD6;
  1707. #endif
  1708. #elif defined(BLEND_TO_PERLIN_NOISE)
  1709. float2 perlin_uv : TEXCOORD6;
  1710. #endif
  1711. #endif
  1712. };
  1713.  
  1714. #ifdef MASK
  1715. CBUFFER_START(c_mask)
  1716. float4x4 world;
  1717. float4x4 view_proj;
  1718. CBUFFER_END
  1719. #else
  1720. CBUFFER_START(c0)
  1721. float4x4 world;
  1722. float4x4 view_proj;
  1723. #ifdef WORLD_XY_AS_UV
  1724. float2 layer0_normal_tile_size; // exports={ name="Layer 0 Normal Map Tile" type="vector2" value=[2.0 2.0] min=[0 0] max=[30 30] step=[0.01 0.01]}
  1725. float2 layer1_normal_tile_size; // exports={ name="Layer 1 Normal Map Tile" type="vector2" value=[1.0 1.0] min=[0 0] max=[30 30] step=[0.01 0.01]}
  1726. #ifdef BLEND_TO_PERLIN_NOISE
  1727. float2 perlin_noise_tile_size; // exports={ name="Perlin Normal Map Tile" type="vector2" value=[1.0 1.0] min=[0 0] max=[30 30] step=[0.01 0.01]}
  1728. #endif
  1729. #ifdef FOAM
  1730. float2 foam_tile_size; // exports={ name="Foam Map Tile" type="vector2" value=[2.0 2.0] min=[0 0] max=[30 30] step=[0.01 0.01]}
  1731. #endif
  1732. #else
  1733. float2 layer0_normal_tile_scale; // exports={ name="Layer 0 Normal Map Scale" type="vector2" value=[2.0 2.0] min=[0 0] max=[30 30] step=[0.01 0.01]}
  1734. float2 layer1_normal_tile_scale; // exports={ name="Layer 1 Normal Map Scale" type="vector2" value=[1.0 1.0] min=[0 0] max=[30 30] step=[0.01 0.01]}
  1735. #ifdef BLEND_TO_PERLIN_NOISE
  1736. float2 perlin_noise_tile_size; // exports={ name="Perlin Normal Map Scale" type="vector2" value=[1.0 1.0] min=[0 0] max=[30 30] step=[0.01 0.01]}
  1737. #endif
  1738. #ifdef FOAM
  1739. float2 foam_tile_scale; // exports={ name="Foam Map Scale" type="vector2" value=[2.0 2.0] min=[0 0] max=[30 30] step=[0.01 0.01]}
  1740. #endif
  1741. #endif
  1742. float2 layer0_normal_tile_scroll_speed; // exports={ name="Layer 0 Normal Map Scroll Speed" type="vector2" value=[0.1 0.1] min=[-2 -2] max=[2 2] step=[0.005 0.005]}
  1743. float2 layer1_normal_tile_scroll_speed; // exports={ name="Layer 1 Normal Map Scroll Speed" type="vector2" value=[0.1 0.1] min=[-2 -2] max=[2 2] step=[0.005 0.005]}
  1744. #ifdef BLEND_TO_PERLIN_NOISE
  1745. float2 perlin_noise_tile_scroll_speed; // exports={ name="Perlin Noise Scroll Speed" type="vector2" value=[0.1 0.1] min=[-2 -2] max=[2 2] step=[0.005 0.005]}
  1746. float3 perlin_noise_octaves; // exports={ name="Perlin Noise Octaves" type="vector3" value=[1.12 0.59 0.23] min=[0 0 0] max=[2 2 2] step=[0.005 0.005 0.005]}
  1747. float3 perlin_noise_gradients; // exports={ name="Perlin Noise Gradients" type="vector3" value=[1.4 1.6 2.2] min=[0 0 0] max=[3 3 3] step=[0.005 0.005 0.005]}
  1748. float2 perlin_noise_blend; // exports = { name="Perlin Noise Blend Start/Distance" type="vector2" value=[80 150] min=[10 10] max=[1000 1000] step=[0.5 0.5]}
  1749. #endif
  1750. #ifdef FOAM
  1751. #ifdef FOAM
  1752. float2 foam_tile_scroll_speed; // exports={ name="Foam Map Scroll Speed" type="vector2" value=[0.1 0.1] min=[-2 -2] max=[2 2] step=[0.005 0.005]}
  1753. #endif
  1754. #endif
  1755. float2 fresnel_settings; // exports={ name="Fresnel Settings [bias, exp]" type="vector2" value=[0.1 3] min=[0 0] max=[1 10] step=[0.001 0.005]}
  1756. float refraction_amount; // exports={ name="Refraction Amount" type="scalar" value=0.01 min=0.0 max=1.0 step=0.001 }
  1757. float specular_mask; // exports={ name="Specular Mask" type="scalar" value=0.8 min=0.0 max=1.0 step=0.001 }
  1758. float glossiness; // exports={ name="Glossiness Amount" type="scalar" value=0.5 min=0.0 max=1.0 step=0.001 }
  1759. float normal_contrast; // exports={ name="Normal Contrast" type="scalar" value=1 min=0.0 max=1.0 step=0.001 }
  1760. float3 surface_albedo; // exports={ name="Surface Color" type="vector3" value=[0.3 0.3 0.8] min=[0 0 0] max=[1 1 1] step=[0.001 0.001 0.001]}
  1761. float3 ambient_top_color;
  1762. float3 ambient_bottom_color;
  1763. float ambient_camera_falloff;
  1764. #ifdef COLOR_EXTINCTION
  1765. float3 color_extinction; // exports={ name="RGB color extinction depth" type="vector3" value=[4.5 75 300] min=[0 0 0] max=[300 300 300] step=[0.2 0.2 0.2] }
  1766. float3 depth_color; // exports={ name="Deep Water Color" type="vector3" value=[0.1 0.1 0.4] min=[0 0 0] max=[4 4 4] step=[0.005 0.005 0.005] }
  1767. #endif
  1768. #ifdef GEOMETRY_FADE_OUT
  1769. float geometry_fade_out_distance; // exports={ name="Geometry Fade out Distance" type="scalar" value=0.2 min=0.01 max=0.8 step=0.005 }
  1770. #endif
  1771. #if defined(CUBE_ENVIRONMENT_MAPPING)
  1772. float cube_environment_intensity_sun;
  1773. float cube_environment_intensity_shadow;
  1774. #endif
  1775. #if defined(FOAM)
  1776. float foam_fade_in; // exports={ name="Foam Fade in Depth" type="scalar" value=0.2 min=0.01 max=2.0 step=0.005 }
  1777. #endif
  1778. CBUFFER_END
  1779. #endif
  1780.  
  1781. PS_INPUT vs_main(VS_INPUT input) {
  1782. PS_INPUT o;
  1783. #ifdef MASK
  1784. float3 wp = mul(input.position, world);
  1785. o.position = mul(float4(wp,1), view_proj);
  1786. return o;
  1787. #else
  1788. float3 wp = mul(input.position, world);
  1789. o.wp.xyz = wp;
  1790. o.position = mul(float4(wp,1), view_proj);
  1791.  
  1792. #if defined(GL2)
  1793. #define layer0_scroll float2(layer0_normal_tile_scroll_speed.x, -layer0_normal_tile_scroll_speed.y)
  1794. #define layer1_scroll float2(layer1_normal_tile_scroll_speed.x, -layer1_normal_tile_scroll_speed.y)
  1795.  
  1796. #define foam_scroll float2(foam_tile_scroll_speed.x, -foam_tile_scroll_speed.y)
  1797. #else
  1798. #define layer0_scroll layer0_normal_tile_scroll_speed
  1799. #define layer1_scroll layer1_normal_tile_scroll_speed
  1800.  
  1801. #define foam_scroll foam_tile_scroll_speed
  1802. #endif
  1803.  
  1804. #ifdef WORLD_XY_AS_UV
  1805. o.uv = float4( (wp.xy / layer0_normal_tile_size) + time * layer0_scroll,
  1806. (wp.xy / layer1_normal_tile_size) + time * layer1_scroll);
  1807.  
  1808. tspace_transform_transpose(o.tsm0, o.tsm1, o.tsm2, float3(-1,0,0), float3(0,-1,0), input.normal, (float3x3)world);
  1809.  
  1810. #ifdef BLEND_TO_PERLIN_NOISE
  1811. o.perlin_uv.xy = (wp.xy / perlin_noise_tile_size);
  1812. #endif
  1813.  
  1814. #ifdef FOAM
  1815. o.foam_uv = float2((wp.xy / foam_tile_size) + time * foam_scroll);
  1816. #endif
  1817. #else
  1818. o.uv = float4( (input.uv * layer0_normal_tile_scale) + time * layer0_scroll,
  1819. (input.uv * layer1_normal_tile_scale) + time * layer1_scroll);
  1820.  
  1821. tspace_transform_transpose(o.tsm0, o.tsm1, o.tsm2, input.tangent, input.binormal, input.normal, (float3x3)world);
  1822.  
  1823. #ifdef BLEND_TO_PERLIN_NOISE
  1824. o.perlin_uv.xy = (wp.xy * perlin_noise_tile_size);
  1825. #endif
  1826.  
  1827. #ifdef FOAM
  1828. o.foam_uv = float2((input.uv * foam_tile_scale) + time * foam_scroll);
  1829. #endif
  1830. #endif
  1831.  
  1832.  
  1833. o.w = encode_world_pos(o.position, camera_unprojection);
  1834. o.wp.w = o.position.z + camera_near_far.x;
  1835. return o;
  1836. #endif
  1837. }
  1838.  
  1839. half fresnel(half n_dot_e, half bias, half power){
  1840. return saturate(bias + (1-bias) * pow(1-n_dot_e, power));
  1841. }
  1842.  
  1843. #ifdef MASK
  1844. float4 ps_main(PS_INPUT input) : SV_TARGET0 {
  1845. #ifdef ALWAYS
  1846. return float4(1,1,1,1);
  1847. #else
  1848. return float4(1,1,1,0);
  1849. #endif
  1850. }
  1851. #else
  1852. #define MAX_WATER_GLOSSINESS 1000
  1853.  
  1854. float4 ps_main(PS_INPUT input, float vface : VFACE
  1855. #if defined(GCM)
  1856. , float4 wpos : WPOS
  1857. #elif defined(X360) || defined(GL2)
  1858. , float4 wpos : VPOS
  1859. #endif
  1860. ) : SV_TARGET0
  1861. {
  1862. #if defined(GCM) || defined(X360) || defined(GL2)
  1863. half2 screen_uv = wpos.xy / back_buffer_size;
  1864. #else
  1865. half2 screen_uv = input.position.xy / back_buffer_size;
  1866. #endif
  1867.  
  1868. float3 view_vector = camera_world._m30_m31_m32 - input.wp;
  1869. half3 view_dir = normalize(view_vector);
  1870.  
  1871. #ifdef BLEND_TO_PERLIN_NOISE
  1872. half blend = saturate((length(view_vector.xy) - perlin_noise_blend.x) / perlin_noise_blend.y);
  1873. normal_contrast = lerp(1, normal_contrast, blend);
  1874.  
  1875. half2 perlin0_uv = blend > 0 ? input.perlin_uv.xy * perlin_noise_octaves.x + perlin_noise_tile_scroll_speed * time : 0;
  1876. half2 perlin1_uv = blend > 0 ? input.perlin_uv.xy * perlin_noise_octaves.y + perlin_noise_tile_scroll_speed * time : 0;
  1877. half2 perlin2_uv = blend > 0 ? input.perlin_uv.xy * perlin_noise_octaves.z + perlin_noise_tile_scroll_speed * time : 0;
  1878. half2 perlin0 = tex2D(blend_normal_map, perlin0_uv).xy;
  1879. half2 perlin1 = tex2D(blend_normal_map, perlin1_uv).xy;
  1880. half2 perlin2 = tex2D(blend_normal_map, perlin2_uv).xy;
  1881.  
  1882. half2 perlin = perlin0 * perlin_noise_gradients.x + perlin1 * perlin_noise_gradients.y + perlin2 * perlin_noise_gradients.z;
  1883.  
  1884. input.uv *= blend > 1 ? 0 : 1;
  1885. #endif
  1886.  
  1887. half2 tnormal_grad = decode_normal_grad(tex2D(normal_map, input.uv.xy)) + decode_normal_grad(tex2D(normal_map, input.uv.zw));
  1888.  
  1889. //half3 tnormal = normalize(half3(normal_contrast,normal_contrast,1) * (decode_normal_map(tex2D(normal_map, input.uv.xy)) + decode_normal_map(tex2D(normal_map, input.uv.zw))));
  1890. #ifdef BLEND_TO_PERLIN_NOISE
  1891. half3 tnormal = normalize(half3(normal_contrast * lerp(tnormal_grad, perlin, blend), 1));
  1892. #else
  1893. half3 tnormal = normalize(half3(normal_contrast * tnormal_grad, 1));
  1894. #endif
  1895.  
  1896. half3 wn = rotate_vector3(tnormal, input.tsm0, input.tsm1, input.tsm2);
  1897.  
  1898. //wn = vface < 0 ? -wn : wn;
  1899.  
  1900. // calc under water color
  1901. half2 refracted_uv = screen_uv + tnormal.xy * refraction_amount;
  1902. refracted_uv = lerp(refracted_uv, screen_uv, tex2D(light_accumulation, refracted_uv).a);
  1903. half3 under_water_color = tex2D(light_accumulation, refracted_uv).rgb;
  1904.  
  1905. // calc fresnel term
  1906. half n_dot_e = saturate(dot(wn, view_dir));
  1907. half f = fresnel(n_dot_e, fresnel_settings.x, fresnel_settings.y);
  1908.  
  1909. // color extinction
  1910. #ifdef COLOR_EXTINCTION
  1911. float d = gbuffer_decode_depth(tex2D(depth, refracted_uv));
  1912. float3 wp = decode_world_pos(input.w, d);
  1913. float water_depth = abs(wp.z - input.wp.z);
  1914. under_water_color = lerp(under_water_color, depth_color, saturate(water_depth / color_extinction));
  1915. #endif
  1916.  
  1917. #ifdef GEOMETRY_FADE_OUT
  1918. float fade_out_depth = gbuffer_decode_depth(tex2D(depth, screen_uv));
  1919. half op = saturate(abs(fade_out_depth - input.wp.w) / geometry_fade_out_distance);
  1920. #else
  1921. half op = 1;
  1922. #endif
  1923.  
  1924. #if defined(FOAM)
  1925. #if !defined(COLOR_EXTINCTION)
  1926. float d = gbuffer_decode_depth(tex2D(depth, refracted_uv));
  1927. float3 wp = decode_world_pos(input.w, d);
  1928. float water_depth = abs(wp.z - input.wp.z);
  1929. #endif
  1930.  
  1931. half foam_intensity = 1-saturate(water_depth / foam_fade_in);
  1932. half4 foam = tex2D(diffuse_map, input.foam_uv) * foam_intensity;
  1933. surface_albedo += foam.rgb;
  1934. #endif
  1935.  
  1936. // calc surface color
  1937. half3 s_dir = -sun_direction;
  1938. half a = saturate(dot(wn, s_dir));
  1939. #ifdef MASK_WITH_DEFERRED_SHADOW
  1940. half shadow = tex2D(mask, refracted_uv).r;
  1941. #else
  1942. half shadow = 1;
  1943. #endif
  1944.  
  1945. half3 ambient = lerp(ambient_bottom_color, ambient_top_color, wn.z*0.5+0.5);
  1946. ambient = lerp(ambient, ambient * (1-saturate(dot(view_dir, wn))), ambient_camera_falloff);
  1947. half3 sun = a * sun_color * shadow;
  1948. half3 surface_color = surface_albedo * ambient + surface_albedo * sun;
  1949. float gloss = glossiness * MAX_WATER_GLOSSINESS;
  1950. float specular_energy_conservation = (gloss + 8) / (8 * 3.14159);
  1951. half3 sun_h = normalize(view_dir + s_dir);
  1952. float s = specular_energy_conservation * pow(saturate(dot(sun_h, wn)), gloss) * specular_mask;
  1953. half3 spec_color = sun * s;
  1954. surface_color += spec_color;
  1955.  
  1956. #if defined(FOAM)
  1957. under_water_color += foam.rgb * sun;
  1958. #endif
  1959.  
  1960. #if defined(CUBE_ENVIRONMENT_MAPPING)
  1961. half3 reflection = reflect(view_dir, wn);
  1962. #if defined(CUBE_FROM_SHADING_ENV)
  1963. half4 cube = texCUBElod(shading_environment_reflection_map, half4(reflection, (1.0 - glossiness) * 8));
  1964. #else
  1965. half4 cube = texCUBElod(reflection_map, half4(reflection, (1.0 - glossiness) * 8));
  1966. #endif
  1967. #ifdef CUBE_AS_RGBM
  1968. cube.rgb = rgbm_decode(cube);
  1969. #endif
  1970. surface_color += cube * specular_mask * lerp(cube_environment_intensity_shadow, cube_environment_intensity_sun, a * shadow);
  1971. #endif
  1972.  
  1973. // lerp between them
  1974. half3 c = lerp(under_water_color, surface_color, f);
  1975.  
  1976. return apply_fog(float4(c, op), input.wp.xyz, input.wp.w);
  1977. }
  1978. #endif
  1979. """
  1980. }
  1981.  
  1982. fog_plane = {
  1983. includes = [ "common", "gbuffer_access" ]
  1984.  
  1985. samplers = {
  1986. depth = { sampler_states = "clamp_point" }
  1987. }
  1988.  
  1989. code="""
  1990. sampler2D depth;
  1991.  
  1992. struct VS_INPUT {
  1993. float4 position : POSITION;
  1994. float3 normal : NORMAL;
  1995. };
  1996.  
  1997. struct PS_INPUT {
  1998. float4 position : SV_POSITION;
  1999. float4 plane_eq : TEXCOORD0;
  2000. float4 w : TEXCOORD1;
  2001. };
  2002.  
  2003. CBUFFER_START(c0)
  2004. float4x4 world;
  2005. float4x4 view_proj;
  2006. float3 fog_color; // exports={ name="Fog Color" type="vector3" value=[0.5 0.5 0.5] min=[0 0 0] max=[8 8 8] step=[0.001 0.001 0.001] }
  2007. float fog_distance; // exports={ name="Fog Distance" type="scalar" value=10 min=0.01 max=200 step=0.01 }
  2008. CBUFFER_END
  2009.  
  2010. PS_INPUT vs_main(VS_INPUT input) {
  2011. PS_INPUT o;
  2012.  
  2013. float3 wp = mul(input.position, world);
  2014. o.position = mul(float4(wp,1), view_proj);
  2015.  
  2016. float3 wnormal = mul(input.normal, (float3x3)world);
  2017. o.plane_eq = float4(wnormal, dot(wnormal, wp));
  2018.  
  2019. o.w = encode_world_pos(o.position, camera_unprojection);
  2020. return o;
  2021. }
  2022.  
  2023. half4 ps_main(PS_INPUT input
  2024. #if defined(GCM)
  2025. , float4 wpos : WPOS
  2026. #elif defined(X360) || defined(GL2)
  2027. , float4 wpos : VPOS
  2028. #endif
  2029. ) : SV_TARGET0
  2030. {
  2031. #if defined(GCM) || defined(X360) || defined(GL2)
  2032. half2 screen_uv = wpos.xy / back_buffer_size;
  2033. #else
  2034. half2 screen_uv = input.position.xy / back_buffer_size;
  2035. #endif
  2036.  
  2037. float d = gbuffer_decode_depth(tex2D(depth, screen_uv));
  2038. float3 wp = decode_world_pos(input.w, d);
  2039.  
  2040. float distance_to_plane = abs(dot(wp, input.plane_eq.xyz) - input.plane_eq.w);
  2041.  
  2042. return half4(fog_color, saturate(distance_to_plane / fog_distance));
  2043. }
  2044. """
  2045. }
  2046.  
  2047. eye_highlight = {
  2048. includes = [ "common", "gbuffer_access", "skinning" ]
  2049.  
  2050. code="""
  2051. struct VS_INPUT {
  2052. float4 position : POSITION;
  2053. SKIN_INPUT
  2054. float3 normal : NORMAL;
  2055. };
  2056.  
  2057. struct PS_INPUT {
  2058. float4 position : SV_POSITION;
  2059. float3 normal : TEXCOORD0;
  2060. float3 view_vector : TEXCOORD1;
  2061. };
  2062.  
  2063. CBUFFER_START(c0)
  2064. float4x4 world;
  2065. float4x4 view_proj;
  2066. float3 sun_color;
  2067. float3 sun_direction;
  2068. float3 highlight_tint; // exports={ name="Tint" type="vector3" value=[1.0 1.0 1.0] min=[0 0 0] max=[1 1 1] step=[0.001 0.001 0.001] }
  2069. float2 highlight_offset; // exports={ name="Offset" type="vector2" value=[0.0 0.0] min=[-1 -1] max=[1 1] step=[0.001 0.001] }
  2070. float highlight_glossiness; // exports={ name="Glossiness" type="scalar" value=250.0 min=0.1 max=5000 step=1 }
  2071. CBUFFER_END
  2072.  
  2073. PS_INPUT vs_main(VS_INPUT input) {
  2074. PS_INPUT o;
  2075.  
  2076. float4 position;
  2077. float3 normal;
  2078. #ifdef SKINNED
  2079. position = float4(skin_point(input.position, input.blendindices, input.blendweights), 1);
  2080. normal = skin_vector(input.normal, input.blendindices, input.blendweights);
  2081. #else
  2082. position = input.position;
  2083. normal = input.normal;
  2084. #endif
  2085.  
  2086. float3 wp = mul(position, world);
  2087. o.position = mul(float4(wp,1), view_proj);
  2088. o.normal = mul(normal, (float3x3)world);
  2089.  
  2090. float3 cp = camera_pos + camera_world._m00_m01_m02 * highlight_offset.x + camera_world._m20_m21_m22 * highlight_offset.y;
  2091. o.view_vector = normalize(cp - wp);
  2092.  
  2093. return o;
  2094. }
  2095.  
  2096. half4 ps_main(PS_INPUT input) : SV_TARGET0
  2097. {
  2098. float3 view_vector = normalize(input.view_vector);
  2099. float3 wn = normalize(input.normal);
  2100. //float3 ldir = normalize(lerp(sun_direction, view_vector, 0.5));
  2101. float3 ldir = normalize(-sun_direction);
  2102. float3 h = normalize(ldir + view_vector);
  2103. float a = saturate(dot(h, wn));
  2104. //float a = saturate(dot(view_vector, wn));
  2105. float glossiness = highlight_glossiness;
  2106. float specular_energy_conservation = (glossiness + 8) / (8 * 3.14159);
  2107. float3 c = highlight_tint * sun_color * pow(a, glossiness) * specular_energy_conservation;
  2108.  
  2109. return float4(c,1);
  2110. }
  2111. """
  2112. }
  2113.  
  2114. pvs_bake = {
  2115. includes = [ "common", "gbuffer_access", "skinning", "vegetation_bending" ]
  2116.  
  2117. samplers = {
  2118. defined_ONE_BIT_ALPHA = {
  2119. defined_ONE_BIT_ALPHA_FROM_MATERIAL_B = {
  2120. material_map = { sampler_states = "wrap_linear_srgb" }
  2121. }
  2122. ndefined_ONE_BIT_ALPHA_FROM_MATERIAL_B = {
  2123. diffuse_map = { sampler_states = "wrap_linear_srgb" }
  2124. }
  2125. }
  2126. }
  2127.  
  2128. code = """
  2129. #if defined(ONE_BIT_ALPHA)
  2130. #define HAS_UV
  2131. #endif
  2132.  
  2133. #if defined(ONE_BIT_ALPHA)
  2134. #if defined(ONE_BIT_ALPHA_FROM_MATERIAL_B)
  2135. sampler2D material_map;
  2136. #else
  2137. sampler2D diffuse_map;
  2138. #endif
  2139. #endif
  2140.  
  2141. struct VS_INPUT {
  2142. float4 position : POSITION;
  2143. #if defined(HAS_UV)
  2144. float2 uv : TEXCOORD0;
  2145. #endif
  2146. };
  2147.  
  2148. struct PS_INPUT {
  2149. float4 position : SV_POSITION;
  2150. #if defined(HAS_UV)
  2151. float2 uv : TEXCOORD0;
  2152. #endif
  2153. };
  2154.  
  2155. CBUFFER_START(c0)
  2156. #ifdef CAMERA_LOCK_XY
  2157. float4x4 world;
  2158. float4x4 view;
  2159. float4x4 proj;
  2160. #endif
  2161. float4x4 world_view_proj;
  2162. float primitive_offset;
  2163. float mesh_id;
  2164. #if defined(ONE_BIT_ALPHA) && defined(EXTERNAL_ALPHA_REF)
  2165. float external_alpha_ref;
  2166. #endif
  2167. CBUFFER_END
  2168.  
  2169. PS_INPUT vs_main(VS_INPUT input) {
  2170. PS_INPUT o;
  2171. float4 position = input.position;
  2172. float4 p;
  2173. #if defined(CAMERA_LOCK_XY)
  2174. float3 wp = mul(position, world);
  2175. #ifdef CAMERA_LOCK_Z
  2176. view._m30_m31_m32 = float3(0,0,0);
  2177. #else
  2178. view._m30_m31 = float2(0,0);
  2179. #endif
  2180. p = mul(mul(float4(wp,1),view), proj);
  2181. #else
  2182. p = mul(position, world_view_proj);
  2183. #endif
  2184.  
  2185. o.position = p;
  2186. #ifdef PROJECT_TO_FAR_PLANE
  2187. o.position.z = o.position.w;
  2188. #endif
  2189.  
  2190. #ifdef HAS_UV
  2191. o.uv = input.uv;
  2192. #endif
  2193.  
  2194. return o;
  2195. }
  2196.  
  2197. float4 ps_main(PS_INPUT input, uint primitive_id : SV_PrimitiveID) : SV_TARGET0
  2198. {
  2199. #if defined(ONE_BIT_ALPHA)
  2200. #if defined(EXTERNAL_ALPHA_REF)
  2201. half alpha_ref = external_alpha_ref;
  2202. #else
  2203. half alpha_ref = ONE_BIT_ALPHA_REF;
  2204. #endif
  2205.  
  2206. #if defined(ONE_BIT_ALPHA_FROM_MATERIAL_B)
  2207. one_bit_alpha_mask(tex2D(material_map, input.uv).b, alpha_ref);
  2208. #else
  2209. one_bit_alpha_mask(tex2D(diffuse_map, input.uv).a, alpha_ref);
  2210. #endif
  2211. #endif
  2212.  
  2213. return float4(mesh_id, primitive_offset + primitive_id, 0, 1);
  2214. }
  2215. """
  2216. }
  2217.  
  2218. ao_bake = {
  2219. includes = [ "common", "skinning", "vegetation_bending" ]
  2220.  
  2221. samplers = {
  2222. defined_DIFFUSE_MAP = {
  2223. diffuse_map = { sampler_states = "wrap_linear" }
  2224. }
  2225. defined_ONE_BIT_ALPHA = {
  2226. defined_ONE_BIT_ALPHA_FROM_MATERIAL_B = {
  2227. material_map = { sampler_states = "wrap_linear_srgb" }
  2228. }
  2229. ndefined_ONE_BIT_ALPHA_FROM_MATERIAL_B = {
  2230. diffuse_map = { sampler_states = "wrap_linear_srgb" }
  2231. }
  2232. }
  2233. }
  2234.  
  2235. instance_data = {
  2236. defined_INSTANCED = {
  2237. world = { type = "matrix4x4" }
  2238. }
  2239. }
  2240.  
  2241. code="""
  2242. #if defined(VEGETATION_BENDING) || defined(INSTANCED) || defined(CAMERA_LOCK_XY)
  2243. #define NEEDS_WORLD_SPACE
  2244. #endif
  2245.  
  2246. #if defined(ONE_BIT_ALPHA) //|| defined(DIFFUSE_MAP)
  2247. #define HAS_UV
  2248. #endif
  2249.  
  2250. struct VS_INPUT {
  2251. float4 position : POSITION;
  2252. #if defined(HAS_UV)
  2253. float2 uv : TEXCOORD0;
  2254. #endif
  2255. SKIN_INPUT
  2256. #if defined(VEGETATION_BENDING)
  2257. float4 color : COLOR0;
  2258. float3 normal : NORMAL;
  2259. #endif
  2260. };
  2261. /*
  2262. struct PS_INPUT {
  2263. float4 position : SV_POSITION;
  2264. uint rt_index : SV_RenderTargetArrayIndex;
  2265. };
  2266. */
  2267.  
  2268. struct PS_INPUT {
  2269. float4 position : SV_POSITION;
  2270. #if defined(HAS_UV)
  2271. float2 uv : TEXCOORD0;
  2272. #endif
  2273. #if defined(NEEDS_WORLD_SPACE)
  2274. float3 wp : TEXCOORD1;
  2275. #endif
  2276. };
  2277.  
  2278. CBUFFER_START(c0)
  2279. #if defined(NEEDS_WORLD_SPACE)
  2280. float4x4 world;
  2281. float4x4 view_proj;
  2282. #if defined(CAMERA_LOCK_XY)
  2283. float4x4 view;
  2284. float4x4 proj;
  2285. #endif
  2286. #else
  2287. float4x4 world_view_proj;
  2288. #endif
  2289. #if defined(ONE_BIT_ALPHA) && defined(EXTERNAL_ALPHA_REF)
  2290. float external_alpha_ref;
  2291. #endif
  2292. float3 sun_direction;
  2293. //float4x4 patch_view;
  2294. CBUFFER_END
  2295.  
  2296. #if defined(DIFFUSE_MAP)
  2297. sampler2D diffuse_map;
  2298. #endif
  2299.  
  2300. #if defined(ONE_BIT_ALPHA)
  2301. #if defined(ONE_BIT_ALPHA_FROM_MATERIAL_B)
  2302. sampler2D material_map;
  2303. #elif !defined(DIFFUSE_MAP)
  2304. sampler2D diffuse_map;
  2305. #endif
  2306. #endif
  2307.  
  2308. #if defined(INSTANCED) && defined(D3D11)
  2309. Buffer<float4> idata;
  2310. float ioffset;
  2311. #endif
  2312.  
  2313. PS_INPUT vs_main(VS_INPUT input
  2314. #if defined(INSTANCED) && defined(D3D11)
  2315. , uint instance_id : SV_InstanceId
  2316. #endif
  2317. )
  2318. {
  2319. PS_INPUT o;
  2320.  
  2321. float4 position;
  2322. #ifdef SKINNED
  2323. position = float4(skin_point(input.position, input.blendindices, input.blendweights), 1);
  2324. #else
  2325. position = input.position;
  2326. #endif
  2327.  
  2328. #if defined(INSTANCED) && defined(D3D11)
  2329. uint offset = (uint)ioffset;
  2330. world[0] = idata.Load(offset + (instance_id*IDATA_STRIDE + IDATA_world + 0));
  2331. world[1] = idata.Load(offset + (instance_id*IDATA_STRIDE + IDATA_world + 1));
  2332. world[2] = idata.Load(offset + (instance_id*IDATA_STRIDE + IDATA_world + 2));
  2333. world[3] = idata.Load(offset + (instance_id*IDATA_STRIDE + IDATA_world + 3));
  2334. #endif
  2335.  
  2336. float4 p;
  2337. #if defined(NEEDS_WORLD_SPACE)
  2338. float4 wp = mul(position, world);
  2339. /*#if defined(VEGETATION_BENDING)
  2340. float3 op = world._m30_m31_m32;
  2341. float3 wnormal = mul(input.normal, (float3x3)world);
  2342. wp = vegetation_bending(op, wp, wnormal, input.color, input.position); //TODO: decode_vertex_color(input.color);
  2343. #endif*/
  2344.  
  2345. #if defined(CAMERA_LOCK_XY)
  2346. #ifdef CAMERA_LOCK_Z
  2347. view._m30_m31_m32 = float3(0,0,0);
  2348. #else
  2349. view._m30_m31 = float2(0,0);
  2350. #endif
  2351. p = mul(mul(wp,view), proj);
  2352. #else
  2353. p = mul(position, view_proj);
  2354. #endif
  2355. o.wp = wp.xyz;
  2356. #else
  2357. p = mul(position, world_view_proj);
  2358. #endif
  2359. o.position = p;
  2360.  
  2361. #if defined(PROJECT_TO_FAR_PLANE)
  2362. o.position.z = o.position.w;
  2363. #endif
  2364.  
  2365. #ifdef HAS_UV
  2366. o.uv = input.uv;
  2367. #endif
  2368. return o;
  2369. }
  2370.  
  2371. float4 ps_main(PS_INPUT input) : SV_TARGET0 {
  2372. #if defined(ONE_BIT_ALPHA)
  2373. #if defined(EXTERNAL_ALPHA_REF)
  2374. half alpha_ref = external_alpha_ref;
  2375. #else
  2376. half alpha_ref = ONE_BIT_ALPHA_REF;
  2377. #endif
  2378.  
  2379. #if defined(ONE_BIT_ALPHA_FROM_MATERIAL_B)
  2380. one_bit_alpha_mask(tex2D(material_map, input.uv).b, alpha_ref);
  2381. #else
  2382. one_bit_alpha_mask(tex2D(diffuse_map, input.uv).a, alpha_ref);
  2383. #endif
  2384. #endif
  2385.  
  2386. #ifdef SKYDOME
  2387. float3 view_vector = normalize(camera_pos - input.wp);
  2388. float sun = saturate(dot(sun_direction, view_vector)) > (1-0.05235) ? 1 : 0;
  2389. return float4(1,sun,1,1);
  2390. #else
  2391. return float4(0,0,0,0);
  2392. #endif
  2393. }
  2394. """
  2395. }
  2396. }
  2397.  
  2398. shaders = {
  2399. base = {
  2400. editor_options = [
  2401. {
  2402. name="Medusa"
  2403. options = [
  2404. { name="Outline" define="OUTLINE" tool_tip="Gives the object an outline" }
  2405. ]
  2406. }
  2407.  
  2408. {
  2409. name="Vertex Modifiers"
  2410. options = [
  2411. { name="Segmented Skinning" define="SKINNED_1WEIGHT" condition="!SKINNED_2WEIGHTS && !SKINNED_3WEIGHTS && !SKINNED_4WEIGHTS" tool_tip="Skin vertices to one weight." }
  2412. { name="2 Weight Skinning" define="SKINNED_2WEIGHTS" condition="!SKINNED_1WEIGHT && !SKINNED_3WEIGHTS && !SKINNED_4WEIGHTS" tool_tip="Skin vertices to two weights." }
  2413. { name="3 Weight Skinning" define="SKINNED_3WEIGHTS" condition="!SKINNED_1WEIGHT && !SKINNED_2WEIGHTS && !SKINNED_4WEIGHTS" tool_tip="Skin vertices to three weights." }
  2414. { name="4 Weight Skinning" define="SKINNED_4WEIGHTS" condition="!SKINNED_1WEIGHT && !SKINNED_2WEIGHTS && !SKINNED_3WEIGHTS" tool_tip="Skin vertices to four weights." }
  2415. { name="Double Sided" define="DOUBLE_SIDED" tool_tip = "Render both back facing and front facing triangles." }
  2416. { name="Vegetation Animation" define="VEGETATION_BENDING" tool_tip = "Enable simple vertex animation useful for animating leaves and similar.\nDetails: http://http.developer.nvidia.com/GPUGems3/gpugems3_ch16.html"}
  2417. { name="Instancing" define="INSTANCED" condition="!BRUSH_INSTANCED && !SKINNED_1WEIGHT && !SKINNED_2WEIGHTS && !SKINNED_3WEIGHTS && !SKINNED_4WEIGHTS" tool_tip="Group identical batches and render them in one draw call." }
  2418. { name="Terrain Undergrowth Instancing" define="BRUSH_INSTANCED" condition="!INSTANCED" tool_tip = "Instancing for procedurally placed terrain undergrowth." }
  2419. ]
  2420. }
  2421.  
  2422. {
  2423. name="Material"
  2424. options = [
  2425. { name="Skin" define="SKIN" condition="!CLOTH_SHADING && !COLORED_SPECULAR" tool_tip="Screen-space subsurface scattering tweaked for skin shading.\nDetails:http://www.iryoku.com/sssss/" }
  2426. { name=" - Subsurface Scattering Map" define="SUBSURFACE_SCATTERING_MAP" condition="SKIN" tool_tip="Control amount of subsurface from a texture.\nAmount is extracted from the green channel." }
  2427. { name="Cloth" define="CLOTH_SHADING" condition="!SKIN && !COLORED_SPECULAR" tool_tip="Enables Naughty-dog-style cloth shading.\nDetails: http://tinyurl.com/d67w5ze" }
  2428. { name=" - Mask Settings With Vertex Color" define="CLOTH_SHADING_VC_MASK" condition="CLOTH_SHADING" tool_tip="Mask Inner & Rim Lobe Settings With Vertex Color\nRed:Inner, Green:Rim"}
  2429. { name="Metal" define="COLORED_SPECULAR" condition="!SKIN && !CLOTH_SHADING" tool_tip="Turn on colored specular."}
  2430. ]
  2431. }
  2432.  
  2433. {
  2434. name="Texture Layers"
  2435. options = [
  2436. { name="Diffuse Map" define="DIFFUSE_MAP" tool_tip="Sample material albedo color from a diffuse texture." }
  2437. { name="- Use UV2 to sample Diffuse Map" define="DIFFUSE_MAP_UNIQUE_UV" tool_tip="Sample diffuse texturing using UV-channel 2 instead of UV-channel 1." }
  2438. { name="Normal Map" define="NORMAL_MAP" tool_tip="Sample per pixel normal from a tangent space normal map." }
  2439. { name="Material Map" define="MATERIAL_MAP" tool_tip="Sample specular and glossiness from Red and Green channels of a material map.\nBlue channel is unused and can be used as an auxilary channel.\nMaterial Map in sRGB for increased precision." }
  2440. { name="- Use UV4 to sample Material Map" define="MATERIAL_MAP_UNIQUE_UV" tool_tip="Sample Material Map from UV-channel 4 instead of UV-channel 1." }
  2441. { name="Ambient Occlusion Map" define="AMBIENT_OCCLUSION_MAP" tool_tip="Sample pre-baked ambient occlusion from an ambient occlusion texture.\nContents in red-channel." }
  2442. { name="Ambient Occlusion from Material Map.a" define="AMBIENT_OCCLUSION_MATERIAL_MAP" condition="!AMBIENT_OCCLUSION_MAP" tool_tip="Use contents in alpha channel of Material Map as pre-baked ambient occlusion value." }
  2443. { name="Masked VC Blend" define="MASKED_VC_BLEND" condition="DIFFUSE_MAP && MATERIAL_MAP" tool_tip="Blend between two sets of textures using vertex alpha and height map in blue channel of Material Map." }
  2444. { name="Detail Diffuse Map" define="DETAIL_DIFFUSE_MAP" tool_tip="Enable detailed diffuse texture multiplied with albedo.\nTexture in linear color space."}
  2445. { name="Detail Normal Map" define="DETAIL_NORMAL_MAP" condition="NORMAL_MAP" tool_tip="Enable detailed detailed normal texture blended with tangent space normal.\nBlended as:[N.xy+DN.xy. N.z*DN.z]" }
  2446. { name="Detail Material Map" define="DETAIL_MATERIAL_MAP" tool_tip="Enable detailed material map where red and green channel gets multiplied with calculated specular and glossiness.\nTexture in linear color space."}
  2447. ]
  2448. }
  2449.  
  2450. {
  2451. name="UV Manipulation"
  2452. options = [
  2453. { name="Diffuse Map UV Animation" define="DIFFUSE_UV_ANIM" condition="DIFFUSE_MAP && !DIFFUSE_UV_OFFSET && !DIFFUSE_UV_ROTATION_ANIM" tool_tip="Turn on UV-animation for diffuse texture." }
  2454. { name="Diffuse Map UV Offset" define="DIFFUSE_UV_OFFSET" condition="DIFFUSE_MAP && !DIFFUSE_UV_ANIM && !DIFFUSE_UV_ROTATION_ANIM" tool_tip="Turn on UV-offset for diffuse texture." }
  2455. { name="Diffuse Map UV Rotation" define="DIFFUSE_UV_ROTATION_ANIM" condition="DIFFUSE_MAP && !DIFFUSE_UV_OFFSET && !DIFFUSE_UV_ANIM" tool_tip="Turn on rotating UV-animation for diffuse texture." }
  2456. { name="Normal Map UV Animation" define="NORMAL_UV_ANIM" condition="NORMAL_MAP && !NORMAL_UV_OFFSET" tool_tip="Turn on UV-animation for normal map." }
  2457. { name="Normal Map UV Offset" define="NORMAL_UV_OFFSET" condition="NORMAL_MAP && !NORMAL_UV_ANIM" tool_tip="Turn on UV-offset for normal map."}
  2458. { name="Self Illumination Map UV Animation" define="SELF_ILLUMINATION_UV_ANIM" condition="SELF_ILLUMINATION_MAP && !SELF_ILLUMINATION_UV_OFFSET && !SELF_ILLUMINATION_UV_ROTATION_ANIM" tool_tip="Turn on UV-animation for self-illumination texture." }
  2459. { name="Self Illumination UV Offset" define="SELF_ILLUMINATION_UV_OFFSET" condition="SELF_ILLUMINATION_MAP && !SELF_ILLUMINATION_UV_ANIM && !SELF_ILLUMINATION_UV_ROTATION_ANIM" tool_tip="Turn on UV-offset for self-illumination texture." }
  2460. { name="Self Illumination UV Rotation" define="SELF_ILLUMINATION_UV_ROTATION_ANIM" condition="SELF_ILLUMINATION_MAP && !SELF_ILLUMINATION_UV_ANIM && !SELF_ILLUMINATION_UV_OFFSET" tool_tip="Turn on rotating UV-animation for self-illumination texture." }
  2461. { name="Material Map UV Animation" define="MATERIAL_UV_ANIM" condition="MATERIAL_MAP && !MATERIAL_UV_OFFSET && !MATERIAL_UV_ROTATION_ANIM" tool_tip="Turn on UV-animation for material texture." }
  2462. { name="Material Map UV Offset" define="MATERIAL_UV_OFFSET" condition="MATERIAL_MAP && !MATERIAL_UV_ANIM && !MATERIAL_UV_ROTATION_ANIM" tool_tip="Turn on UV-offset for material texture." }
  2463. { name="Material UV Rotation" define="MATERIAL_UV_ROTATION_ANIM" condition="MATERIAL_MAP && !MATERIAL_UV_ANIM && !MATERIAL_UV_OFFSET" tool_tip="Turn on rotating UV-animation for material texture." }
  2464. ]
  2465. }
  2466.  
  2467. {
  2468. name="Self Illumination"
  2469. options = [
  2470. { name="Self Illumination Map" define="SELF_ILLUMINATION_MAP" tool_tip="Sample self illumination / emissive color from an emissive texture." }
  2471. { name="- Use UV3 to sample Self Illumination Map" define="SELF_ILLUMINATION_MAP_UNIQUE_UV" condition="SELF_ILLUMINATION_MAP" tool_tip="Sample emissive texture using UV-channel 3 instead of UV-channel 1." }
  2472. { name="Tint Self Illumination With Material Color" define="SELF_ILLUMINATION_TINT_MATERIAL" condition="SELF_ILLUMINATION_MAP" tool_tip="Tint emissive color using material color variable." }
  2473. ]
  2474. }
  2475.  
  2476. {
  2477. name="Environment Mapping"
  2478. options = [
  2479. { name="Cube Environment Mapping" define="CUBE_ENVIRONMENT_MAPPING" tool_tip="Enables cube environment reflections.\nReflection respects the final G-buffer normal and are rendered as an extra pass." }
  2480. { name=" - Cube as RGBM" define="CUBE_AS_RGBM" condition="CUBE_ENVIRONMENT_MAPPING" tool_tip="Reflection texture encoded as RGBM. Cube maps generated in Bitsquid are encoded this way.\nNote: Requires Deferred Cube Environment Mapping to be enabled." }
  2481. { name=" - Cube from shading environment" define="CUBE_FROM_SHADING_ENV" condition="CUBE_ENVIRONMENT_MAPPING" tool_tip="Use reflection map defined in lighting environment. \nNote: Requires Deferred Cube Environment Mapping to be enabled." }
  2482. ]
  2483. }
  2484.  
  2485. {
  2486. name="Alpha Masking"
  2487. options = [
  2488. { name="One Bit Alpha" define="ONE_BIT_ALPHA" condition="DIFFUSE_MAP || MATERIAL_MAP" tool_tip="Enable 1-bit alpha masking. Reference value is 0.5 and mask in diffuse alpha." }
  2489. { name="Alpha From Material Map" define="ONE_BIT_ALPHA_FROM_MATERIAL_B" condition="ONE_BIT_ALPHA && MATERIAL_MAP" tool_tip="Mask value from blue channel of material map." }
  2490. { name="One Bit Alpha Reference" define="EXTERNAL_ALPHA_REF" condition="ONE_BIT_ALPHA" tool_tip="Reference value from material variable instead of hardcoded 0.5" }
  2491. { name="Soft Alpha Test (tangent)" define="SOFT_ALPHA_TEST_TANGENT" condition="ONE_BIT_ALPHA" tool_tip="Run extra pass that tries to soften edges of 1-bit alpha masked geometry by doing a streak blur in screen space tangent direction." }
  2492. { name="Dissolve Alpha Over Distance" define="DISSOLVE_ALPHA_OVER_DISTANCE" condition="ONE_BIT_ALPHA" tool_tip="Animate reference clip value to zero based on distance between pixel and camera." }
  2493. ]
  2494. }
  2495.  
  2496. {
  2497. name="Tinting"
  2498. options = [
  2499. { name="Tint Diffuse With Vertex Color RGB" define="VC_TINT_RGB" tool_tip="Tint albedo color with vertex color rgb.\nVertex Colors in gamma 2.0 and converted to linear space before multiplying with albedo." }
  2500. { name="Compressed Vertex Colors" define="VC_COMPRESSED" tool_tip="Treat vertex colors as compressed." }
  2501. { name="Tint Diffuse With Material Color" define="MATERIAL_TINT_RGB" tool_tip="Tint albedo color with material tint color.\nBlend done as: [albedo*material_color*2]\nMaterial Color in linear color space." }
  2502. ]
  2503. }
  2504.  
  2505. {
  2506. name="Baked Lighting"
  2507. options = [
  2508. { name="Vertex Baked Ambient Occlusion" define="BAKED_VERTEX_AMBIENT_OCCLUSION" tool_tip="Pipe blue channel of vertex color channel 1 as ambient occlusion value." }
  2509. ]
  2510. }
  2511.  
  2512. {
  2513. name="Special"
  2514. options = [
  2515. { name="Blend Normal To World Z+" define="BLEND_NORMAL_WORLD_POSITIVE_Z" condition="BLEND_NORMAL_OBJECT_POSITIVE_Z" tool_tip="Blend world space normal towards world up axis based on material variable." }
  2516. { name="Blend Normal To Object Z+" define="BLEND_NORMAL_OBJECT_POSITIVE_Z" condition="BLEND_NORMAL_WORLD_POSITIVE_Z" tool_tip="Blend world space normal towards object up axis based on material variable." }
  2517. { name="Mask Blend Normal With Material Map" define="MASK_BLEND_NORMAL_WITH_MATERIAL" condition="BLEND_NORMAL_OBJECT_POSITIVE_Z || BLEND_NORMAL_WORLD_POSITIVE_Z" tool_tip="Mask blend value with blue channel of Material Map."}
  2518. ]
  2519. }
  2520.  
  2521. {
  2522. name="Transparency"
  2523. options = [
  2524. { name = "One Layer Semi Transparency" define="SEMI_TRANSPARENCY" condition="!JITTERED_TRANSPARENCY" tool_tip="Uses stippling to render one layer of transparency.\nRunning in half shading frequency and patched up with extra pass." }
  2525. { name = "Jittered Transparency" define="JITTERED_TRANSPARENCY" condition="!SEMI_TRANSPARENCY" tool_tip="Uses stippling to control opacity in 4 steps." }
  2526. ]
  2527. }
  2528.  
  2529. {
  2530. name="Quality"
  2531. options = [
  2532. { name="HiQuality Normals" define="HIQUALITY_GBUFFER_NORMALS" tool_tip="Uses Crytek's best-fit normals method when storing normals in G-buffer.\nDetails: http://tinyurl.com/354j6nq" }
  2533. ]
  2534. }
  2535.  
  2536. {
  2537. name="Performance"
  2538. options = [
  2539. { name="Depth Prepass" define="DEPTH_PREPASS" tool_tip="Enable rendering of batch in depth prepass layer." }
  2540. ]
  2541. }
  2542.  
  2543. {
  2544. name="Hardware Tesselation (DX11)"
  2545. options = [
  2546. { name="Displacement Mapping" define="DX11_DISPLACEMENT_MAPPING" tool_tip="Turn on vector displacement mapping." }
  2547. { name="Height Map Displacement" define="HEIGHT_MAP_DISPLACEMENT" condition="DX11_DISPLACEMENT_MAPPING" tool_tip="Treat displacement map as height map instead of vector map." }
  2548. { name="Mask Height Map with Vertex Color Alpha" define="MASK_HEIGHT_MAP_WITH_VC_ALPHA" condition="HEIGHT_MAP_DISPLACEMENT" tool_tip="Blend between zero displacement and full height map displacement based on alpha channel in the vertex colors." }
  2549. { name="Detail Displacement Mapping" define="DETAILED_DISPLACEMENT_MAPPING" condition="DX11_DISPLACEMENT_MAPPING" tool_tip="Enable detailed height map displacement.\nHeight in blue channel."}
  2550. { name="Detail Displacement Mapping From Alpha" define="DETAIL_DISPLACEMENT_FROM_ALPHA" condition="DETAILED_DISPLACEMENT_MAPPING" tool_tip="Use alpha channel instead of blue channel for detail height map displacement." }
  2551. { name="Phong Tessellation" define="PHONG_TESSELLATION" condition="DX11_DISPLACEMENT_MAPPING" tool_tip="Enable phong tessellation." }
  2552. ]
  2553. }
  2554.  
  2555. {
  2556. name="Mobile Optimizations"
  2557. options = [
  2558. { name="Fog Color Only" define="FOG_COLOR_ONLY" tool_tip="Disable all lighting calculations and texture sampling, output the fog color." }
  2559. { name="Disable Dynamic Lightning" define="DISABLE_VTX_LIGHTNING" tool_tip="Disable dynamic lighting from local lights." }
  2560. { name="Masked VC Tint" define="MASKED_VC_TINT" condition="!MASKED_VC_TINT_INV && !FOG_COLOR_ONLY" tool_tip="A cheap & hacky variation of 'Masked VC Blend' but instead of sampling texture blend towards a tint color." }
  2561. { name="Masked VC Tint Inverted" define="MASKED_VC_TINT_INV" condition="!MASKED_VC_TINT && !FOG_COLOR_ONLY" tool_tip="Same as Maked VC Tint but blend reference is inverted." }
  2562. ]
  2563. }
  2564. ]
  2565.  
  2566. contexts = {
  2567.  
  2568. shadow_caster = {
  2569. passes_sort_mode="immediate"
  2570. passes = [{
  2571. defined="MOBILE"
  2572. pass = [
  2573.  
  2574. ]
  2575. fail = [
  2576. { hlsl_shader="depth_only" render_states="shadow_caster" }
  2577. ]
  2578. }]
  2579. }
  2580. pvs_bake = {
  2581. passes_sort_mode="immediate"
  2582. passes = [{
  2583. defined="D3D11"
  2584. pass = [
  2585. { hlsl_shader="pvs_bake" render_states="pvs_bake" }
  2586. ]
  2587. fail = [
  2588.  
  2589. ]
  2590. }]
  2591. }
  2592. ao_bake = {
  2593. passes_sort_mode="immediate"
  2594. passes = [
  2595. { hlsl_shader="ao_bake" render_states="ao_bake" }
  2596. ]
  2597. }
  2598.  
  2599. voxelize = {
  2600. passes_sort_mode="immediate"
  2601. passes = [
  2602. { hlsl_shader="base_voxelize" render_states="voxelize" }
  2603. ]
  2604. }
  2605.  
  2606. default = {
  2607. passes = [{
  2608. defined = "MOBILE"
  2609. pass = [{
  2610. defined ="SEMI_TRANSPARENCY"
  2611. pass = [
  2612. { layer="transparent" hlsl_shader="mobile_forward_base" defines="SEMI_TRANSPARENCY_RESOLVE" render_states="opacity" }
  2613. ]
  2614. fail = [
  2615. {
  2616. defined ="OES2"
  2617. pass = [
  2618. {
  2619. defined = "DISABLE_VTX_LIGHTNING"
  2620. pass = [
  2621. { layer="opaque" hlsl_shader="mobile_forward_base" render_states="gbuffer_ambient" }
  2622. ]
  2623. fail = [
  2624. { layer="opaque" hlsl_shader="mobile_forward_base" render_states="gbuffer_ambient" defines="NO_LIGHTS" branch_key="forward_lighting_disabled"}
  2625. { layer="opaque" hlsl_shader="mobile_forward_base" render_states="gbuffer_ambient" defines="LIGHT0" branch_key="forward_lighting_one_light"}
  2626. { layer="opaque" hlsl_shader="mobile_forward_base" render_states="gbuffer_ambient" defines="LIGHT0 LIGHT1" branch_key="forward_lighting_two_lights"}
  2627. { layer="opaque" hlsl_shader="mobile_forward_base" render_states="gbuffer_ambient" defines="LIGHT0 LIGHT1 LIGHT2" branch_key="forward_lighting_three_lights"}
  2628. { layer="opaque" hlsl_shader="mobile_forward_base" render_states="gbuffer_ambient" defines="LIGHT0 LIGHT1 LIGHT2 LIGHT3" branch_key="forward_lighting_four_lights"}
  2629. ]
  2630. }
  2631. ]
  2632. fail = [
  2633. { layer="outline" hlsl_shader="outline" defines="OUTLINE" render_states="outline" }
  2634. { layer="opaque" hlsl_shader="mobile_forward_base" render_states="gbuffer_ambient" }
  2635. { layer="wireframe" hlsl_shader="mobile_forward_base" defines="DRAW_WIREFRAME" render_states="wireframe" branch_key="dev_wireframe" }
  2636. ]
  2637. }
  2638. ]
  2639. }]
  2640. fail = [{
  2641. defined="DX11_0 DX11_DISPLACEMENT_MAPPING"
  2642. pass = [
  2643. {
  2644. defined="ONE_BIT_ALPHA"
  2645.  
  2646. pass = [
  2647. { layer="gbuffer_alpha_masked" hlsl_shader="gbuffer_displacement_mapping_base" render_states="gbuffer_material" }
  2648. ]
  2649. fail = [
  2650. { layer="gbuffer" hlsl_shader="gbuffer_displacement_mapping_base" render_states="gbuffer_material" }
  2651. ]
  2652. }
  2653. { layer="wireframe" hlsl_shader="gbuffer_displacement_mapping_base" defines="DRAW_WIREFRAME" render_states="wireframe" branch_key="dev_wireframe" }
  2654. { layer="outline" hlsl_shader="outline" render_states="outline" }
  2655. ]
  2656. fail = [
  2657. {
  2658. defined="DEPTH_PREPASS"
  2659. pass = [
  2660. { layer="depth_prepass" hlsl_shader="depth_only" render_states="depth_only" }
  2661. ]
  2662. }
  2663. {
  2664. defined = "SELF_ILLUMINATION_MAP"
  2665. pass = [
  2666. {
  2667. defined = "X360"
  2668. pass = [
  2669. { layer="gbuffer" hlsl_shader="gbuffer_base" render_states="gbuffer_material" }
  2670. { layer="outline" hlsl_shader="outline" render_states="outline" }
  2671. { layer="semi_transparency" hlsl_shader="forward_base" defines="EMISSIVE_PASS" render_states="gbuffer_ambient_zequal_add" }
  2672. ]
  2673. fail = [
  2674. { layer="gbuffer_self_illumination" hlsl_shader="gbuffer_base" render_states="gbuffer_material" }
  2675. { layer="outline" hlsl_shader="outline" render_states="outline" }
  2676. ]
  2677. }
  2678. ]
  2679. fail = [
  2680. {
  2681. defined = "ONE_BIT_ALPHA"
  2682. pass = [
  2683. { layer="gbuffer_alpha_masked" hlsl_shader="gbuffer_base" render_states="gbuffer_material" }
  2684. ]
  2685. fail = [
  2686. { layer="gbuffer" hlsl_shader="gbuffer_base" render_states="gbuffer_material" }
  2687. { layer="outline" hlsl_shader="outline" render_states="outline" }
  2688. ]
  2689. }
  2690. ]
  2691. }
  2692. {
  2693. defined ="SEMI_TRANSPARENCY"
  2694. pass = [
  2695. { layer="semi_transparency" hlsl_shader="forward_base" defines="SEMI_TRANSPARENCY_RESOLVE" render_states="gbuffer_material" }
  2696. ]
  2697. }
  2698. {
  2699. defined = "CUBE_ENVIRONMENT_MAPPING"
  2700. pass = [
  2701. { layer="reflections" hlsl_shader="forward_base" render_states="gbuffer_ambient_zequal_add" }
  2702. ]
  2703. }
  2704.  
  2705. { layer="wireframe" hlsl_shader="gbuffer_base" defines="DRAW_WIREFRAME" render_states="wireframe" branch_key="dev_wireframe" }
  2706. { layer="outline" hlsl_shader="outline" render_states="outline" }
  2707.  
  2708. {
  2709. defined = "SOFT_ALPHA_TEST_TANGENT"
  2710. pass = [
  2711. { layer="hdr_transparent" hlsl_shader="forward_base" render_states="ambient_no_depth_write" }
  2712. ]
  2713. }
  2714. ]
  2715. }]
  2716. }]
  2717. }
  2718. }
  2719.  
  2720. compile = {
  2721. shadow_caster = [
  2722. { defines="MOBILE" render_caps={emulate_mobile=true} platforms="D3D11" }
  2723. { defines="MOBILE" platforms = "OES2" }
  2724. { defines="HWSM" platforms = "D3D11 GCM X360 GL2"}
  2725. ]
  2726. pvs_bake = [
  2727. { defines="" platforms="D3D11" }
  2728. ]
  2729. ao_bake = [
  2730. { defines="" platforms="D3D11" }
  2731. ]
  2732. voxelize = [
  2733. { defines="" platforms="D3D11" }
  2734. ]
  2735. default = [
  2736. { defines="MOBILE" render_caps={ emulate_mobile=true} platforms="D3D11" }
  2737. { defines="MOBILE" platforms = "OES2" }
  2738. { defines="DX11_0" render_caps={ feature_level="DX11_0" tessellation_enabled = true} platforms="D3D11" }
  2739. { defines="" platforms = "D3D11 GCM X360 GL2"}
  2740. ]
  2741. }
  2742. }
  2743.  
  2744. skydome = {
  2745. editor_options = [
  2746. {
  2747. name="Vertex Modifiers"
  2748. options = [
  2749. { name="Lock Camera in XY-plane" define="CAMERA_LOCK_XY" }
  2750. { name="Lock Camera in Z-plane" define="CAMERA_LOCK_Z" }
  2751. ]
  2752. }
  2753. {
  2754. name="Pixel Modifiers"
  2755. options = [
  2756. { name="Diffuse Map" define="DIFFUSE_MAP" }
  2757. { name=" - RGBM encoded" define = "DIFFUSE_AS_RGBM" }
  2758. ]
  2759. }
  2760. ]
  2761.  
  2762. contexts = {
  2763. default = {
  2764. passes = [{
  2765. defined="MOBILE"
  2766. pass = [
  2767. { layer="skydome" hlsl_shader="mobile_skydome" defines="PROJECT_TO_FAR_PLANE" render_states="ambient_no_depth_write" }
  2768. ]
  2769. fail = [
  2770. { layer="skydome" hlsl_shader="forward_base" defines="PROJECT_TO_FAR_PLANE SKYDOME" render_states="ambient_no_depth_write" }
  2771. ]
  2772. }]
  2773. }
  2774. ao_bake = {
  2775. passes_sort_mode="immediate"
  2776. passes = [{
  2777. defined="D3D11"
  2778. pass = [
  2779. { hlsl_shader="ao_bake" defines="PROJECT_TO_FAR_PLANE SKYDOME" render_states="ambient_no_depth_write" }
  2780. ]
  2781. fail = [
  2782. ]
  2783. }]
  2784. }
  2785. pvs_bake = {
  2786. passes_sort_mode="immediate"
  2787. passes = [{
  2788. defined="D3D11"
  2789. pass = [
  2790. { hlsl_shader="pvs_bake" render_states="pvs_bake" }
  2791. ]
  2792. fail = [
  2793.  
  2794. ]
  2795. }]
  2796. }
  2797. }
  2798.  
  2799. compile = {
  2800. default = [
  2801. { defines="MOBILE" render_caps={ emulate_mobile = true} platforms="D3D11" }
  2802. { defines="MOBILE" platforms = "OES2" }
  2803. { defines="" platforms = "D3D11 GCM X360 GL2"}
  2804. ]
  2805. pvs_bake = [
  2806. { defines=""}
  2807. ]
  2808. ao_bake = [
  2809. { defines="" platforms="D3D11" }
  2810. ]
  2811. }
  2812. }
  2813.  
  2814. water = {
  2815. editor_options = [
  2816. {
  2817. name="UV Generation"
  2818. options = [
  2819. { name="Base UV coordinates on World XY" define="WORLD_XY_AS_UV" }
  2820. ]
  2821. }
  2822. {
  2823. name="Water Surface Features"
  2824. options = [
  2825. { name="Depth color extinction" define="COLOR_EXTINCTION" }
  2826. { name="Geometry Fade out" define="GEOMETRY_FADE_OUT" }
  2827. { name="Cube Environment Mapping" define="CUBE_ENVIRONMENT_MAPPING" }
  2828. { name=" - Cube as RGBM" define="CUBE_AS_RGBM" }
  2829. { name=" - Cube from shading environment" define="CUBE_FROM_SHADING_ENV" tool_tip="Use reflection map defined in lighting environment. \nNote: Requires Deferred Cube Environment Mapping to be enabled." }
  2830. { name="Foam Map" define="FOAM" }
  2831. { name="Blend to perlin noise to hide tiling" define="BLEND_TO_PERLIN_NOISE" }
  2832. { name="Mask sun with deferred shadows" define="MASK_WITH_DEFERRED_SHADOW" }
  2833. ]
  2834. }
  2835.  
  2836. ]
  2837.  
  2838. contexts = {
  2839. default = {
  2840. passes = [{
  2841. defined="MOBILE"
  2842. pass = [
  2843. //
  2844. ]
  2845. fail = [
  2846. { layer="water" hlsl_shader="water" defines="MASK ALWAYS" render_states="water_mask" }
  2847. { layer="water" hlsl_shader="water" defines="MASK" render_states="water_mask" }
  2848. { layer="water" hlsl_shader="water" render_states="opacity" }
  2849. ]
  2850. }]
  2851. }
  2852. }
  2853.  
  2854. compile = {
  2855. default = [
  2856. { defines="MOBILE" render_caps={ emulate_mobile = true} platforms="D3D11" }
  2857. { defines="MOBILE" platforms = "OES2" }
  2858. { defines="" platforms = "D3D11 GCM X360 GL2"}
  2859. ]
  2860. }
  2861. }
  2862.  
  2863. mobile_water = {
  2864. editor_options = [
  2865. {
  2866. name="Water Surface Options"
  2867. options = [
  2868. { name="Tangent Space Transformation" define="TANGENT_SPACE" }
  2869. ]
  2870. }
  2871. ]
  2872.  
  2873. contexts = {
  2874. default = {
  2875. passes = [
  2876. { layer="water" hlsl_shader="mobile_water" render_states="opacity" }
  2877. ]
  2878. }
  2879. }
  2880.  
  2881. compile = {
  2882. default = [
  2883. { defines="MOBILE" render_caps={ emulate_mobile = true} platforms="D3D11" }
  2884. { defines="MOBILE" platforms = "OES2 GL2" }
  2885. ]
  2886. }
  2887. }
  2888.  
  2889. fog_plane = {
  2890. editor_options = [
  2891. {
  2892. name="Settings"
  2893. options = [
  2894. { name="Inverted: Fog pixels in-front of plane" define="INVERTED" }
  2895. ]
  2896. }
  2897. ]
  2898.  
  2899. contexts = {
  2900. default = {
  2901. passes = [{
  2902. defined="MOBILE"
  2903. pass = [
  2904. //
  2905. ]
  2906. fail = [
  2907. { layer="fog_volumes" hlsl_shader="fog_plane" render_states="fog_plane" }
  2908. ]
  2909. }]
  2910. }
  2911. }
  2912.  
  2913. compile = {
  2914. default = [
  2915. { defines="MOBILE" render_caps={ emulate_mobile = true} platforms="D3D11" }
  2916. { defines="MOBILE" platforms = "OES2" }
  2917. { defines="" platforms = "D3D11 GCM X360 GL2"}
  2918. ]
  2919. }
  2920. }
  2921.  
  2922. eye_highlight = {
  2923. editor_options = [
  2924. {
  2925. name="Vertex Modifiers"
  2926. options = [
  2927. { name="Segmented Skinning" define="SKINNED_1WEIGHT" }
  2928. { name="2 Weight Skinning" define="SKINNED_2WEIGHTS" }
  2929. { name="3 Weight Skinning" define="SKINNED_3WEIGHTS" }
  2930. { name="4 Weight Skinning" define="SKINNED_4WEIGHTS" }
  2931. ]
  2932. }
  2933. ]
  2934.  
  2935. contexts = {
  2936. default = {
  2937. passes = [{
  2938. defined="MOBILE"
  2939. pass = [
  2940. //
  2941. ]
  2942. fail = [
  2943. { layer="semi_transparency" hlsl_shader="eye_highlight" render_states="opacity_add" }
  2944. ]
  2945. }]
  2946. }
  2947. }
  2948.  
  2949. compile = {
  2950. default = [
  2951. { defines="MOBILE" render_caps={ emulate_mobile = true} platforms="D3D11" }
  2952. { defines="MOBILE" platforms = "OES2" }
  2953. { defines="" platforms = "D3D11 GCM X360 GL2"}
  2954. ]
  2955. }
  2956. }
  2957.  
  2958. mobile_ao_plane = {
  2959. editor_options = [
  2960. {
  2961. name="Sphere Occlusion"
  2962. options = [
  2963. { name="1 Sphere" define="SKINNED_1WEIGHT" }
  2964. { name="2 Spheres" define="SKINNED_2WEIGHTS" }
  2965. { name="3 Spheres" define="SKINNED_3WEIGHTS" }
  2966. { name="4 Spheres" define="SKINNED_4WEIGHTS" }
  2967. ]
  2968. }
  2969. ]
  2970.  
  2971. contexts = {
  2972. default = {
  2973. passes = [{
  2974. defined="MOBILE"
  2975. pass = [
  2976. { layer="decals" hlsl_shader="mobile_ao_plane" render_states="mobile_ao" }
  2977. ]
  2978. fail = [
  2979.  
  2980. ]
  2981. }]
  2982. }
  2983. }
  2984.  
  2985. compile = {
  2986. default = [
  2987. { defines="MOBILE" render_caps={ emulate_mobile = true} platforms="D3D11" }
  2988. { defines="MOBILE" platforms = "OES2" }
  2989. ]
  2990. }
  2991. }
  2992. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement