Ember

TGA PhysicallyBasedLighting

Oct 7th, 2013
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 65.98 KB | None | 0 0
  1. /*
  2. TGA Physically Based Lighting CGFX Realtime Shader for Maya
  3.  
  4. Current Version:
  5. v0.3.6
  6. 2013-05-07
  7.  
  8. By Kostas Gialitakis & Niklas Hansson
  9. www.thegameassembly.com
  10.  
  11. ----Change Log----
  12.  
  13. From 0.3.5.2 to 0.3.6
  14. -New "Cube Rotation" feature which allows you to easily rotate the cube map around the Maya Y axis with a slider.
  15. -Switched the gp4vp/gp4fp to vp40/fp40 profiles for the TransparencyUsingAlbedoAlpha technique as I was having some issues with the gp4vp/gp4fp profile. Let me know if you have problems with this change.
  16.  
  17. From 0.3.5.1 to 0.3.5.2
  18. -Reflection fresnel is now affected by Roughness.
  19.  
  20. From 0.3.5 to 0.3.5.1
  21. -Roughness now properly gamma correct for reflections.
  22. -Minor improvement in mip-map selection formula for reflections.
  23.  
  24. From 0.3.4.1 to 0.3.5
  25. -Energy conservation between diffuse and specular materials.
  26. -Implemented Kelemen Szirmay Kalos visibility model.
  27. -Adjusted blinn-phong normalization to better approximation.
  28. -Raised max specular power to take advantage of our logarithmic encoding.
  29. -Adapted max specular to work with common cubemap blurring levels.
  30.  
  31. From 0.3.4 to 0.3.4.1
  32. -Bug fix, ambient light is now properly gamma corrected.
  33.  
  34. From 0.3.3.1 to 0.3.4
  35. -Now features energy conservation between ambient and reflective amount. I.e. If a sampled point is reflecting a lot of light, it won't also add a lot of ambient light and vice versa. Thanks for helping me with this Niklas.
  36.  
  37. From 0.3.3 to 0.3.3.1
  38. -Bug fix, Normal Map multiplier was at 1.5x prior to this version. Now default is 1.0x.
  39. -Normal Multiplier added as a slider.
  40. -Scrapped idea of running two parallell shaders. Will just continue to use just the newer "multiplier sliders version".
  41.  
  42. From 0.3.2.1 to 0.3.3:
  43. -Added a version of the shader with "multiplier sliders" for the Albedo texture, Roughness texture, Substance texture and Cube Map texture.
  44.  
  45. From 0.3.2 to 0.3.2.1:
  46. -Retroactively added bug-fixes in Change Log between 0.2.2 -> 0.3 for clarity reasons.
  47.  
  48. From 0.3.1 to 0.3.2:
  49. -Added transparency support. Use the albedo texture alpha channel.
  50.  
  51. From 0.3 to 0.3.1:
  52. -Added Emissive Texture feature.
  53.  
  54. From 0.2.2 to 0.3:
  55. -Added Blended Normals feature along with a Cyan Suppress and access to the Lerp values for the blend.
  56. -Added Shadow Map feature to a pre-baked texture for shadows, this utilizes the UV set defined in TEXCOORD3 slot (bottom of shader list).
  57. -Bug fix, reflection are now affected by the normal maps contribution.
  58. -Bug fix, gamma correction working correctly in conjunction with the exposure feature.
  59.  
  60. From 0.2.1 to 0.2.2:
  61. -Fixed a bug with how reflections were handled in conjunction with a normal map.
  62.  
  63. */
  64.  
  65. /******************************************************************************
  66. * The following code was generated by the mental mill(R) *
  67. * Fx_code_generator build 45261.50496 23 Jul 2009 nt-x86
  68. * *
  69. * Portions Copyright (c) 1986-2009 mental images GmbH, Berlin, Germany. *
  70. ******************************************************************************/
  71.  
  72. // shader type surface
  73.  
  74. //
  75. // The state structure is used internally within the fragment shader to
  76. // commonly used values.
  77. //
  78. struct State
  79. {
  80. float4 tex_coord[4];
  81. float3 position;
  82. float3 origin;
  83. float3 normal;
  84. float3 direction;
  85. float ray_length;
  86. float3x3 tangent_space[1];
  87. };
  88.  
  89. //
  90. // Values for the light_type parameter of light shaders
  91. //
  92. #define LIGHT_POINT 0
  93. #define LIGHT_SPOT 1
  94. #define LIGHT_INFINITE 2
  95. #define LIGHT_PLANAR 3
  96.  
  97. //
  98. // The light iterator structure holds the return values resulting from
  99. // evaluating a light.
  100. //
  101. #ifndef __LIGHT_ITERATOR_STRUCT
  102. #define __LIGHT_ITERATOR_STRUCT
  103. struct Light_iterator {
  104. float3 msl_point;
  105. float4 msl_contribution;
  106. float4 msl_raw_contribution;
  107. float msl_dot_nl;
  108. float3 msl_direction;
  109. float msl_distance;
  110. float4 msl_shadow;
  111. int msl_count;
  112. };
  113. #endif // __LIGHT_ITERATOR_STRUCT
  114.  
  115. struct Ray {
  116. float3 msl_origin;
  117. float3 msl_direction;
  118. };
  119.  
  120. void __make_basis(const float3 n, const float3 u, const float3 v,
  121. out float3 t, out float3 b)
  122. {
  123. b = normalize(cross(u,n));
  124. t = cross(n,b);
  125. if (dot(b,v) < 0.0) b = -b;
  126. }
  127.  
  128. float3 __perspective_divide(float4 pt)
  129. {
  130. return pt.xyz/pt.w;
  131. }
  132.  
  133. //
  134. // State dependant variable recalculation.
  135. //
  136. void __update_state_origin_or_position(inout State state)
  137. {
  138. state.direction = state.position - state.origin;
  139. state.ray_length = length(state.direction);
  140. state.direction = normalize(state.direction);
  141. }
  142.  
  143. //
  144. // The following are free parameters of the shader that should be set by the
  145. // application at runtime.
  146. //
  147.  
  148. texture __msl_TGA_PhysicallBasedLighting_Shader_1_AlbedoTexture <
  149. string UIName = "msl_TGA_PhysicallBasedLighting_Shader_1_AlbedoTexture";
  150. string ResourceType = "2D";
  151. >;
  152.  
  153. sampler2D Albedo_Texture_Gamma = sampler_state {
  154. Texture = <__msl_TGA_PhysicallBasedLighting_Shader_1_AlbedoTexture>;
  155. MinFilter = LinearMipMapLinear;
  156. MagFilter = Linear;
  157. };
  158.  
  159. float Albedo_Multiplier
  160. <
  161. float UIMin = 0.0;
  162. float UIMax = 4.0;
  163. float UIStep = 0.01;
  164. string UIWidget = "slider";
  165. > = 1;
  166.  
  167.  
  168.  
  169. texture __msl_TGA_PhysicallBasedLighting_Shader_1_NormalTexture <
  170. string UIName = "msl_TGA_PhysicallBasedLighting_Shader_1_NormalTexture";
  171. string ResourceType = "2D";
  172. >;
  173.  
  174. sampler2D Normal_Texture_Linear = sampler_state {
  175. Texture = <__msl_TGA_PhysicallBasedLighting_Shader_1_NormalTexture>;
  176. MinFilter = LinearMipMapLinear;
  177. MagFilter = Linear;
  178. };
  179.  
  180. float Normal_Multiplier
  181. <
  182. float UIMin = 0.0;
  183. float UIMax = 4.0;
  184. float UIStep = 0.01;
  185. string UIWidget = "slider";
  186. > = 1;
  187.  
  188.  
  189. texture __msl_TGA_PhysicallBasedLighting_Shader_1_AOTexture <
  190. string UIName = "msl_TGA_PhysicallBasedLighting_Shader_1_AOTexture";
  191. string ResourceType = "2D";
  192. >;
  193.  
  194. sampler2D AO_Texture_Gamma_TEXCOORD3= sampler_state {
  195. Texture = <__msl_TGA_PhysicallBasedLighting_Shader_1_AOTexture>;
  196. MinFilter = LinearMipMapLinear;
  197. MagFilter = Linear;
  198. };
  199.  
  200. texture __msl_TGA_PhysicallBasedLighting_Shader_1_RoughnessTexture <
  201. string UIName = "msl_TGA_PhysicallBasedLighting_Shader_1_RoughnessTexture";
  202. string ResourceType = "2D";
  203. >;
  204.  
  205. sampler2D Roughness_Texture_Gamma = sampler_state {
  206. Texture = <__msl_TGA_PhysicallBasedLighting_Shader_1_RoughnessTexture>;
  207. MinFilter = LinearMipMapLinear;
  208. MagFilter = Linear;
  209. };
  210.  
  211. float Roughness_Multiplier
  212. <
  213. float UIMin = 0.0;
  214. float UIMax = 4.0;
  215. float UIStep = 0.01;
  216. string UIWidget = "slider";
  217. > = 1;
  218.  
  219. texture __msl_TGA_PhysicallBasedLighting_Shader_1_SubstanceTexture <
  220. string UIName = "msl_TGA_PhysicallBasedLighting_Shader_1_SubstanceTexture";
  221. string ResourceType = "2D";
  222. >;
  223.  
  224. sampler2D Substance_Texture_Gamma = sampler_state {
  225. Texture = <__msl_TGA_PhysicallBasedLighting_Shader_1_SubstanceTexture>;
  226. MinFilter = LinearMipMapLinear;
  227. MagFilter = Linear;
  228. };
  229.  
  230. float Substance_Multiplier
  231. <
  232. float UIMin = 0.0;
  233. float UIMax = 4.0;
  234. float UIStep = 0.01;
  235. string UIWidget = "slider";
  236. > = 1;
  237.  
  238. texture __msl_TGA_PhysicallBasedLighting_Shader_1_AmbEnvTex <
  239. string UIName = "msl_TGA_PhysicallBasedLighting_Shader_1_AmbEnvTex";
  240. string ResourceType = "Cube";
  241. >;
  242.  
  243. float CubeRotation
  244. <
  245. string UIName = "Cube Map Rotation";
  246. float UIMin = float(0.0f);
  247. float UIMax = float(360.0f);
  248. string UIWidget = "slider";
  249. > = 0;
  250.  
  251. samplerCUBE Environment_Cube_Gamma = sampler_state {
  252. Texture = <__msl_TGA_PhysicallBasedLighting_Shader_1_AmbEnvTex>;
  253. MinFilter = LinearMipMapLinear;
  254. MagFilter = Linear;
  255. WrapR = ClampToEdge;
  256. WrapS = ClampToEdge;
  257. WrapT = ClampToEdge;
  258. };
  259.  
  260. float Cube_Multiplier
  261. <
  262. float UIMin = 0.0;
  263. float UIMax = 4.0;
  264. float UIStep = 0.01;
  265. string UIWidget = "slider";
  266. > = 1;
  267.  
  268.  
  269. float Ambient_Mip_Level
  270. <
  271. string UIName = "Ambient Mip Level";
  272. > = 6;
  273.  
  274. float Reflection_Max_Mip_Level
  275. <
  276. string UIName = "Reflection Max Mip Level";
  277. > = 10;
  278.  
  279. float Exposure
  280. <
  281. float UIMin = 0.0;
  282. float UIMax = 1.0;
  283. float UIStep = 0.01;
  284. string UIWidget = "slider";
  285. > = 0.741935;
  286.  
  287. bool UseBlendedNormals
  288. <
  289. string UIName = "Use Blended Normals";
  290. > = false;
  291.  
  292. float Cyan_Suppress
  293. <
  294. string UIName = "Cyan Suppress";
  295. > = 0.400000;
  296.  
  297. float3 Blend_Lerps
  298. <
  299. string UIName = "Blend Lerps";
  300. > = float3(0.400000, 1.0, 1.0);
  301.  
  302. bool Use_Emissive_Map
  303. <
  304. string UIName = "Use Emissive Texture";
  305. > = false;
  306.  
  307. texture tga_pbl_emissive_texture <
  308. string UIName = "Emissive Texture";
  309. string ResourceType = "2D";
  310. >;
  311.  
  312. sampler2D Emissive_Texture = sampler_state {
  313. Texture = <tga_pbl_emissive_texture>;
  314. MinFilter = LinearMipMapLinear;
  315. MagFilter = Linear;
  316. };
  317.  
  318.  
  319. bool Use_Shadow_Map
  320. <
  321. string UIName = "Use Shadow Map (TEXCOORD3)";
  322. > = false;
  323.  
  324. texture __msl_TGA_PhysicallBasedLighting_Shader_1_ShadowMap <
  325. string UIName = "msl_TGA_PhysicallBasedLighting_Shader_1_ShadowMap";
  326. string ResourceType = "2D";
  327. >;
  328.  
  329. sampler2D Shadow_Map = sampler_state {
  330. Texture = <__msl_TGA_PhysicallBasedLighting_Shader_1_ShadowMap>;
  331. MinFilter = LinearMipMapLinear;
  332. MagFilter = Linear;
  333. };
  334.  
  335.  
  336. /////////// LIGHTS
  337.  
  338.  
  339. /// DIRECTIONAL 1
  340.  
  341. float3 msl_Light_directional_1_color: Diffuse
  342. <
  343. string UIName = "Directional 1 Color";
  344. float3 UIMin = float3(0.0, 0.0, 0.0);
  345. float3 UIMax = float3(1.0, 1.0, 1.0);
  346. float UIStep = 0.01;
  347. string UIWidget = "slider";
  348. > = float3(1.0, 1.0, 1.0);
  349.  
  350. float msl_Light_directional_1_intensity
  351. <
  352. string UIName = "Directional 1 Intensity";
  353. float UIMin = 0.0;
  354. float UIMax = 5.000000;
  355. float UIStep = 0.01;
  356. string UIWidget = "slider";
  357. > = 1.0;
  358.  
  359. float3 Directional1_Direction : Direction
  360. <
  361. string Object = "InfiniteLight0";
  362. string UIName = "Directional 1 Direction";
  363. string Space = "View";
  364. > = float3(0.0, 0.0, -1.000000);
  365. float4x4 msl_light0_transform_internal_to_light;
  366. float4x4 msl_light0_transform_light_to_internal;
  367.  
  368.  
  369.  
  370. /// DIRECTIONAL 2
  371.  
  372. float3 msl_Light_directional_2_color: Diffuse
  373. <
  374. string UIName = "Directional 2 Color";
  375. float3 UIMin = float3(0.0, 0.0, 0.0);
  376. float3 UIMax = float3(1.0, 1.0, 1.0);
  377. float UIStep = 0.01;
  378. string UIWidget = "slider";
  379. > = float3(1.0, 1.0, 1.0);
  380.  
  381. float msl_Light_directional_2_intensity
  382. <
  383. string UIName = "Directional 2 Intensity";
  384. float UIMin = 0.0;
  385. float UIMax = 5.000000;
  386. float UIStep = 0.01;
  387. string UIWidget = "slider";
  388. > = 0.0;
  389.  
  390. float3 msl_light1_direction : Direction
  391. <
  392. string Object = "InfiniteLight1";
  393. string UIName = "Directional 2 Direction";
  394. string Space = "View";
  395. > = float3(0.0, 0.0, -1.000000);
  396. float4x4 msl_light1_transform_internal_to_light;
  397. float4x4 msl_light1_transform_light_to_internal;
  398.  
  399.  
  400.  
  401.  
  402. /// DIRECTIONAL 3
  403.  
  404. float3 msl_Light_directional_3_color: Diffuse
  405. <
  406. string UIName = "Directional 3 Color";
  407. float3 UIMin = float3(0.0, 0.0, 0.0);
  408. float3 UIMax = float3(1.0, 1.0, 1.0);
  409. float UIStep = 0.01;
  410. string UIWidget = "slider";
  411. > = float3(1.0, 1.0, 1.0);
  412.  
  413. float msl_Light_directional_3_intensity
  414. <
  415. string UIName = "Directional 3 Intensity";
  416. float UIMin = 0.0;
  417. float UIMax = 5.000000;
  418. float UIStep = 0.01;
  419. string UIWidget = "slider";
  420. > = 0.0;
  421.  
  422. float3 msl_light2_direction : Direction
  423. <
  424. string Object = "InfiniteLight2";
  425. string UIName = "Directional 3 Direction";
  426. string Space = "View";
  427. > = float3(0.0, 0.0, -1.000000);
  428. float4x4 msl_light2_transform_internal_to_light;
  429. float4x4 msl_light2_transform_light_to_internal;
  430.  
  431.  
  432.  
  433. /// POINT 1
  434.  
  435. float3 msl_Light_point_1_color: Diffuse
  436. <
  437. string UIName = "Point 1 Color";
  438. string UIWidget = "Color";
  439. > = float3(1.0, 1.0, 1.0);
  440.  
  441. float msl_Light_point_1_intensity
  442. <
  443. string UIName = "Point 1 Intensity";
  444. float UIMin = 0.0;
  445. float UIMax = 5.000000;
  446. float UIStep = 0.01;
  447. string UIWidget = "slider";
  448. > = 0.0;
  449.  
  450. float msl_Light_point_1_distance_falloff_exponent
  451. <
  452. string UIName = "Point 1 Distance Falloff Exp";
  453. float UIMin = 0.0;
  454. float UIMax = 4.000000;
  455. float UIStep = 0.01;
  456. string UIWidget = "slider";
  457. > = 0.0;
  458.  
  459. float msl_Light_point_1_distance_scale
  460. <
  461. string UIName = "Point 1 Distance Scale";
  462. float UIMin = 0.001000;
  463. float UIMax = 2.000000;
  464. float UIStep = 0.01;
  465. string UIWidget = "slider";
  466. > = 1.0;
  467.  
  468. float3 msl_light3_position : Position
  469. <
  470. string Object = "PointLight3";
  471. string UIName = "Point 1 Position";
  472. string Space = "View";
  473. > = float3(0.0, 0.0, 0.0);
  474. float4x4 msl_light3_transform_internal_to_light;
  475. float4x4 msl_light3_transform_light_to_internal;
  476.  
  477.  
  478.  
  479. /// POINT 2
  480.  
  481. float3 msl_Light_point_2_color: Diffuse
  482. <
  483. string UIName = "Point 2 Color";
  484. string UIWidget = "Color";
  485. > = float3(1.0, 1.0, 1.0);
  486.  
  487. float msl_Light_point_2_intensity
  488. <
  489. string UIName = "Point 2 Intensity";
  490. float UIMin = 0.0;
  491. float UIMax = 5.000000;
  492. float UIStep = 0.01;
  493. string UIWidget = "slider";
  494. > = 0.0;
  495.  
  496. float msl_Light_point_2_distance_falloff_exponent
  497. <
  498. string UIName = "Point 2 Distance Falloff Exp";
  499. float UIMin = 0.0;
  500. float UIMax = 4.000000;
  501. float UIStep = 0.01;
  502. string UIWidget = "slider";
  503. > = 0.0;
  504.  
  505. float msl_Light_point_2_distance_scale
  506. <
  507. string UIName = "Point 2 Distance Scale";
  508. float UIMin = 0.001000;
  509. float UIMax = 2.000000;
  510. float UIStep = 0.01;
  511. string UIWidget = "slider";
  512. > = 1.0;
  513.  
  514. float3 msl_light4_position : Position
  515. <
  516. string Object = "PointLight4";
  517. string UIName = "Point 2 Position";
  518. string Space = "View";
  519. > = float3(0.0, 0.0, 0.0);
  520. float4x4 msl_light4_transform_internal_to_light;
  521. float4x4 msl_light4_transform_light_to_internal;
  522.  
  523.  
  524.  
  525.  
  526. /// POINT 3
  527.  
  528. float3 msl_Light_point_3_color: Diffuse
  529. <
  530. string UIName = "Point 3 Color";
  531. string UIWidget = "Color";
  532. > = float3(1.0, 1.0, 1.0);
  533.  
  534. float msl_Light_point_3_intensity
  535. <
  536. string UIName = "Point 3 Intensity";
  537. float UIMin = 0.0;
  538. float UIMax = 5.000000;
  539. float UIStep = 0.01;
  540. string UIWidget = "slider";
  541. > = 0.0;
  542.  
  543. float msl_Light_point_3_distance_falloff_exponent
  544. <
  545. string UIName = "Point 3 Distance Falloff Exp";
  546. float UIMin = 0.0;
  547. float UIMax = 4.000000;
  548. float UIStep = 0.01;
  549. string UIWidget = "slider";
  550. > = 0.0;
  551.  
  552. float msl_Light_point_3_distance_scale
  553. <
  554. string UIName = "Point 3 Distance Scale";
  555. float UIMin = 0.001000;
  556. float UIMax = 2.000000;
  557. float UIStep = 0.01;
  558. string UIWidget = "slider";
  559. > = 1.0;
  560.  
  561. float3 msl_light5_position : Position
  562. <
  563. string Object = "PointLight5";
  564. string UIName = "Point 3 Position";
  565. string Space = "View";
  566. > = float3(0.0, 0.0, 0.0);
  567. float4x4 msl_light5_transform_internal_to_light;
  568. float4x4 msl_light5_transform_light_to_internal;
  569.  
  570.  
  571. //////// END OF LIGHTS
  572.  
  573.  
  574.  
  575. //
  576. // The following are parameters representing non-varying state variables
  577. // referenced by the shader. These should be set by the application at runtime.
  578. // Note that vector parameters should be provided in camera space.
  579. //
  580. float4x4 __object_to_ndc : WorldViewProjection
  581. <
  582. string UIWidget = "none";
  583. >;
  584.  
  585. float4x4 __world_to_camera : View
  586. <
  587. string UIWidget = "none";
  588. >;
  589. float4x4 __object_to_world : World
  590. <
  591. string UIWidget = "none";
  592. >;
  593. float4x4 __object_to_camera : WorldView
  594. <
  595. string UIWidget = "none";
  596. >;
  597. float4x4 __camera_to_world : ViewInverse
  598. <
  599. string UIWidget = "none";
  600. >;
  601. float4x4 __camera_to_object : WorldViewInverse
  602. <
  603. string UIWidget = "none";
  604. >;
  605. //
  606. // The following are parameters representing non-varying non-state variables
  607. // referenced by the shader. These should be set by the application at runtime.
  608. //
  609. float4x4 __internal_to_light;
  610. float4x4 __light_to_internal;
  611.  
  612.  
  613.  
  614. //
  615. // The App2vert structure defines the vertex attributes used by the vertex
  616. // shader. The application should supply a vertex stream containing these
  617. // elements.
  618. //
  619. struct App2vert
  620. {
  621. float3 position : POSITION;
  622. float3 normal : NORMAL;
  623. float4 texcoord0 : TEXCOORD0;
  624. float4 texcoord1 : TEXCOORD1;
  625. float4 texcoord2 : TEXCOORD2;
  626. float4 texcoord3 : TEXCOORD3;
  627. float3 tex_du : TANGENT;
  628. float3 tex_dv : BINORMAL;
  629. };
  630.  
  631. //
  632. // The Vert2frag structure defines values used by the fragment shader and
  633. // supplied by the vertex shader.
  634. //
  635. struct Vert2frag
  636. {
  637. float4 hpos : POSITION;
  638. float4 tex_coord[4] : TEXCOORD0;
  639. float3 tex_du : TEXCOORD4;
  640. float3 tex_dv : TEXCOORD5;
  641. float3 position : TEXCOORD6;
  642. float3 normal : TEXCOORD7;
  643. };
  644.  
  645. //
  646. // This function is the main method of the vertex shader.
  647. //
  648. Vert2frag vertex_main(
  649. App2vert vs_in)
  650. {
  651. Vert2frag vs_out;
  652. float4 position = float4(vs_in.position, 1);
  653. vs_out.hpos = mul(__object_to_ndc, position);
  654. vs_out.position = mul(__object_to_camera, position).xyz;
  655. vs_out.normal = mul(vs_in.normal, (float3x3)__camera_to_object);
  656. vs_out.tex_coord[0] = vs_in.texcoord0;
  657. vs_out.tex_coord[1] = vs_in.texcoord1;
  658. vs_out.tex_coord[2] = vs_in.texcoord2;
  659. vs_out.tex_coord[3] = vs_in.texcoord3;
  660. vs_out.tex_du = mul((float3x3)__object_to_camera, vs_in.tex_du);
  661. vs_out.tex_dv = mul((float3x3)__object_to_camera, vs_in.tex_dv);
  662. return vs_out;
  663. }
  664.  
  665. //
  666. // Declaration of final output type. For MRT, this is a struct.
  667. //
  668. typedef float4 FS_OUT;
  669.  
  670. //
  671. // The following functions are generated from the MetaSL implementation of
  672. // the shaders that are part of the compiled shader graph.
  673. //
  674.  
  675. void TGA_PhysicallBasedLighting_Shader_Conversion_float_to_color_main(
  676. inout State state,
  677. float msl_scalar,
  678. out float4 msl_color)
  679. {
  680. {
  681. msl_color = (float4(msl_scalar, msl_scalar, msl_scalar, 1.0));
  682. }
  683. }
  684.  
  685. void TGA_PhysicallBasedLighting_Shader_Inputs_Ext_texture_lookup_2d_alpha_main(
  686. inout State state,
  687. sampler2D msl_texture,
  688. float2 msl_texture_uv,
  689. out float4 msl_result,
  690. out float msl_alpha)
  691. {
  692. {
  693. msl_result = (tex2D(msl_texture, msl_texture_uv));
  694. msl_alpha = msl_result.a;
  695. }
  696. }
  697.  
  698. void TGA_PhysicallBasedLighting_Shader_Inputs_Conversion_float_to_color_main(
  699. inout State state,
  700. float msl_scalar,
  701. out float4 msl_color)
  702. {
  703. {
  704. msl_color = (float4(msl_scalar, msl_scalar, msl_scalar, 1.0));
  705. }
  706. }
  707.  
  708. void TGA_PhysicallBasedLighting_Shader_Inputs_Math_color_pow_main(
  709. inout State state,
  710. float4 msl_base,
  711. float4 msl_exponent,
  712. out float4 msl_result)
  713. {
  714. {
  715. msl_result = (float4((pow((float4(msl_base)), (float4(msl_exponent))))));
  716. }
  717. }
  718.  
  719. void TGA_PhysicallBasedLighting_Shader_Inputs_Normals_make_normal_main(
  720. inout State state,
  721. float4 msl_color,
  722. float msl_amount,
  723. out float3 msl_result)
  724. {
  725. {
  726. float3 msl_n = (msl_color.xyz - 0.5) * 2.0;
  727. msl_n.xy *= msl_amount;
  728. msl_result = (normalize((mul(msl_n, (state.tangent_space)[0]))));
  729. }
  730. }
  731.  
  732. void TGA_PhysicallBasedLighting_Shader_Inputs_Conversion_color_to_float_main(
  733. inout State state,
  734. float4 msl_color,
  735. out float msl_scalar)
  736. {
  737. {
  738. msl_scalar = (((msl_color.r + msl_color.g) + msl_color.b) / 3.0);
  739. }
  740. }
  741.  
  742. void TGA_PhysicallBasedLighting_Shader_Inputs_main(
  743. inout State state,
  744. sampler2D msl_AlbedoTexture,
  745. float Albedo_Multiplier,
  746. sampler2D msl_NormalTexture,
  747. sampler2D msl_AOTexture,
  748. sampler2D msl_RoughnessTexture,
  749. float Roughness_Multiplier,
  750. sampler2D msl_SubstanceTexture,
  751. float Substance_Multiplier,
  752. out float4 msl_Albedo,
  753. out float3 msl_Normal,
  754. out float msl_AO,
  755. out float msl_Roughness,
  756. out float4 msl_Substance,
  757. float Normal_Multiplier
  758. )
  759.  
  760.  
  761. {
  762. {
  763. float4 msl_AlbedoGamma_RGB_result;
  764. float msl_AlbedoGamma_RGB_alpha;
  765. TGA_PhysicallBasedLighting_Shader_Inputs_Ext_texture_lookup_2d_alpha_main(state, msl_AlbedoTexture, (state.tex_coord)[0].xy, msl_AlbedoGamma_RGB_result, msl_AlbedoGamma_RGB_alpha);
  766. float4 msl_MyGamma_2_2_color;
  767. TGA_PhysicallBasedLighting_Shader_Inputs_Conversion_float_to_color_main(state, 2.200000, msl_MyGamma_2_2_color);
  768. float4 msl_AlbedoLinear_RGB_result;
  769. TGA_PhysicallBasedLighting_Shader_Inputs_Math_color_pow_main(state, msl_AlbedoGamma_RGB_result, msl_MyGamma_2_2_color, msl_AlbedoLinear_RGB_result);
  770. msl_Albedo = msl_AlbedoLinear_RGB_result * Albedo_Multiplier;
  771. float4 msl_Normal_RGB_result;
  772. float msl_Normal_RGB_alpha;
  773. TGA_PhysicallBasedLighting_Shader_Inputs_Ext_texture_lookup_2d_alpha_main(state, msl_NormalTexture, (state.tex_coord)[0].xy, msl_Normal_RGB_result, msl_Normal_RGB_alpha);
  774. float3 msl_Normals_make_normal_1_result;
  775. TGA_PhysicallBasedLighting_Shader_Inputs_Normals_make_normal_main(state, msl_Normal_RGB_result, Normal_Multiplier, msl_Normals_make_normal_1_result);
  776. msl_Normal = msl_Normals_make_normal_1_result;
  777. float4 msl_AOGamma_BW_result;
  778. float msl_AOGamma_BW_alpha;
  779. TGA_PhysicallBasedLighting_Shader_Inputs_Ext_texture_lookup_2d_alpha_main(state, msl_AOTexture, (state.tex_coord)[3].xy, msl_AOGamma_BW_result, msl_AOGamma_BW_alpha);
  780. float4 msl_AOLinear_BW_result;
  781. TGA_PhysicallBasedLighting_Shader_Inputs_Math_color_pow_main(state, msl_AOGamma_BW_result, msl_MyGamma_2_2_color, msl_AOLinear_BW_result);
  782. float msl_Conversion_color_to_float_1_scalar;
  783. TGA_PhysicallBasedLighting_Shader_Inputs_Conversion_color_to_float_main(state, msl_AOLinear_BW_result, msl_Conversion_color_to_float_1_scalar);
  784. msl_AO = msl_Conversion_color_to_float_1_scalar;
  785. float4 msl_RoughnessGamma_BW_result;
  786. float msl_RoughnessGamma_BW_alpha;
  787. TGA_PhysicallBasedLighting_Shader_Inputs_Ext_texture_lookup_2d_alpha_main(state, msl_RoughnessTexture, (state.tex_coord)[0].xy, msl_RoughnessGamma_BW_result, msl_RoughnessGamma_BW_alpha);
  788. float4 msl_RoughnessLinear_BW_result;
  789. TGA_PhysicallBasedLighting_Shader_Inputs_Math_color_pow_main(state, msl_RoughnessGamma_BW_result, msl_MyGamma_2_2_color, msl_RoughnessLinear_BW_result);
  790. float msl_Conversion_color_to_float_2_scalar;
  791. TGA_PhysicallBasedLighting_Shader_Inputs_Conversion_color_to_float_main(state, msl_RoughnessLinear_BW_result, msl_Conversion_color_to_float_2_scalar);
  792. msl_Roughness = msl_Conversion_color_to_float_2_scalar * Roughness_Multiplier;
  793. float4 msl_SubstanceGamma_RGB_result;
  794. float msl_SubstanceGamma_RGB_alpha;
  795. TGA_PhysicallBasedLighting_Shader_Inputs_Ext_texture_lookup_2d_alpha_main(state, msl_SubstanceTexture, (state.tex_coord)[0].xy, msl_SubstanceGamma_RGB_result, msl_SubstanceGamma_RGB_alpha);
  796. float4 msl_SubstanceLinear_RGB_result;
  797. TGA_PhysicallBasedLighting_Shader_Inputs_Math_color_pow_main(state, msl_SubstanceGamma_RGB_result, msl_MyGamma_2_2_color, msl_SubstanceLinear_RGB_result);
  798. msl_Substance = msl_SubstanceLinear_RGB_result * Substance_Multiplier;
  799. }
  800. }
  801.  
  802. void Light_directional_main(
  803. inout State state,
  804. float4 msl_color,
  805. float msl_intensity,
  806. out float4 msl_result,
  807. out float4 msl_light_shadow,
  808. inout float4x4 msl__state_transform_internal_to_light,
  809. inout float4x4 msl__state_transform_light_to_internal)
  810. {
  811. {
  812. msl_result = (float4(((float4(msl_color)) * msl_intensity)));
  813. msl_light_shadow = (float4(1,1,1,1));
  814. }
  815. }
  816.  
  817. void Light_directional_1_lightmain(
  818. inout State state,
  819. in float3 msl__state_light_position,
  820. in float3 msl__state_light_direction,
  821. in float4x4 msl__state_transform_internal_to_light,
  822. in float4x4 msl__state_transform_light_to_internal,
  823. out Light_iterator msl___light)
  824. {
  825. float3 msl__state_light_to_surface = (state.position) - msl__state_light_position;
  826. float msl__state_light_distance = length(msl__state_light_to_surface);
  827. msl__state_light_to_surface /= msl__state_light_distance;
  828. float msl__state_light_dot_nl = dot((-msl__state_light_direction), (state.normal));
  829. float4 msl_Light_directional_1_result;
  830. float4 msl_Light_directional_1_light_shadow;
  831. Light_directional_main(state, float4(msl_Light_directional_1_color,1), msl_Light_directional_1_intensity, msl_Light_directional_1_result, msl_Light_directional_1_light_shadow, msl__state_transform_internal_to_light, msl__state_transform_light_to_internal);
  832. msl___light.msl_point = msl__state_light_position;
  833. msl___light.msl_direction = (-msl__state_light_direction);
  834. msl___light.msl_distance = msl__state_light_distance;
  835. msl___light.msl_dot_nl = msl__state_light_dot_nl;
  836. msl___light.msl_raw_contribution = msl_Light_directional_1_result;
  837. msl___light.msl_contribution = msl_Light_directional_1_result;
  838. msl___light.msl_shadow = msl_Light_directional_1_light_shadow;
  839. msl___light.msl_count = 1;
  840. }
  841.  
  842. void Light_directional_2_lightmain(
  843. inout State state,
  844. in float3 msl__state_light_position,
  845. in float3 msl__state_light_direction,
  846. in float4x4 msl__state_transform_internal_to_light,
  847. in float4x4 msl__state_transform_light_to_internal,
  848. out Light_iterator msl___light)
  849. {
  850. float3 msl__state_light_to_surface = (state.position) - msl__state_light_position;
  851. float msl__state_light_distance = length(msl__state_light_to_surface);
  852. msl__state_light_to_surface /= msl__state_light_distance;
  853. float msl__state_light_dot_nl = dot((-msl__state_light_direction), (state.normal));
  854. float4 msl_Light_directional_2_result;
  855. float4 msl_Light_directional_2_light_shadow;
  856. Light_directional_main(state, float4(msl_Light_directional_2_color,1), msl_Light_directional_2_intensity, msl_Light_directional_2_result, msl_Light_directional_2_light_shadow, msl__state_transform_internal_to_light, msl__state_transform_light_to_internal);
  857. msl___light.msl_point = msl__state_light_position;
  858. msl___light.msl_direction = (-msl__state_light_direction);
  859. msl___light.msl_distance = msl__state_light_distance;
  860. msl___light.msl_dot_nl = msl__state_light_dot_nl;
  861. msl___light.msl_raw_contribution = msl_Light_directional_2_result;
  862. msl___light.msl_contribution = msl_Light_directional_2_result;
  863. msl___light.msl_shadow = msl_Light_directional_2_light_shadow;
  864. msl___light.msl_count = 1;
  865. }
  866.  
  867. void Light_directional_3_lightmain(
  868. inout State state,
  869. in float3 msl__state_light_position,
  870. in float3 msl__state_light_direction,
  871. in float4x4 msl__state_transform_internal_to_light,
  872. in float4x4 msl__state_transform_light_to_internal,
  873. out Light_iterator msl___light)
  874. {
  875. float3 msl__state_light_to_surface = (state.position) - msl__state_light_position;
  876. float msl__state_light_distance = length(msl__state_light_to_surface);
  877. msl__state_light_to_surface /= msl__state_light_distance;
  878. float msl__state_light_dot_nl = dot((-msl__state_light_direction), (state.normal));
  879. float4 msl_Light_directional_3_result;
  880. float4 msl_Light_directional_3_light_shadow;
  881. Light_directional_main(state, float4(msl_Light_directional_3_color,1), msl_Light_directional_3_intensity, msl_Light_directional_3_result, msl_Light_directional_3_light_shadow, msl__state_transform_internal_to_light, msl__state_transform_light_to_internal);
  882. msl___light.msl_point = msl__state_light_position;
  883. msl___light.msl_direction = (-msl__state_light_direction);
  884. msl___light.msl_distance = msl__state_light_distance;
  885. msl___light.msl_dot_nl = msl__state_light_dot_nl;
  886. msl___light.msl_raw_contribution = msl_Light_directional_3_result;
  887. msl___light.msl_contribution = msl_Light_directional_3_result;
  888. msl___light.msl_shadow = msl_Light_directional_3_light_shadow;
  889. msl___light.msl_count = 1;
  890. }
  891.  
  892. void Light_point_main(
  893. inout State state,
  894. float4 msl_color,
  895. float msl_intensity,
  896. float msl_distance_falloff_exponent,
  897. float msl_distance_scale,
  898. out float4 msl_result,
  899. out float4 msl_light_shadow,
  900. inout float4x4 msl__state_transform_internal_to_light,
  901. inout float msl__state_light_distance,
  902. inout float4x4 msl__state_transform_light_to_internal)
  903. {
  904. {
  905. float msl_attenuation = 1.0;
  906. if (msl_distance_falloff_exponent > (float(0)))
  907. {
  908. msl_attenuation = (pow((msl__state_light_distance * msl_distance_scale), (-msl_distance_falloff_exponent)));
  909. }
  910. msl_result = (float4((((float4(msl_color)) * msl_intensity) * msl_attenuation)));
  911. msl_light_shadow = (float4(1,1,1,1));
  912. }
  913. }
  914.  
  915. void Light_point_1_lightmain(
  916. inout State state,
  917. in float3 msl__state_light_position,
  918. in float4x4 msl__state_transform_internal_to_light,
  919. in float4x4 msl__state_transform_light_to_internal,
  920. out Light_iterator msl___light)
  921. {
  922. float3 msl__state_light_to_surface = (state.position) - msl__state_light_position;
  923. float msl__state_light_distance = length(msl__state_light_to_surface);
  924. msl__state_light_to_surface /= msl__state_light_distance;
  925. float msl__state_light_dot_nl = dot((-msl__state_light_to_surface), (state.normal));
  926. float4 msl_Light_point_1_result;
  927. float4 msl_Light_point_1_light_shadow;
  928. Light_point_main(state, float4(msl_Light_point_1_color,1), msl_Light_point_1_intensity, msl_Light_point_1_distance_falloff_exponent, msl_Light_point_1_distance_scale, msl_Light_point_1_result, msl_Light_point_1_light_shadow, msl__state_transform_internal_to_light, msl__state_light_distance, msl__state_transform_light_to_internal);
  929. msl___light.msl_point = msl__state_light_position;
  930. msl___light.msl_direction = (-msl__state_light_to_surface);
  931. msl___light.msl_distance = msl__state_light_distance;
  932. msl___light.msl_dot_nl = msl__state_light_dot_nl;
  933. msl___light.msl_raw_contribution = msl_Light_point_1_result;
  934. msl___light.msl_contribution = msl_Light_point_1_result;
  935. msl___light.msl_shadow = msl_Light_point_1_light_shadow;
  936. msl___light.msl_count = 1;
  937. }
  938.  
  939. void Light_point_2_lightmain(
  940. inout State state,
  941. in float3 msl__state_light_position,
  942. in float4x4 msl__state_transform_internal_to_light,
  943. in float4x4 msl__state_transform_light_to_internal,
  944. out Light_iterator msl___light)
  945. {
  946. float3 msl__state_light_to_surface = (state.position) - msl__state_light_position;
  947. float msl__state_light_distance = length(msl__state_light_to_surface);
  948. msl__state_light_to_surface /= msl__state_light_distance;
  949. float msl__state_light_dot_nl = dot((-msl__state_light_to_surface), (state.normal));
  950. float4 msl_Light_point_2_result;
  951. float4 msl_Light_point_2_light_shadow;
  952. Light_point_main(state, float4(msl_Light_point_2_color,1), msl_Light_point_2_intensity, msl_Light_point_2_distance_falloff_exponent, msl_Light_point_2_distance_scale, msl_Light_point_2_result, msl_Light_point_2_light_shadow, msl__state_transform_internal_to_light, msl__state_light_distance, msl__state_transform_light_to_internal);
  953. msl___light.msl_point = msl__state_light_position;
  954. msl___light.msl_direction = (-msl__state_light_to_surface);
  955. msl___light.msl_distance = msl__state_light_distance;
  956. msl___light.msl_dot_nl = msl__state_light_dot_nl;
  957. msl___light.msl_raw_contribution = msl_Light_point_2_result;
  958. msl___light.msl_contribution = msl_Light_point_2_result;
  959. msl___light.msl_shadow = msl_Light_point_2_light_shadow;
  960. msl___light.msl_count = 1;
  961. }
  962.  
  963. void Light_point_3_lightmain(
  964. inout State state,
  965. in float3 msl__state_light_position,
  966. in float4x4 msl__state_transform_internal_to_light,
  967. in float4x4 msl__state_transform_light_to_internal,
  968. out Light_iterator msl___light)
  969. {
  970. float3 msl__state_light_to_surface = (state.position) - msl__state_light_position;
  971. float msl__state_light_distance = length(msl__state_light_to_surface);
  972. msl__state_light_to_surface /= msl__state_light_distance;
  973. float msl__state_light_dot_nl = dot((-msl__state_light_to_surface), (state.normal));
  974. float4 msl_Light_point_3_result;
  975. float4 msl_Light_point_3_light_shadow;
  976. Light_point_main(state, float4(msl_Light_point_3_color,1), msl_Light_point_3_intensity, msl_Light_point_3_distance_falloff_exponent, msl_Light_point_3_distance_scale, msl_Light_point_3_result, msl_Light_point_3_light_shadow, msl__state_transform_internal_to_light, msl__state_light_distance, msl__state_transform_light_to_internal);
  977. msl___light.msl_point = msl__state_light_position;
  978. msl___light.msl_direction = (-msl__state_light_to_surface);
  979. msl___light.msl_distance = msl__state_light_distance;
  980. msl___light.msl_dot_nl = msl__state_light_dot_nl;
  981. msl___light.msl_raw_contribution = msl_Light_point_3_result;
  982. msl___light.msl_contribution = msl_Light_point_3_result;
  983. msl___light.msl_shadow = msl_Light_point_3_light_shadow;
  984. msl___light.msl_count = 1;
  985. }
  986.  
  987.  
  988. const float maxSpecularPower=8192;
  989.  
  990. void TGA_PhysicallBasedLighting_Shader_Ext_normalized_blinnphong_separated_main(
  991. inout State state,
  992. float4 msl_Substance,
  993. float msl_Roughness,
  994. out float4 msl_diffu,
  995. out float4 msl_specu)
  996. {
  997. float4 invSubstance=1-msl_Substance;
  998. {
  999. Light_iterator msl_light;
  1000. {
  1001. Light_directional_1_lightmain(state, float3(0,0,0), Directional1_Direction, msl_light0_transform_internal_to_light, msl_light0_transform_light_to_internal, msl_light);
  1002. {
  1003. float msl_ap = pow((float(maxSpecularPower)), msl_Roughness);
  1004. float3 VplusL =normalize(msl_light.msl_direction) + normalize(-(state.direction));
  1005. float3 msl_halfVec = normalize(VplusL);
  1006. float msl_LdotH = dot((normalize(msl_light.msl_direction)), msl_halfVec);
  1007. float msl_NdotH = dot((normalize((state.normal))), msl_halfVec);
  1008. float4 msl_fresnel = float4(((float4(msl_Substance)) + (((float(1)) - (float4(msl_Substance))) * (pow(((float(1)) - msl_LdotH), (float(5)))))));
  1009. float GeometryTerm =4/(dot(VplusL,VplusL));
  1010. float4 msl_spec = float4(((((((float(8)) + msl_ap) / (float(8))) * (float4(msl_fresnel))) * (pow((saturate(msl_NdotH)), msl_ap))) * ((float4(msl_light.msl_contribution)) * (saturate(msl_light.msl_dot_nl)))))*GeometryTerm;
  1011. float4 msl_diffusevalue = float4(((saturate(msl_light.msl_dot_nl)) * (float4(msl_light.msl_contribution))))*invSubstance;
  1012. msl_specu += msl_spec;
  1013. msl_diffu += msl_diffusevalue;
  1014. }
  1015. Light_directional_2_lightmain(state, float3(0,0,0), msl_light1_direction, msl_light1_transform_internal_to_light, msl_light1_transform_light_to_internal, msl_light);
  1016. {
  1017. float msl_ap = pow((float(maxSpecularPower)), msl_Roughness);
  1018. float3 VplusL =normalize(msl_light.msl_direction) + normalize(-(state.direction));
  1019. float3 msl_halfVec = normalize(VplusL);
  1020. float msl_LdotH = dot((normalize(msl_light.msl_direction)), msl_halfVec);
  1021. float msl_NdotH = dot((normalize((state.normal))), msl_halfVec);
  1022. float4 msl_fresnel = float4(((float4(msl_Substance)) + (((float(1)) - (float4(msl_Substance))) * (pow(((float(1)) - msl_LdotH), (float(5)))))));
  1023. float GeometryTerm =4/(dot(VplusL,VplusL));
  1024. float4 msl_spec = float4(((((((float(8)) + msl_ap) / (float(8))) * (float4(msl_fresnel))) * (pow((saturate(msl_NdotH)), msl_ap))) * ((float4(msl_light.msl_contribution)) * (saturate(msl_light.msl_dot_nl)))))*GeometryTerm;
  1025. float4 msl_diffusevalue = float4(((saturate(msl_light.msl_dot_nl)) * (float4(msl_light.msl_contribution))))*invSubstance;
  1026. msl_specu += msl_spec;
  1027. msl_diffu += msl_diffusevalue;
  1028. }
  1029. Light_directional_3_lightmain(state, float3(0,0,0), msl_light2_direction, msl_light2_transform_internal_to_light, msl_light2_transform_light_to_internal, msl_light);
  1030. {
  1031. float msl_ap = pow((float(maxSpecularPower)), msl_Roughness);
  1032. float3 VplusL =normalize(msl_light.msl_direction) + normalize(-(state.direction));
  1033. float3 msl_halfVec = normalize(VplusL);
  1034. float msl_LdotH = dot((normalize(msl_light.msl_direction)), msl_halfVec);
  1035. float msl_NdotH = dot((normalize((state.normal))), msl_halfVec);
  1036. float4 msl_fresnel = float4(((float4(msl_Substance)) + (((float(1)) - (float4(msl_Substance))) * (pow(((float(1)) - msl_LdotH), (float(5)))))));
  1037. float GeometryTerm =4/(dot(VplusL,VplusL));
  1038. float4 msl_spec = float4(((((((float(8)) + msl_ap) / (float(8))) * (float4(msl_fresnel))) * (pow((saturate(msl_NdotH)), msl_ap))) * ((float4(msl_light.msl_contribution)) * (saturate(msl_light.msl_dot_nl)))))*GeometryTerm;
  1039. float4 msl_diffusevalue = float4(((saturate(msl_light.msl_dot_nl)) * (float4(msl_light.msl_contribution))))*invSubstance;
  1040. msl_specu += msl_spec;
  1041. msl_diffu += msl_diffusevalue;
  1042. }
  1043. Light_point_1_lightmain(state, msl_light3_position, msl_light3_transform_internal_to_light, msl_light3_transform_light_to_internal, msl_light);
  1044. {
  1045. float msl_ap = pow((float(maxSpecularPower)), msl_Roughness);
  1046. float3 VplusL =normalize(msl_light.msl_direction) + normalize(-(state.direction));
  1047. float3 msl_halfVec = normalize(VplusL);
  1048. float msl_LdotH = dot((normalize(msl_light.msl_direction)), msl_halfVec);
  1049. float msl_NdotH = dot((normalize((state.normal))), msl_halfVec);
  1050. float4 msl_fresnel = float4(((float4(msl_Substance)) + (((float(1)) - (float4(msl_Substance))) * (pow(((float(1)) - msl_LdotH), (float(5)))))));
  1051. float GeometryTerm =4/(dot(VplusL,VplusL));
  1052. float4 msl_spec = float4(((((((float(8)) + msl_ap) / (float(8))) * (float4(msl_fresnel))) * (pow((saturate(msl_NdotH)), msl_ap))) * ((float4(msl_light.msl_contribution)) * (saturate(msl_light.msl_dot_nl)))))*GeometryTerm;
  1053. float4 msl_diffusevalue = float4(((saturate(msl_light.msl_dot_nl)) * (float4(msl_light.msl_contribution))))*invSubstance;
  1054. msl_specu += msl_spec;
  1055. msl_diffu += msl_diffusevalue;
  1056. }
  1057. Light_point_2_lightmain(state, msl_light4_position, msl_light4_transform_internal_to_light, msl_light4_transform_light_to_internal, msl_light);
  1058. {
  1059. float msl_ap = pow((float(maxSpecularPower)), msl_Roughness);
  1060. float3 VplusL =normalize(msl_light.msl_direction) + normalize(-(state.direction));
  1061. float3 msl_halfVec = normalize(VplusL);
  1062. float msl_LdotH = dot((normalize(msl_light.msl_direction)), msl_halfVec);
  1063. float msl_NdotH = dot((normalize((state.normal))), msl_halfVec);
  1064. float4 msl_fresnel = float4(((float4(msl_Substance)) + (((float(1)) - (float4(msl_Substance))) * (pow(((float(1)) - msl_LdotH), (float(5)))))));
  1065. float GeometryTerm =4/(dot(VplusL,VplusL));
  1066. float4 msl_spec = float4(((((((float(8)) + msl_ap) / (float(8))) * (float4(msl_fresnel))) * (pow((saturate(msl_NdotH)), msl_ap))) * ((float4(msl_light.msl_contribution)) * (saturate(msl_light.msl_dot_nl)))))*GeometryTerm;
  1067. float4 msl_diffusevalue = float4(((saturate(msl_light.msl_dot_nl)) * (float4(msl_light.msl_contribution))))*invSubstance;
  1068. msl_specu += msl_spec;
  1069. msl_diffu += msl_diffusevalue;
  1070. }
  1071. Light_point_3_lightmain(state, msl_light5_position, msl_light5_transform_internal_to_light, msl_light5_transform_light_to_internal, msl_light);
  1072. {
  1073. float msl_ap = pow((float(maxSpecularPower)), msl_Roughness);
  1074. float3 VplusL =normalize(msl_light.msl_direction) + normalize(-(state.direction));
  1075. float3 msl_halfVec = normalize(VplusL);
  1076. float msl_LdotH = dot((normalize(msl_light.msl_direction)), msl_halfVec);
  1077. float msl_NdotH = dot((normalize((state.normal))), msl_halfVec);
  1078. float4 msl_fresnel = float4(((float4(msl_Substance)) + (((float(1)) - (float4(msl_Substance))) * (pow(((float(1)) - msl_LdotH), (float(5)))))));
  1079. float GeometryTerm =4/(dot(VplusL,VplusL));
  1080. float4 msl_spec = float4(((((((float(8)) + msl_ap) / (float(8))) * (float4(msl_fresnel))) * (pow((saturate(msl_NdotH)), msl_ap))) * ((float4(msl_light.msl_contribution)) * (saturate(msl_light.msl_dot_nl)))))*GeometryTerm;
  1081. float4 msl_diffusevalue = float4(((saturate(msl_light.msl_dot_nl)) * (float4(msl_light.msl_contribution))))*invSubstance;
  1082. msl_specu += msl_spec;
  1083. msl_diffu += msl_diffusevalue;
  1084. }
  1085. }
  1086. msl_specu.a = 1.0;
  1087. msl_diffu.a = 1.0;
  1088. }
  1089. }
  1090.  
  1091. void tga_pbl_emissive_texture_lookup(
  1092. inout State state,
  1093. sampler2D msl_texture,
  1094. int msl_texture_space,
  1095. float2 msl_texture_uv,
  1096. out float4 msl_result)
  1097. {
  1098. {
  1099. msl_result = (tex2D(msl_texture, msl_texture_uv));
  1100. }
  1101. }
  1102.  
  1103.  
  1104. void TGA_PhysicallBasedLighting_Shader_ShadowMap_Texture_lookup_2d_main(
  1105. inout State state,
  1106. sampler2D msl_texture,
  1107. int msl_texture_space,
  1108. float2 msl_texture_uv,
  1109. out float4 msl_result)
  1110. {
  1111. {
  1112. msl_result = (tex2D(msl_texture, msl_texture_uv));
  1113. }
  1114. }
  1115.  
  1116. void TGA_PhysicallBasedLighting_Shader_ShadowMap_Math_color_multiply_main(
  1117. inout State state,
  1118. float4 msl_left,
  1119. float4 msl_right,
  1120. out float4 msl_result)
  1121. {
  1122. {
  1123. msl_result = (float4(((float4(msl_left)) * (float4(msl_right)))));
  1124. }
  1125. }
  1126.  
  1127. void TGA_PhysicallBasedLighting_Shader_ShadowMap_Math_color_conditional_main(
  1128. inout State state,
  1129. bool msl_condition,
  1130. float4 msl_true_value,
  1131. float4 msl_false_value,
  1132. out float4 msl_result)
  1133. {
  1134. {
  1135. msl_result = (msl_condition ? msl_true_value : msl_false_value);
  1136. }
  1137. }
  1138.  
  1139. void TGA_PhysicallBasedLighting_Shader_ShadowMap_main(
  1140. inout State state,
  1141. float4 msl_LightInput,
  1142. bool msl_UseShadowMap,
  1143. sampler2D msl_ShadowMap,
  1144. out float4 msl_result)
  1145. {
  1146. {
  1147. float4 msl_Texture_lookup_2d_1_result;
  1148. TGA_PhysicallBasedLighting_Shader_ShadowMap_Texture_lookup_2d_main(state, msl_ShadowMap, 0, (float2((state.tex_coord)[3].x, (state.tex_coord)[3].y)), msl_Texture_lookup_2d_1_result);
  1149. float4 msl_Math_color_multiply_6_result;
  1150. TGA_PhysicallBasedLighting_Shader_ShadowMap_Math_color_multiply_main(state, msl_LightInput, msl_Texture_lookup_2d_1_result, msl_Math_color_multiply_6_result);
  1151. float4 msl_Math_color_conditional_2_result;
  1152. TGA_PhysicallBasedLighting_Shader_ShadowMap_Math_color_conditional_main(state, msl_UseShadowMap, msl_Math_color_multiply_6_result, msl_LightInput, msl_Math_color_conditional_2_result);
  1153. msl_result = msl_Math_color_conditional_2_result;
  1154. }
  1155. }
  1156.  
  1157. void TGA_PhysicallBasedLighting_Shader_AmbientCube_State_normal_main(
  1158. inout State state,
  1159. out float3 msl_result)
  1160. {
  1161. {
  1162. msl_result = (state.normal);
  1163. }
  1164. }
  1165.  
  1166. void TGA_PhysicallBasedLighting_Shader_AmbientCube_Transform_internal_to_world_normal_main(
  1167. inout State state,
  1168. float3 msl_norm,
  1169. out float3 msl_result)
  1170. {
  1171. {
  1172. msl_result = (mul(msl_norm, (float3x3)__world_to_camera));
  1173. }
  1174. }
  1175.  
  1176. void TGA_PhysicallBasedLighting_Shader_AmbientCube_Conversion_float3_to_floats_main(
  1177. inout State state,
  1178. float3 msl_vector,
  1179. out float msl_x,
  1180. out float msl_y,
  1181. out float msl_z)
  1182. {
  1183. {
  1184. msl_x = msl_vector.x;
  1185. msl_y = msl_vector.y;
  1186. msl_z = msl_vector.z;
  1187. }
  1188. }
  1189.  
  1190. void TGA_PhysicallBasedLighting_Shader_AmbientCube_Conversion_floats_to_float3_main(
  1191. inout State state,
  1192. float msl_x,
  1193. float msl_y,
  1194. float msl_z,
  1195. out float3 msl_result)
  1196. {
  1197. {
  1198. msl_result = (float3(msl_x, msl_y, msl_z));
  1199. }
  1200. }
  1201.  
  1202. void TGA_PhysicallBasedLighting_Shader_AmbientCube_Math_float3_lerp_main(
  1203. inout State state,
  1204. float3 msl_start,
  1205. float3 msl_end,
  1206. float3 msl_location,
  1207. out float3 msl_result)
  1208. {
  1209. {
  1210. msl_result = (lerp(msl_start, msl_end, msl_location));
  1211. }
  1212. }
  1213.  
  1214. void TGA_PhysicallBasedLighting_Shader_AmbientCube_Ext_cube_mip_main(
  1215. inout State state,
  1216. samplerCUBE msl_texture,
  1217. int msl_texture_space,
  1218. float3 msl_texture_uvw,
  1219. float CubeRotation,
  1220. out float4 msl_result,
  1221. float4 fresnel)
  1222.  
  1223. {
  1224. {
  1225. float3 swivledUVW = float3(msl_texture_uvw.x, msl_texture_uvw.z, msl_texture_uvw.y);
  1226. float3 rotatedUVW;
  1227. rotatedUVW.x = cos(radians(CubeRotation))* swivledUVW.x + sin(radians(CubeRotation)) * swivledUVW.z;
  1228. rotatedUVW.y = swivledUVW.y;
  1229. rotatedUVW.z = -1 * sin(radians(CubeRotation)) * swivledUVW.x + cos(radians(CubeRotation)) * swivledUVW.z;
  1230.  
  1231. msl_result = (texCUBElod(msl_texture, float4(rotatedUVW,Ambient_Mip_Level)));
  1232. msl_result = pow(msl_result,2.2);
  1233. msl_result = (1-fresnel)*msl_result;
  1234. }
  1235. }
  1236.  
  1237. void TGA_PhysicallBasedLighting_Shader_AmbientCube_Math_color_conditional_main(
  1238. inout State state,
  1239. bool msl_condition,
  1240. float4 msl_true_value,
  1241. float4 msl_false_value,
  1242. out float4 msl_result)
  1243. {
  1244. {
  1245. msl_result = (msl_condition ? msl_true_value : msl_false_value);
  1246. }
  1247. }
  1248.  
  1249.  
  1250. void TGA_PhysicallBasedLighting_Shader_ReflectionCube_Ext_reflection_fresnel_main(
  1251. inout State state,
  1252. float4 msl_Substance,
  1253. float Roughness,
  1254. out float4 msl_result)
  1255. {
  1256. {
  1257. float msl_NdotV = dot((normalize((state.normal))), (normalize((-(state.direction)))));
  1258. float4 msl_fresnel = float4(((float4(msl_Substance)) + (((float(1)) - (float4(msl_Substance))) * (pow(((float(1)) - msl_NdotV), (float(5))))/(4-3*Roughness))));
  1259. msl_result = msl_fresnel;
  1260. }
  1261. }
  1262.  
  1263.  
  1264. void TGA_PhysicallBasedLighting_Shader_AmbientCube_main(
  1265. inout State state,
  1266. samplerCUBE msl_EnvironmentTexture,
  1267. float Cube_Multiplier,
  1268. float3 msl_NormalMapInput,
  1269. float3 msl_BlendLerp,
  1270. bool msl_UseBlendedNormals,
  1271. out float4 msl_result,
  1272. float4 Substance,
  1273. float Roughness
  1274. )
  1275. {
  1276. {
  1277. float3 msl_State_normal_2_result;
  1278. TGA_PhysicallBasedLighting_Shader_AmbientCube_State_normal_main(state, msl_State_normal_2_result);
  1279. float3 msl_Transform_internal_to_world_normal_2_result;
  1280. TGA_PhysicallBasedLighting_Shader_AmbientCube_Transform_internal_to_world_normal_main(state, msl_State_normal_2_result, msl_Transform_internal_to_world_normal_2_result);
  1281. float msl_Conversion_float3_to_floats_3_x;
  1282. float msl_Conversion_float3_to_floats_3_y;
  1283. float msl_Conversion_float3_to_floats_3_z;
  1284. TGA_PhysicallBasedLighting_Shader_AmbientCube_Conversion_float3_to_floats_main(state, msl_Transform_internal_to_world_normal_2_result, msl_Conversion_float3_to_floats_3_x, msl_Conversion_float3_to_floats_3_y, msl_Conversion_float3_to_floats_3_z);
  1285. float3 msl_Conversion_floats_to_float3_2_result;
  1286. TGA_PhysicallBasedLighting_Shader_AmbientCube_Conversion_floats_to_float3_main(state, msl_Conversion_float3_to_floats_3_x, msl_Conversion_float3_to_floats_3_z, msl_Conversion_float3_to_floats_3_y, msl_Conversion_floats_to_float3_2_result);
  1287. float3 msl_State_normal_1_result;
  1288. {
  1289. float3 msl__normal_temp = state.normal;
  1290. (state.normal) = msl_NormalMapInput;
  1291. TGA_PhysicallBasedLighting_Shader_AmbientCube_State_normal_main(state, msl_State_normal_1_result);
  1292. (state.normal) = msl__normal_temp;
  1293. }
  1294. float3 msl_Transform_internal_to_world_normal_1_result;
  1295. TGA_PhysicallBasedLighting_Shader_AmbientCube_Transform_internal_to_world_normal_main(state, msl_State_normal_1_result, msl_Transform_internal_to_world_normal_1_result);
  1296. float msl_Conversion_float3_to_floats_1_x;
  1297. float msl_Conversion_float3_to_floats_1_y;
  1298. float msl_Conversion_float3_to_floats_1_z;
  1299. TGA_PhysicallBasedLighting_Shader_AmbientCube_Conversion_float3_to_floats_main(state, msl_Transform_internal_to_world_normal_1_result, msl_Conversion_float3_to_floats_1_x, msl_Conversion_float3_to_floats_1_y, msl_Conversion_float3_to_floats_1_z);
  1300. float3 msl_Conversion_floats_to_float3_1_result;
  1301. TGA_PhysicallBasedLighting_Shader_AmbientCube_Conversion_floats_to_float3_main(state, msl_Conversion_float3_to_floats_1_x, msl_Conversion_float3_to_floats_1_z, msl_Conversion_float3_to_floats_1_y, msl_Conversion_floats_to_float3_1_result);
  1302. float3 msl_Math_float3_lerp_2_result;
  1303. TGA_PhysicallBasedLighting_Shader_AmbientCube_Math_float3_lerp_main(state, msl_Conversion_floats_to_float3_2_result, msl_Conversion_floats_to_float3_1_result, msl_BlendLerp, msl_Math_float3_lerp_2_result);
  1304. float4 msl_AmbientCube_result;
  1305.  
  1306.  
  1307. // HACK TO ADD
  1308. float4 fresnel=0;
  1309.  
  1310. TGA_PhysicallBasedLighting_Shader_ReflectionCube_Ext_reflection_fresnel_main(state,Substance,Roughness,fresnel);
  1311.  
  1312.  
  1313.  
  1314. TGA_PhysicallBasedLighting_Shader_AmbientCube_Ext_cube_mip_main(state, msl_EnvironmentTexture, 0, msl_Math_float3_lerp_2_result, CubeRotation, msl_AmbientCube_result,fresnel);
  1315. float4 msl_Ext_cube_mip_1_result;
  1316. TGA_PhysicallBasedLighting_Shader_AmbientCube_Ext_cube_mip_main(state, msl_EnvironmentTexture, 0, msl_Conversion_floats_to_float3_1_result, CubeRotation, msl_Ext_cube_mip_1_result,fresnel);
  1317. float4 msl_Math_color_conditional_3_result;
  1318. TGA_PhysicallBasedLighting_Shader_AmbientCube_Math_color_conditional_main(state, msl_UseBlendedNormals, msl_AmbientCube_result, msl_Ext_cube_mip_1_result, msl_Math_color_conditional_3_result);
  1319. msl_result = msl_Math_color_conditional_3_result * Cube_Multiplier;
  1320. }
  1321. }
  1322.  
  1323. void TGA_PhysicallBasedLighting_Shader_Math_color_multiply_main(
  1324. inout State state,
  1325. float4 msl_left,
  1326. float4 msl_right,
  1327. out float4 msl_result)
  1328. {
  1329. {
  1330. msl_result = (float4(((float4(msl_left)) * (float4(msl_right)))));
  1331. }
  1332. }
  1333.  
  1334. void TGA_PhysicallBasedLighting_Shader_BlendedNormals_Math_color_add_main(
  1335. inout State state,
  1336. float4 msl_left,
  1337. float4 msl_right,
  1338. out float4 msl_result)
  1339. {
  1340. {
  1341. msl_result = (float4(((float4(msl_left)) + (float4(msl_right)))));
  1342. }
  1343. }
  1344.  
  1345. void TGA_PhysicallBasedLighting_Shader_BlendedNormals_Conversion_color_to_float3_main(
  1346. inout State state,
  1347. float4 msl_color,
  1348. out float3 msl_vector)
  1349. {
  1350. {
  1351. msl_vector.x = msl_color.r;
  1352. msl_vector.y = msl_color.g;
  1353. msl_vector.z = msl_color.b;
  1354. }
  1355. }
  1356.  
  1357. void TGA_PhysicallBasedLighting_Shader_BlendedNormals_Math_float3_clamp_main(
  1358. inout State state,
  1359. float3 msl_input,
  1360. float3 msl_min,
  1361. float3 msl_max,
  1362. out float3 msl_result)
  1363. {
  1364. {
  1365. msl_result = (clamp(msl_input, msl_min, msl_max));
  1366. }
  1367. }
  1368.  
  1369. void TGA_PhysicallBasedLighting_Shader_BlendedNormals_Math_float3_lerp_main(
  1370. inout State state,
  1371. float3 msl_start,
  1372. float3 msl_end,
  1373. float3 msl_location,
  1374. out float3 msl_result)
  1375. {
  1376. {
  1377. msl_result = (lerp(msl_start, msl_end, msl_location));
  1378. }
  1379. }
  1380.  
  1381. void TGA_PhysicallBasedLighting_Shader_BlendedNormals_Conversion_float3_to_floats_main(
  1382. inout State state,
  1383. float3 msl_vector,
  1384. out float msl_x,
  1385. out float msl_y,
  1386. out float msl_z)
  1387. {
  1388. {
  1389. msl_x = msl_vector.x;
  1390. msl_y = msl_vector.y;
  1391. msl_z = msl_vector.z;
  1392. }
  1393. }
  1394.  
  1395. void TGA_PhysicallBasedLighting_Shader_BlendedNormals_Math_float_multiply_main(
  1396. inout State state,
  1397. float msl_left,
  1398. float msl_right,
  1399. out float msl_result)
  1400. {
  1401. {
  1402. msl_result = (msl_left * msl_right);
  1403. }
  1404. }
  1405.  
  1406. void TGA_PhysicallBasedLighting_Shader_BlendedNormals_Math_float_divide_main(
  1407. inout State state,
  1408. float msl_left,
  1409. float msl_right,
  1410. out float msl_result)
  1411. {
  1412. {
  1413. msl_result = (msl_left / msl_right);
  1414. }
  1415. }
  1416.  
  1417. void TGA_PhysicallBasedLighting_Shader_BlendedNormals_Math_float_add_main(
  1418. inout State state,
  1419. float msl_left,
  1420. float msl_right,
  1421. out float msl_result)
  1422. {
  1423. {
  1424. msl_result = (msl_left + msl_right);
  1425. }
  1426. }
  1427.  
  1428. void TGA_PhysicallBasedLighting_Shader_BlendedNormals_Math_float_min_main(
  1429. inout State state,
  1430. float msl_left,
  1431. float msl_right,
  1432. out float msl_result)
  1433. {
  1434. {
  1435. msl_result = (min(msl_left, msl_right));
  1436. }
  1437. }
  1438.  
  1439. void TGA_PhysicallBasedLighting_Shader_BlendedNormals_Conversion_floats_to_color_main(
  1440. inout State state,
  1441. float msl_r,
  1442. float msl_g,
  1443. float msl_b,
  1444. float msl_a,
  1445. out float4 msl_result)
  1446. {
  1447. {
  1448. msl_result = (float4(msl_r, msl_g, msl_b, msl_a));
  1449. }
  1450. }
  1451.  
  1452. void TGA_PhysicallBasedLighting_Shader_BlendedNormals_Math_color_conditional_main(
  1453. inout State state,
  1454. bool msl_condition,
  1455. float4 msl_true_value,
  1456. float4 msl_false_value,
  1457. out float4 msl_result)
  1458. {
  1459. {
  1460. msl_result = (msl_condition ? msl_true_value : msl_false_value);
  1461. }
  1462. }
  1463.  
  1464. void TGA_PhysicallBasedLighting_Shader_BlendedNormals_main(
  1465. inout State state,
  1466. float4 msl_NormalMap,
  1467. float4 msl_GeoNormals,
  1468. float3 msl_BlendLerps,
  1469. float msl_CyanSuppress,
  1470. bool msl_UseBlendedNormals,
  1471. float4 msl_AmbientLightInput,
  1472. out float4 msl_result)
  1473. {
  1474. {
  1475. float4 msl_Math_color_add_4_result;
  1476. TGA_PhysicallBasedLighting_Shader_BlendedNormals_Math_color_add_main(state, msl_GeoNormals, msl_AmbientLightInput, msl_Math_color_add_4_result);
  1477. float3 msl_Conversion_color_to_float3_1_vector;
  1478. TGA_PhysicallBasedLighting_Shader_BlendedNormals_Conversion_color_to_float3_main(state, msl_Math_color_add_4_result, msl_Conversion_color_to_float3_1_vector);
  1479. float4 msl_Math_color_add_1_result;
  1480. TGA_PhysicallBasedLighting_Shader_BlendedNormals_Math_color_add_main(state, msl_NormalMap, msl_AmbientLightInput, msl_Math_color_add_1_result);
  1481. float3 msl_Conversion_color_to_float3_2_vector;
  1482. TGA_PhysicallBasedLighting_Shader_BlendedNormals_Conversion_color_to_float3_main(state, msl_Math_color_add_1_result, msl_Conversion_color_to_float3_2_vector);
  1483. float3 msl_Math_float3_clamp_1_result;
  1484. TGA_PhysicallBasedLighting_Shader_BlendedNormals_Math_float3_clamp_main(state, msl_BlendLerps, (float3(0.0, 0.0, 0.0)), (float3(1.0, 1.0, 1.0)), msl_Math_float3_clamp_1_result);
  1485. float3 msl_Math_float3_lerp_1_result;
  1486. TGA_PhysicallBasedLighting_Shader_BlendedNormals_Math_float3_lerp_main(state, msl_Conversion_color_to_float3_1_vector, msl_Conversion_color_to_float3_2_vector, msl_Math_float3_clamp_1_result, msl_Math_float3_lerp_1_result);
  1487. float msl_Conversion_float3_to_floats_2_x;
  1488. float msl_Conversion_float3_to_floats_2_y;
  1489. float msl_Conversion_float3_to_floats_2_z;
  1490. TGA_PhysicallBasedLighting_Shader_BlendedNormals_Conversion_float3_to_floats_main(state, msl_Math_float3_lerp_1_result, msl_Conversion_float3_to_floats_2_x, msl_Conversion_float3_to_floats_2_y, msl_Conversion_float3_to_floats_2_z);
  1491. float msl_Math_float_multiply_1_result;
  1492. TGA_PhysicallBasedLighting_Shader_BlendedNormals_Math_float_multiply_main(state, msl_CyanSuppress, -1.000000, msl_Math_float_multiply_1_result);
  1493. float msl_Math_float_divide_2_result;
  1494. TGA_PhysicallBasedLighting_Shader_BlendedNormals_Math_float_divide_main(state, msl_Math_float_multiply_1_result, 10.000000, msl_Math_float_divide_2_result);
  1495. float msl_Math_float_add_1_result;
  1496. TGA_PhysicallBasedLighting_Shader_BlendedNormals_Math_float_add_main(state, msl_Math_float_divide_2_result, msl_Conversion_float3_to_floats_2_x, msl_Math_float_add_1_result);
  1497. float msl_Math_float_min_1_result;
  1498. TGA_PhysicallBasedLighting_Shader_BlendedNormals_Math_float_min_main(state, msl_Math_float_add_1_result, msl_Conversion_float3_to_floats_2_y, msl_Math_float_min_1_result);
  1499. float msl_Math_float_add_2_result;
  1500. TGA_PhysicallBasedLighting_Shader_BlendedNormals_Math_float_add_main(state, msl_Math_float_divide_2_result, msl_Conversion_float3_to_floats_2_x, msl_Math_float_add_2_result);
  1501. float msl_Math_float_min_2_result;
  1502. TGA_PhysicallBasedLighting_Shader_BlendedNormals_Math_float_min_main(state, msl_Math_float_add_2_result, msl_Conversion_float3_to_floats_2_z, msl_Math_float_min_2_result);
  1503. float4 msl_Conversion_floats_to_color_1_result;
  1504. TGA_PhysicallBasedLighting_Shader_BlendedNormals_Conversion_floats_to_color_main(state, msl_Conversion_float3_to_floats_2_x, msl_Math_float_min_1_result, msl_Math_float_min_2_result, 1.0, msl_Conversion_floats_to_color_1_result);
  1505. float4 msl_Math_color_conditional_1_result;
  1506. TGA_PhysicallBasedLighting_Shader_BlendedNormals_Math_color_conditional_main(state, msl_UseBlendedNormals, msl_Conversion_floats_to_color_1_result, msl_Math_color_add_1_result, msl_Math_color_conditional_1_result);
  1507. msl_result = msl_Math_color_conditional_1_result;
  1508. }
  1509. }
  1510.  
  1511. void TGA_PhysicallBasedLighting_Shader_Math_color_add_main(
  1512. inout State state,
  1513. float4 msl_left,
  1514. float4 msl_right,
  1515. out float4 msl_result)
  1516. {
  1517. {
  1518. msl_result = (float4(((float4(msl_left)) + (float4(msl_right)))));
  1519. }
  1520. }
  1521.  
  1522.  
  1523. void Environment_map_cubic_mip_main(
  1524. inout State state,
  1525. samplerCUBE msl_env_tex,
  1526. float msl_intensity,
  1527. sampler2D msl_texture,
  1528. float CubeRotation,
  1529. out float4 msl_result,
  1530. inout float3 msl__state_direction)
  1531. {
  1532. {
  1533. float roughness;
  1534. roughness = tex2D(msl_texture,state.tex_coord[0].xy).r;
  1535.  
  1536. float3 msl_v = mul((float3x3)__camera_to_world, msl__state_direction);
  1537.  
  1538. float3 rotatedUVW;
  1539. rotatedUVW.x = cos(radians(CubeRotation))* msl_v.x + sin(radians(CubeRotation)) * msl_v.z;
  1540. rotatedUVW.y = msl_v.y;
  1541. rotatedUVW.z = -1 * sin(radians(CubeRotation)) * msl_v.x + cos(radians(CubeRotation)) * msl_v.z;
  1542.  
  1543. msl_result = (texCUBElod((msl_env_tex), float4(rotatedUVW,(((Reflection_Max_Mip_Level)-(Reflection_Max_Mip_Level * roughness))))));
  1544. msl_result *= msl_intensity;
  1545. msl_result = pow(msl_result,2.2);
  1546. }
  1547. }
  1548.  
  1549. void Environment_map_cubic_mip_1_environmentmain(
  1550. inout State state,
  1551. in float3 msl__state_direction,
  1552. float Cube_Multiplier,
  1553. out float4 msl___result)
  1554. {
  1555. float4 cube_mult;
  1556. cube_mult = float4(Cube_Multiplier,Cube_Multiplier,Cube_Multiplier,Cube_Multiplier);
  1557. float4 msl_Environment_map_cubic_mip_1_result;
  1558. Environment_map_cubic_mip_main(state, Environment_Cube_Gamma, float(1.0), Roughness_Texture_Gamma, CubeRotation, msl_Environment_map_cubic_mip_1_result, msl__state_direction);
  1559. msl___result = msl_Environment_map_cubic_mip_1_result * cube_mult;
  1560. }
  1561.  
  1562.  
  1563. //{
  1564. // float4 msl_Environment_map_cubic_mip_1_result;
  1565. // Environment_map_cubic_mip_main(state, Environment_Cube_Gamma, float(1.0), Roughness_Texture_Gamma, CubeRotation, msl_Environment_map_cubic_mip_1_result, msl__state_direction);
  1566. // msl___result = msl_Environment_map_cubic_mip_1_result;
  1567. //}
  1568.  
  1569.  
  1570.  
  1571.  
  1572.  
  1573. float4 __trace_environment(
  1574. inout State state,
  1575. Ray msl_ray)
  1576. {
  1577. float4 msl_result;
  1578. Environment_map_cubic_mip_1_environmentmain(state, msl_ray.msl_direction, Cube_Multiplier, msl_result);
  1579. return msl_result;
  1580. }
  1581.  
  1582. void TGA_PhysicallBasedLighting_Shader_ReflectionCube_Component_reflection_main(
  1583. inout State state,
  1584. out float4 msl_result)
  1585. {
  1586. {
  1587. float3 msl_reflected = reflect((state.direction), (state.normal));
  1588. msl_result = (float4(0.0));
  1589. Ray msl_ray = Ray((state.position), msl_reflected);
  1590. Ray msl_ray_dx = Ray((float3((float(0)))), (float3((float(0)))));
  1591. Ray msl_ray_dy = Ray((float3((float(0)))), (float3((float(0)))));
  1592. int msl_trace_opt = 13;
  1593. msl_trace_opt = 13;
  1594. if (!(((((msl_trace_opt == 3) || (msl_trace_opt == 13)) || (msl_trace_opt == 12)) || (msl_trace_opt == 11)) ? (((msl_result = (__trace_environment(state, msl_ray))), true)) : false))
  1595. {
  1596. msl_trace_opt = 3;
  1597. ((((msl_trace_opt == 3) || (msl_trace_opt == 13)) || (msl_trace_opt == 12)) || (msl_trace_opt == 11)) ? (((msl_result = (__trace_environment(state, msl_ray))), true)) : false;
  1598. }
  1599. }
  1600. }
  1601.  
  1602. void TGA_PhysicallBasedLighting_Shader_ReflectionCube_Math_color_multiply_main(
  1603. inout State state,
  1604. float4 msl_left,
  1605. float4 msl_right,
  1606. out float4 msl_result)
  1607. {
  1608. {
  1609. msl_result = (float4(((float4(msl_left)) * (float4(msl_right)))));
  1610. }
  1611. }
  1612.  
  1613. void TGA_PhysicallBasedLighting_Shader_ReflectionCube_main(
  1614. inout State state,
  1615. float4 msl_SubstanceInput,
  1616. float3 msl_Inputs_1_Normal,
  1617. float Roughness,
  1618. out float4 msl_result
  1619.  
  1620. )
  1621. {
  1622. {
  1623. float4 msl_Ext_reflection_fresnel_1_result;
  1624. TGA_PhysicallBasedLighting_Shader_ReflectionCube_Ext_reflection_fresnel_main(state, msl_SubstanceInput,Roughness, msl_Ext_reflection_fresnel_1_result);
  1625. float4 msl_Component_reflection_1_result;
  1626. float3 msl__normal_temp = state.normal;
  1627. (state.normal) = msl_Inputs_1_Normal;
  1628. TGA_PhysicallBasedLighting_Shader_ReflectionCube_Component_reflection_main(state, msl_Component_reflection_1_result);
  1629. (state.normal) = msl__normal_temp;
  1630. float4 msl_Math_color_multiply_2_result;
  1631. TGA_PhysicallBasedLighting_Shader_ReflectionCube_Math_color_multiply_main(state, msl_Ext_reflection_fresnel_1_result, msl_Component_reflection_1_result, msl_Math_color_multiply_2_result);
  1632. msl_result = msl_Math_color_multiply_2_result;
  1633. }
  1634. }
  1635.  
  1636. void TGA_PhysicallBasedLighting_Shader_Math_float_divide_main(
  1637. inout State state,
  1638. float msl_left,
  1639. float msl_right,
  1640. out float msl_result)
  1641. {
  1642. {
  1643. msl_result = (msl_left / msl_right);
  1644. }
  1645. }
  1646.  
  1647. void TGA_PhysicallBasedLighting_Shader_Math_color_pow_main(
  1648. inout State state,
  1649. float4 msl_base,
  1650. float4 msl_exponent,
  1651. out float4 msl_result)
  1652. {
  1653. {
  1654. msl_result = (float4((pow((float4(msl_base)), (float4(msl_exponent))))));
  1655. }
  1656. }
  1657.  
  1658. void TGA_PhysicallBasedLighting_Shader_main(
  1659. inout State state,
  1660. sampler2D msl_AlbedoTexture,
  1661. float Albedo_Multiplier,
  1662. sampler2D msl_NormalTexture,
  1663. sampler2D msl_AOTexture,
  1664. sampler2D msl_RoughnessTexture,
  1665. float Roughness_Multiplier,
  1666. sampler2D msl_SubstanceTexture,
  1667. float Substance_Multiplier,
  1668. samplerCUBE msl_AmbEnvTex,
  1669. float Cube_Multiplier,
  1670. float msl_SimpleExposure,
  1671. bool msl_UseBlendedNormals,
  1672. float msl_CyanSuppress,
  1673. float3 msl_BlendLerps,
  1674. bool msl_UseEmissiveMap,
  1675. sampler2D msl_EmissiveTexture,
  1676. bool msl_UseShadowMap,
  1677. sampler2D msl_ShadowMap,
  1678. out float4 msl_result,
  1679. float Normal_Multiplier)
  1680. {
  1681. {
  1682. float4 msl_SimpleExposure_color;
  1683. TGA_PhysicallBasedLighting_Shader_Conversion_float_to_color_main(state, msl_SimpleExposure, msl_SimpleExposure_color);
  1684. float4 msl_Inputs_1_Albedo;
  1685. float3 msl_Inputs_1_Normal;
  1686. float msl_Inputs_1_AO;
  1687. float msl_Inputs_1_Roughness;
  1688. float4 msl_Inputs_1_Substance;
  1689. float4 InvSubstance;
  1690. TGA_PhysicallBasedLighting_Shader_Inputs_main(state, msl_AlbedoTexture, Albedo_Multiplier, msl_NormalTexture, msl_AOTexture, msl_RoughnessTexture, Roughness_Multiplier, msl_SubstanceTexture, Substance_Multiplier, msl_Inputs_1_Albedo, msl_Inputs_1_Normal, msl_Inputs_1_AO, msl_Inputs_1_Roughness, msl_Inputs_1_Substance,Normal_Multiplier);
  1691. InvSubstance=1.0-msl_Inputs_1_Substance;
  1692. float4 msl_Ext_normalized_blinnphong_separated_2_diffu;
  1693. float4 msl_Ext_normalized_blinnphong_separated_2_specu;
  1694. {
  1695. float3 msl__normal_temp = state.normal;
  1696. (state.normal) = msl_Inputs_1_Normal;
  1697. TGA_PhysicallBasedLighting_Shader_Ext_normalized_blinnphong_separated_main(state, msl_Inputs_1_Substance, msl_Inputs_1_Roughness, msl_Ext_normalized_blinnphong_separated_2_diffu, msl_Ext_normalized_blinnphong_separated_2_specu);
  1698. (state.normal) = msl__normal_temp;
  1699. }
  1700. float4 msl_ShadowMap_3_result;
  1701. TGA_PhysicallBasedLighting_Shader_ShadowMap_main(state, msl_Ext_normalized_blinnphong_separated_2_specu, msl_UseShadowMap, msl_ShadowMap, msl_ShadowMap_3_result);
  1702. float4 msl_ShadowMap_1_result;
  1703. TGA_PhysicallBasedLighting_Shader_ShadowMap_main(state, msl_Ext_normalized_blinnphong_separated_2_diffu, msl_UseShadowMap, msl_ShadowMap, msl_ShadowMap_1_result);
  1704. float4 msl_Ext_normalized_blinnphong_separated_1_diffu;
  1705. float4 msl_Ext_normalized_blinnphong_separated_1_specu;
  1706. TGA_PhysicallBasedLighting_Shader_Ext_normalized_blinnphong_separated_main(state, msl_Inputs_1_Substance, msl_Inputs_1_Roughness, msl_Ext_normalized_blinnphong_separated_1_diffu, msl_Ext_normalized_blinnphong_separated_1_specu);
  1707. float4 msl_ShadowMap_2_result;
  1708. TGA_PhysicallBasedLighting_Shader_ShadowMap_main(state, msl_Ext_normalized_blinnphong_separated_1_diffu, msl_UseShadowMap, msl_ShadowMap, msl_ShadowMap_2_result);
  1709. float4 msl_AO_float_to_color_color;
  1710. TGA_PhysicallBasedLighting_Shader_Conversion_float_to_color_main(state, msl_Inputs_1_AO, msl_AO_float_to_color_color);
  1711. float4 msl_AmbientCube_1_result;
  1712. {
  1713. float3 msl__normal_temp = state.normal;
  1714. TGA_PhysicallBasedLighting_Shader_AmbientCube_main(state, msl_AmbEnvTex, Cube_Multiplier, msl_Inputs_1_Normal, msl_BlendLerps, msl_UseBlendedNormals, msl_AmbientCube_1_result,msl_Inputs_1_Substance,msl_Inputs_1_Roughness);
  1715. (state.normal) = msl__normal_temp;
  1716. }
  1717. float4 msl_Math_color_multiply_4_result;
  1718. TGA_PhysicallBasedLighting_Shader_Math_color_multiply_main(state, msl_AO_float_to_color_color, msl_AmbientCube_1_result, msl_Math_color_multiply_4_result);
  1719. float4 msl_BlendedNormals_1_result;
  1720. TGA_PhysicallBasedLighting_Shader_BlendedNormals_main(state, msl_ShadowMap_1_result, msl_ShadowMap_2_result, msl_BlendLerps, msl_CyanSuppress, msl_UseBlendedNormals, msl_Math_color_multiply_4_result, msl_BlendedNormals_1_result);
  1721. float4 msl_Math_color_multiply_5_result;
  1722. TGA_PhysicallBasedLighting_Shader_Math_color_multiply_main(state, msl_BlendedNormals_1_result, msl_Inputs_1_Albedo, msl_Math_color_multiply_5_result);
  1723. float4 msl_Math_color_add_3_result;
  1724. TGA_PhysicallBasedLighting_Shader_Math_color_add_main(state, msl_ShadowMap_3_result, msl_Math_color_multiply_5_result, msl_Math_color_add_3_result);
  1725. float4 msl_ReflectionCube_1_result;
  1726. TGA_PhysicallBasedLighting_Shader_ReflectionCube_main(state, msl_Inputs_1_Substance, msl_Inputs_1_Normal,msl_Inputs_1_Roughness, msl_ReflectionCube_1_result);
  1727. float4 msl_Math_color_multiply_1_result;
  1728. TGA_PhysicallBasedLighting_Shader_Math_color_multiply_main(state, msl_AO_float_to_color_color, msl_ReflectionCube_1_result, msl_Math_color_multiply_1_result);
  1729. float4 msl_Math_color_add_2_result;
  1730. TGA_PhysicallBasedLighting_Shader_Math_color_add_main(state, msl_Math_color_add_3_result, msl_Math_color_multiply_1_result, msl_Math_color_add_2_result);
  1731. float4 msl_Math_color_multiply_3_result;
  1732. TGA_PhysicallBasedLighting_Shader_Math_color_multiply_main(state, msl_SimpleExposure_color, msl_Math_color_add_2_result, msl_Math_color_multiply_3_result);
  1733. float msl_Math_float_divide_1_result;
  1734. TGA_PhysicallBasedLighting_Shader_Math_float_divide_main(state, 1.0, 2.200000, msl_Math_float_divide_1_result);
  1735. float4 msl_Conversion_float_to_color_1_color;
  1736. TGA_PhysicallBasedLighting_Shader_Conversion_float_to_color_main(state, msl_Math_float_divide_1_result, msl_Conversion_float_to_color_1_color);
  1737. float4 msl_Math_color_pow_1_result;
  1738. TGA_PhysicallBasedLighting_Shader_Math_color_pow_main(state, msl_Math_color_multiply_3_result, msl_Conversion_float_to_color_1_color, msl_Math_color_pow_1_result);
  1739.  
  1740. float4 msl_EmissiveTexture_result;
  1741. tga_pbl_emissive_texture_lookup(state, msl_EmissiveTexture, 0, (float2((state.tex_coord)[3].x, (state.tex_coord)[3].y)), msl_EmissiveTexture_result);
  1742.  
  1743. bool msl_UseEmissiveMap = Use_Emissive_Map;
  1744. msl_result = msl_Math_color_pow_1_result + (msl_EmissiveTexture_result * msl_UseEmissiveMap);
  1745. msl_result.a = msl_Inputs_1_Albedo.a;
  1746. }
  1747. }
  1748.  
  1749. //
  1750. // The following method is the root function of the shader graph
  1751. //
  1752. float4 TGA_PhysicallBasedLighting_Shader_1_eval(State state, out FS_OUT eval_out)
  1753. {
  1754. // primary_out:
  1755. float4 msl_result;
  1756. {
  1757. float3 msl__normal_temp = state.normal;
  1758. TGA_PhysicallBasedLighting_Shader_main(state, Albedo_Texture_Gamma, Albedo_Multiplier, Normal_Texture_Linear, AO_Texture_Gamma_TEXCOORD3, Roughness_Texture_Gamma, Roughness_Multiplier, Substance_Texture_Gamma, Substance_Multiplier, Environment_Cube_Gamma, Cube_Multiplier, Exposure, UseBlendedNormals, Cyan_Suppress, Blend_Lerps, Use_Emissive_Map, Emissive_Texture, Use_Shadow_Map, Shadow_Map, msl_result,Normal_Multiplier);
  1759. (state.normal) = msl__normal_temp;
  1760. }
  1761. eval_out = float4(msl_result);
  1762. return float4(msl_result);
  1763. }
  1764.  
  1765. //
  1766. // This function is the main method of the fragment shader. It initializes the
  1767. // values in the state structure that are used by nodes in the shader graph
  1768. // and produces the final result of the shader.
  1769. //
  1770. FS_OUT fragment_main(
  1771. Vert2frag fs_in) : COLOR
  1772. {
  1773. State state;
  1774. state.position = fs_in.position;
  1775. state.normal = normalize(fs_in.normal);
  1776. state.tex_coord = fs_in.tex_coord;
  1777. state.origin = 0;
  1778. state.ray_length = length(state.position);
  1779. state.direction = state.position/state.ray_length;
  1780. float3 t_tex_tangent, t_tex_binormal;
  1781. __make_basis(state.normal, fs_in.tex_du, fs_in.tex_dv, t_tex_tangent, t_tex_binormal);
  1782. state.tangent_space[0] = float3x3(
  1783. t_tex_tangent,
  1784. t_tex_binormal,
  1785. state.normal);
  1786.  
  1787. FS_OUT eval_out; // multiple shader outputs
  1788. float4 primary_out; // primary shader output
  1789. primary_out = TGA_PhysicallBasedLighting_Shader_1_eval(state, eval_out);
  1790. FS_OUT fs_out;
  1791. fs_out = primary_out;
  1792. return fs_out;
  1793. }
  1794.  
  1795. //
  1796. // The following define the default technique and pass of the effect.
  1797. //
  1798. technique NoTransparency
  1799. {
  1800. pass P0
  1801. {
  1802. DepthTestEnable = true;
  1803. DepthMask = true;
  1804. CullFaceEnable = true;
  1805. VertexShader = compile vp40 vertex_main();
  1806. PixelShader = compile fp40 fragment_main();
  1807. }
  1808. }
  1809.  
  1810. technique TransparencyUsingAlbedoAlpha
  1811. {
  1812. pass P0
  1813. {
  1814. DepthTestEnable = true;
  1815. DepthMask = true;
  1816. CullFaceEnable = true;
  1817. BlendEnable = true;
  1818. blendfunc = int2(srcalpha, oneminussrcalpha);
  1819. VertexShader = compile vp40 vertex_main();
  1820. PixelShader = compile fp40 fragment_main();
  1821. }
  1822. }
  1823.  
  1824. string description = "TGA Physically Based Lighting Shader v0.3.4.2";
Advertisement
Add Comment
Please, Sign In to add comment