SHARE
TWEET

Thrive shader

a guest Dec 22nd, 2018 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #if 0
  2.     *** [Hash 0x010d84dd]   2
  3.     *** [Hash 0x06285893]   0
  4.     *** [Hash 0x0790ba12]   4
  5.     *** [Hash 0x086bb3a6]   0
  6.     *** [Hash 0x0b4678e4]   1
  7.     *** [Hash 0x0c7e761b]   4
  8.     *** [Hash 0x1185e86f]   0
  9.     *** [Hash 0x123606a9]   0
  10.     *** [Hash 0x15cb74a1]   0
  11.     *** [Hash 0x19a61682]   1
  12.     *** [Hash 0x1af900a2]   1
  13.     *** [Hash 0x1b0c2b69]   0
  14.     *** [Hash 0x1bab8cdd]   0
  15.     *** [Hash 0x1bb5acac]   0
  16.     *** [Hash 0x1e8b5671]   50000
  17.     *** [Hash 0x1f2c6e82]   0
  18.     *** [Hash 0x201f84c0]   0
  19.     *** [Hash 0x22caa76a]   0
  20.     *** [Hash 0x25dc73c6]   635204550
  21.     *** [Hash 0x26249384]   42857
  22.     *** [Hash 0x2a892b58]   0
  23.     *** [Hash 0x2cb6ab02]   0
  24.     *** [Hash 0x2dd3a2cd]   0
  25.     *** [Hash 0x354d66c0]   3
  26.     *** [Hash 0x359e8062]   1
  27.     *** [Hash 0x360c3db1]   0
  28.     *** [Hash 0x39384d5a]   28571
  29.     *** [Hash 0x3b038020]   0
  30.     *** [Hash 0x3dde9817]   1
  31.     *** [Hash 0x3f315fff]   0
  32.     *** [Hash 0x3fcb60f1]   1070293233
  33.     *** [Hash 0x415a738b]   0
  34.     *** [Hash 0x4508a85c]   1
  35.     *** [Hash 0x45d6475f]   0
  36.     *** [Hash 0x46bba485]   0
  37.     *** [Hash 0x491233c3]   0
  38.     *** [Hash 0x4956ca9a]   1
  39.     *** [Hash 0x4ec19020]   1
  40.     *** [Hash 0x51de8f13]   42857
  41.     *** [Hash 0x549bb006]   0
  42.     *** [Hash 0x55683ca9]   1
  43.     *** [Hash 0x57643473]   3
  44.     *** [Hash 0x5a1459c4]   1
  45.     *** [Hash 0x5a23f9f0]   0
  46.     *** [Hash 0x5ca459ef]   0
  47.     *** [Hash 0x5cb4719a]   1
  48.     *** [Hash 0x5dbe1dca]   1
  49.     *** [Hash 0x61e63948]   1
  50.     *** [Hash 0x66ac9d57]   0
  51.     *** [Hash 0x675280f4]   0
  52.     *** [Hash 0x6962e498]   1
  53.     *** [Hash 0x6be92c72]   0
  54.     *** [Hash 0x6bf5b20f]   1
  55.     *** [Hash 0x6d28c426]   1
  56.     *** [Hash 0x6f177a79]   0
  57.     *** [Hash 0x701971ed]   1
  58.     *** [Hash 0x717564b5]   0
  59.     *** [Hash 0x74824502]   1
  60.     *** [Hash 0x790cdbbe]   1
  61.     *** [Hash 0x7a148ebc]   0
  62.     *** [Hash 0x7ae862a6]   0
  63.     *** [Hash 0x7e693a86]   2
  64.     *** [Hash 0x7e8dec1c]   0
  65.     *** [Hash 0x7e934f0e]   0
  66.     *** [Hash 0x8040ea88]   28571
  67.     *** [Hash 0x8045c1b4]   1
  68.     *** [Hash 0x840f5b80]   0
  69.     *** [Hash 0x8421366d]   256
  70.     *** [Hash 0x86319b9f]   1
  71.     *** [Hash 0x866a0bb6]   0
  72.     *** [Hash 0x875516cf]   1
  73.     *** [Hash 0x8857c26f]   0
  74.     *** [Hash 0x91f755f3]   0
  75.     *** [Hash 0x92baf270]   0
  76.     *** [Hash 0x93f2327b]   635204550
  77.     *** [Hash 0x94b1117a]   1
  78.     *** [Hash 0x962aeb1a]   1
  79.     *** [Hash 0x96c12323]   1
  80.     *** [Hash 0x9abd84b5]   -1698855755
  81.     *** [Hash 0xa1b3cd70]   1
  82.     *** [Hash 0xa461daa9]   1
  83.     *** [Hash 0xa62cee23]   0
  84.     *** [Hash 0xa69f72d5]   0
  85.     *** [Hash 0xa6ac776b]   0
  86.     *** [Hash 0xa7fb3663]   1
  87.     *** [Hash 0xa89ac41a]   1
  88.     *** [Hash 0xa90324bb]   0
  89.     *** [Hash 0xadc70c72]   1
  90.     *** [Hash 0xafaf1bb3]   450
  91.     *** [Hash 0xb0e4cb8e]   0
  92.     *** [Hash 0xb22f037a]   0
  93.     *** [Hash 0xb7b857ae]   1
  94.     *** [Hash 0xb9201184]   0
  95.     *** [Hash 0xb967bb7b]   0
  96.     *** [Hash 0xbc128c23]   0
  97.     *** [Hash 0xc377e795]   50000
  98.     *** [Hash 0xc46d5eba]   1
  99.     *** [Hash 0xc5ed03e2]   1
  100.     *** [Hash 0xc7cccc57]   0
  101.     *** [Hash 0xcb33bcfe]   0
  102.     *** [Hash 0xcef10401]   1
  103.     *** [Hash 0xd17f1d1c]   1
  104.     *** [Hash 0xd7ec9987]   1
  105.     *** [Hash 0xdc23368e]   0
  106.     *** [Hash 0xe40b2520]   1
  107.     *** [Hash 0xe7bd0fde]   0
  108.     *** [Hash 0xe9b3b96d]   0
  109.     *** [Hash 0xe9c0285b]   0
  110.     *** [Hash 0xea1519fa]   1
  111.     *** [Hash 0xebfcdcac]   28571
  112.     *** [Hash 0xec133132]   -334286542
  113.     *** [Hash 0xec4e19ce]   0
  114.     *** [Hash 0xf6eb512d]   0
  115.     *** [Hash 0xf742ff75]   1
  116.     DONE DUMPING PROPERTIES
  117.     DONE DUMPING PIECES
  118. #endif
  119.  
  120. #version 430 core
  121.  
  122.  
  123.     #extension GL_ARB_shading_language_420pack: require
  124.     #define layout_constbuffer(x) layout( std140, x )
  125.  
  126.     #define bufferFetch texelFetch
  127.  
  128. #define float2 vec2
  129. #define float3 vec3
  130. #define float4 vec4
  131.  
  132. #define int2 ivec2
  133. #define int3 ivec3
  134. #define int4 ivec4
  135.  
  136. #define uint2 uvec2
  137. #define uint3 uvec3
  138. #define uint4 uvec4
  139.  
  140. #define float3x3 mat3
  141. #define float4x4 mat4
  142.  
  143. #define mul( x, y ) ((x) * (y))
  144. #define saturate(x) clamp( (x), 0.0, 1.0 )
  145. #define lerp mix
  146. #define INLINE
  147.  
  148. #define outVs_Position gl_Position
  149. #define OGRE_SampleLevel( tex, sampler, uv, lod ) textureLod( tex, uv.xy, lod )
  150.  
  151.  
  152. #extension GL_ARB_texture_gather: require#extension GL_AMD_shader_trinary_minmax: require
  153.  
  154. layout(std140) uniform;
  155. #define FRAG_COLOR      0
  156.  
  157.    
  158.        
  159.             layout(location = FRAG_COLOR, index = 0) out vec4 outColour;
  160.            
  161.  
  162.  
  163.  
  164.  
  165.  
  166. // START UNIFORM DECLARATION
  167.  
  168.    
  169.        
  170. struct ShadowReceiverData
  171. {
  172.     mat4 texViewProj;
  173.     vec2 shadowDepthRange;
  174.     vec4 invShadowMapSize;
  175. };
  176.  
  177. struct Light
  178. {
  179.     vec4 position; //.w contains the objLightMask
  180.     vec3 diffuse;
  181.     vec3 specular;
  182.  
  183.     vec3 attenuation;
  184.     vec3 spotDirection;
  185.     vec3 spotParams;
  186. };
  187.  
  188.  
  189.  
  190. //Uniforms that change per pass
  191. layout_constbuffer(binding = 0) uniform PassBuffer
  192. {
  193.     //Vertex shader (common to both receiver and casters)
  194.     mat4 viewProj;
  195.  
  196.  
  197.  
  198.  
  199.     //Vertex shader
  200.     mat4 view;
  201.     ShadowReceiverData shadowRcv[3];
  202.     //-------------------------------------------------------------------------
  203.  
  204.     //Pixel shader
  205.     mat3 invViewMatCubemap;
  206.  
  207.  
  208.  
  209.  
  210.     vec4 ambientUpperHemi;
  211.  
  212.     vec4 ambientLowerHemi;
  213.     vec4 ambientHemisphereDir;
  214.  
  215.  
  216.  
  217.     float pssmSplitPoints0;
  218.     float pssmSplitPoints1;
  219.     float pssmSplitPoints2; Light lights[1];
  220.  
  221.    
  222.  
  223.  
  224.    
  225. } passBuf;
  226.  
  227.        
  228. //Uniforms that change per Item/Entity, but change very infrequently
  229. struct Material
  230. {
  231.     /* kD is already divided by PI to make it energy conserving.
  232.       (formula is finalDiffuse = NdotL * surfaceDiffuse / PI)
  233.     */
  234.     vec4 bgDiffuse;
  235.     vec4 kD; //kD.w is alpha_test_threshold
  236.     vec4 kS; //kS.w is roughness
  237.     //Fresnel coefficient, may be per colour component (vec3) or scalar (float)
  238.     //F0.w is transparency
  239.     vec4 F0;
  240.     vec4 normalWeights;
  241.     vec4 cDetailWeights;
  242.     vec4 detailOffsetScaleD[4];
  243.     vec4 detailOffsetScaleN[4];
  244.  
  245.     uvec4 indices0_3;
  246.     //uintBitsToFloat( indices4_7.w ) contains mNormalMapWeight.
  247.     uvec4 indices4_7;
  248. };
  249.  
  250. layout_constbuffer(binding = 1) uniform MaterialBuf
  251. {
  252.     Material m[256];
  253. } materialArray;
  254.  
  255.    
  256. //Uniforms that change per Item/Entity
  257. layout_constbuffer(binding = 2) uniform InstanceBuffer
  258. {
  259.     //.x =
  260.     //The lower 9 bits contain the material's start index.
  261.     //The higher 23 bits contain the world matrix start index.
  262.     //
  263.     //.y =
  264.     //shadowConstantBias. Send the bias directly to avoid an
  265.     //unnecessary indirection during the shadow mapping pass.
  266.     //Must be loaded with uintBitsToFloat
  267.     //
  268.     //.z =
  269.     //lightMask. Ogre must have been compiled with OGRE_NO_FINE_LIGHT_MASK_GRANULARITY
  270.     uvec4 worldMaterialIdx[4096];
  271. } instance;
  272.  
  273.    
  274.  
  275. // END UNIFORM DECLARATION
  276.  
  277. in block
  278. {
  279.  
  280.    
  281.        
  282.             flat uint drawId;
  283.                
  284.             vec3 pos;
  285.             vec3 normal;
  286.             vec3 tangent;
  287.                 flat float biNormalReflection;                         
  288.             vec2 uv0;
  289.        
  290.            
  291.                 vec4 posL0;
  292.            
  293.                 vec4 posL1;
  294.            
  295.                 vec4 posL2;     float depth;                   
  296.  
  297. } inPs;
  298.  
  299.  
  300.  
  301.  
  302. uniform sampler2DArray textureMaps[1];
  303.     uint diffuseIdx;    uint normalIdx; uint specularIdx;   uint roughnessIdx;
  304.    
  305.    
  306.    
  307.    
  308.    
  309.    
  310.    
  311.    
  312. vec4 diffuseCol;
  313. vec3 specularCol;float ROUGHNESS;
  314. Material material;
  315. vec3 nNormal;
  316.  
  317.  
  318.  
  319.  
  320. vec3 getTSNormal( vec3 uv )
  321. {
  322.     vec3 tsNormal;
  323.  
  324.     //Normal texture must be in U8V8 or BC5 format!
  325.     tsNormal.xy = texture( textureMaps[0], uv ).xy;
  326.     tsNormal.z  = sqrt( max( 0, 1.0 - tsNormal.x * tsNormal.x - tsNormal.y * tsNormal.y ) );
  327.  
  328.     return tsNormal;
  329. }
  330.  
  331.  
  332.  
  333. //Default BRDF
  334. vec3 BRDF( vec3 lightDir, vec3 viewDir, float NdotV, vec3 lightDiffuse, vec3 lightSpecular )
  335. {
  336.     vec3 halfWay= normalize( lightDir + viewDir );
  337.     float NdotL = clamp( dot( nNormal, lightDir ), 0.0, 1.0 );
  338.     float NdotH = clamp( dot( nNormal, halfWay ), 0.0, 1.0 );
  339.     float VdotH = clamp( dot( viewDir, halfWay ), 0.0, 1.0 );
  340.  
  341.     float sqR = ROUGHNESS * ROUGHNESS;
  342.  
  343.     //Roughness/Distribution/NDF term (GGX)
  344.     //Formula:
  345.     //  Where alpha = roughness
  346.     //  R = alpha^2 / [ PI * [ ( NdotH^2 * (alpha^2 - 1) ) + 1 ]^2 ]
  347.     float f = ( NdotH * sqR - NdotH ) * NdotH + 1.0;
  348.     float R = sqR / (f * f + 1e-6f);
  349.  
  350.     //Geometric/Visibility term (Smith GGX Height-Correlated)
  351.  
  352.     float Lambda_GGXV = NdotL * sqrt( (-NdotV * sqR + NdotV) * NdotV + sqR );
  353.     float Lambda_GGXL = NdotV * sqrt( (-NdotL * sqR + NdotL) * NdotL + sqR );
  354.  
  355.     float G = 0.5 / (( Lambda_GGXV + Lambda_GGXL + 1e-6f ) * 3.141592654);
  356.  
  357.     //Formula:
  358.     //  fresnelS = lerp( (1 - V*H)^5, 1, F0 )
  359.     float fresnelS = material.F0.x + pow( 1.0 - VdotH, 5.0 ) * (1.0 - material.F0.x);
  360.  
  361.     //We should divide Rs by PI, but it was done inside G for performance
  362.     vec3 Rs = ( fresnelS * (R * G) ) * specularCol.xyz * lightSpecular;
  363.  
  364.     //Diffuse BRDF (*Normalized* Disney, see course_notes_moving_frostbite_to_pbr.pdf
  365.     //"Moving Frostbite to Physically Based Rendering" Sebastien Lagarde & Charles de Rousiers)
  366.     float energyBias    = ROUGHNESS * 0.5;
  367.     float energyFactor  = mix( 1.0, 1.0 / 1.51, ROUGHNESS );
  368.     float fd90          = energyBias + 2.0 * VdotH * VdotH * ROUGHNESS;
  369.     float lightScatter  = 1.0 + (fd90 - 1.0) * pow( 1.0 - NdotL, 5.0 );
  370.     float viewScatter   = 1.0 + (fd90 - 1.0) * pow( 1.0 - NdotV, 5.0 );
  371.  
  372.  
  373.     float fresnelD = 1.0f - fresnelS;
  374.     //We should divide Rd by PI, but it is already included in kD
  375.     vec3 Rd = (lightScatter * viewScatter * energyFactor * fresnelD) * diffuseCol.xyz * lightDiffuse;
  376.  
  377.     return NdotL * (Rs + Rd);
  378. }
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.     #define hlms_shadowmap0 texShadowMap0
  386.     #define hlms_shadowmap0_uv_min SH_HALF2( 0.0, 0.0 )
  387.     #define hlms_shadowmap0_uv_max SH_HALF2( 1.0, 0.28571 )
  388.    
  389.        
  390.             #define hlms_shadowmap0_uv_param , hlms_shadowmap0_uv_min, hlms_shadowmap0_uv_max
  391.            
  392.     #define hlms_shadowmap1 texShadowMap0
  393.     #define hlms_shadowmap1_uv_min SH_HALF2( 0.0, 0.28571 )
  394.     #define hlms_shadowmap1_uv_max SH_HALF2( 0.50000, 0.42857 )
  395.    
  396.        
  397.             #define hlms_shadowmap1_uv_param , hlms_shadowmap1_uv_min, hlms_shadowmap1_uv_max
  398.            
  399.     #define hlms_shadowmap2 texShadowMap0
  400.     #define hlms_shadowmap2_uv_min SH_HALF2( 0.50000, 0.28571 )
  401.     #define hlms_shadowmap2_uv_max SH_HALF2( 1.0, 0.42857 )
  402.    
  403.        
  404.             #define hlms_shadowmap2_uv_param , hlms_shadowmap2_uv_min, hlms_shadowmap2_uv_max
  405.            
  406.  
  407.     #define SH_HALF2 vec2
  408.     #define SH_HALF float
  409.     #define OGRE_SAMPLE_SHADOW( tex, sampler, uv, depth ) texture( tex, vec3( uv, fDepth ) )
  410.     #define OGRE_SAMPLE_SHADOW_ESM( tex, sampler, uv ) textureLod( tex, uv, 0 ).x
  411.     #define PASSBUF_ARG_DECL
  412.     #define PASSBUF_ARG
  413.  
  414.  
  415.  
  416.  
  417.        
  418.             uniform sampler2DShadow texShadowMap0; 
  419.  
  420.  
  421.    
  422.         INLINE float getShadow( sampler2DShadow shadowMap,
  423.                                 float4 psPosLN, float4 invShadowMapSize )
  424.         {
  425.    
  426.         //Spot and directional lights
  427.         float fDepth = psPosLN.z;
  428.         SH_HALF2 uv = SH_HALF2( psPosLN.xy / psPosLN.w );
  429.    
  430.    
  431.         float retVal = 0;
  432.  
  433.        
  434.             SH_HALF2 offsets[4] =
  435.            
  436.                 SH_HALF2[4](
  437.                                    
  438.                 SH_HALF2( 0, 0 ),   //0, 0
  439.                 SH_HALF2( 1, 0 ),   //1, 0
  440.                 SH_HALF2( 0, 1 ),   //1, 1
  441.                 SH_HALF2( 0, 0 )    //1, 1
  442.                                    
  443.             );
  444.                                
  445.        
  446.        
  447.            
  448.                 uv += offsets[0] * SH_HALF2( invShadowMapSize.xy );             retVal += OGRE_SAMPLE_SHADOW( shadowMap, shadowSampler, uv, fDepth );
  449.                 uv += offsets[1] * SH_HALF2( invShadowMapSize.xy );             retVal += OGRE_SAMPLE_SHADOW( shadowMap, shadowSampler, uv, fDepth );
  450.                 uv += offsets[2] * SH_HALF2( invShadowMapSize.xy );             retVal += OGRE_SAMPLE_SHADOW( shadowMap, shadowSampler, uv, fDepth );
  451.                 uv += offsets[3] * SH_HALF2( invShadowMapSize.xy );             retVal += OGRE_SAMPLE_SHADOW( shadowMap, shadowSampler, uv, fDepth );      
  452.        
  453.             retVal *= 0.25;
  454.             ///! exponential_shadow_maps
  455.        ///! exponential_shadow_maps
  456.  
  457.    
  458.    
  459.         return retVal;
  460.     }
  461.  
  462.    
  463.         INLINE float getShadow( sampler2DShadow shadowMap,
  464.                                 float4 psPosLN, float4 invShadowMapSize, SH_HALF2 minUV, SH_HALF2 maxUV )
  465.         {
  466.    
  467.         //Spot and directional lights
  468.         float fDepth = psPosLN.z;
  469.         SH_HALF2 uv = SH_HALF2( psPosLN.xy / psPosLN.w );
  470.    
  471.    
  472.         float retVal = 0;
  473.  
  474.        
  475.             SH_HALF2 offsets[4] =
  476.            
  477.                 SH_HALF2[4](
  478.                                    
  479.                 SH_HALF2( 0, 0 ),   //0, 0
  480.                 SH_HALF2( 1, 0 ),   //1, 0
  481.                 SH_HALF2( 0, 1 ),   //1, 1
  482.                 SH_HALF2( 0, 0 )    //1, 1
  483.                                    
  484.             );
  485.                                
  486.        
  487.        
  488.            
  489.                 uv += offsets[0] * SH_HALF2( invShadowMapSize.xy );             retVal += OGRE_SAMPLE_SHADOW( shadowMap, shadowSampler, uv, fDepth );
  490.                 uv += offsets[1] * SH_HALF2( invShadowMapSize.xy );             retVal += OGRE_SAMPLE_SHADOW( shadowMap, shadowSampler, uv, fDepth );
  491.                 uv += offsets[2] * SH_HALF2( invShadowMapSize.xy );             retVal += OGRE_SAMPLE_SHADOW( shadowMap, shadowSampler, uv, fDepth );
  492.                 uv += offsets[3] * SH_HALF2( invShadowMapSize.xy );             retVal += OGRE_SAMPLE_SHADOW( shadowMap, shadowSampler, uv, fDepth );      
  493.        
  494.             retVal *= 0.25;
  495.             ///! exponential_shadow_maps
  496.        ///! exponential_shadow_maps
  497.  
  498.    
  499.    
  500.         retVal = (uv.x <= minUV.x || uv.x >= maxUV.x ||
  501.                   uv.y <= minUV.y || uv.y >= maxUV.y) ? 1.0 : retVal;
  502.    
  503.         return retVal;
  504.     }
  505.  
  506.    
  507.         INLINE float getShadowPoint( sampler2DShadow shadowMap,
  508.                                      float3 posVS, float3 lightPos, float4 invShadowMapSize, float2 invDepthRange
  509.                                      PASSBUF_ARG_DECL )
  510.         {
  511.    
  512.         //Point lights
  513.         float3 cubemapDir = posVS.xyz - lightPos.xyz;
  514.         float fDepth = length( cubemapDir );
  515.         cubemapDir *= 1.0 / fDepth;
  516.         cubemapDir = mul( cubemapDir.xyz, passBuf.invViewMatCubemap );
  517.         fDepth = (fDepth - invDepthRange.x) * invDepthRange.y;
  518.  
  519.         SH_HALF2 uv;
  520.         uv.x = (cubemapDir.x / (1.0 + abs( cubemapDir.z ))) * 0.25 +
  521.                 (cubemapDir.z < 0.0 ? SH_HALF( 0.75 ) : SH_HALF( 0.25 ));
  522.         uv.y = (cubemapDir.y / (1.0 + abs( cubemapDir.z ))) * 0.5 + 0.5;
  523.  
  524.            
  525.    
  526.         float retVal = 0;
  527.  
  528.        
  529.             SH_HALF2 offsets[4] =
  530.            
  531.                 SH_HALF2[4](
  532.                                    
  533.                 SH_HALF2( 0, 0 ),   //0, 0
  534.                 SH_HALF2( 1, 0 ),   //1, 0
  535.                 SH_HALF2( 0, 1 ),   //1, 1
  536.                 SH_HALF2( 0, 0 )    //1, 1
  537.                                    
  538.             );
  539.                                
  540.        
  541.        
  542.            
  543.                 uv += offsets[0] * SH_HALF2( invShadowMapSize.xy );             retVal += OGRE_SAMPLE_SHADOW( shadowMap, shadowSampler, uv, fDepth );
  544.                 uv += offsets[1] * SH_HALF2( invShadowMapSize.xy );             retVal += OGRE_SAMPLE_SHADOW( shadowMap, shadowSampler, uv, fDepth );
  545.                 uv += offsets[2] * SH_HALF2( invShadowMapSize.xy );             retVal += OGRE_SAMPLE_SHADOW( shadowMap, shadowSampler, uv, fDepth );
  546.                 uv += offsets[3] * SH_HALF2( invShadowMapSize.xy );             retVal += OGRE_SAMPLE_SHADOW( shadowMap, shadowSampler, uv, fDepth );      
  547.        
  548.             retVal *= 0.25;
  549.             ///! exponential_shadow_maps
  550.        ///! exponential_shadow_maps
  551.  
  552.    
  553.    
  554.         return retVal;
  555.     }
  556.  
  557.    
  558.         INLINE float getShadowPoint( sampler2DShadow shadowMap,
  559.                                      float3 posVS, float3 lightPos, float4 invShadowMapSize, float2 invDepthRange,
  560.                                      SH_HALF2 minUV, SH_HALF2 maxUV, SH_HALF2 lengthUV
  561.                                      PASSBUF_ARG_DECL )
  562.         {
  563.    
  564.         //Point lights
  565.         float3 cubemapDir = posVS.xyz - lightPos.xyz;
  566.         float fDepth = length( cubemapDir );
  567.         cubemapDir *= 1.0 / fDepth;
  568.         cubemapDir = mul( cubemapDir.xyz, passBuf.invViewMatCubemap );
  569.         fDepth = (fDepth - invDepthRange.x) * invDepthRange.y;
  570.  
  571.         SH_HALF2 uv;
  572.         uv.x = (cubemapDir.x / (1.0 + abs( cubemapDir.z ))) * 0.25 +
  573.                 (cubemapDir.z < 0.0 ? SH_HALF( 0.75 ) : SH_HALF( 0.25 ));
  574.         uv.y = (cubemapDir.y / (1.0 + abs( cubemapDir.z ))) * 0.5 + 0.5;
  575.  
  576.         uv.xy = uv.xy * lengthUV.xy + minUV.xy;
  577.    
  578.         float retVal = 0;
  579.  
  580.        
  581.             SH_HALF2 offsets[4] =
  582.            
  583.                 SH_HALF2[4](
  584.                                    
  585.                 SH_HALF2( 0, 0 ),   //0, 0
  586.                 SH_HALF2( 1, 0 ),   //1, 0
  587.                 SH_HALF2( 0, 1 ),   //1, 1
  588.                 SH_HALF2( 0, 0 )    //1, 1
  589.                                    
  590.             );
  591.                                
  592.        
  593.        
  594.            
  595.                 uv += offsets[0] * SH_HALF2( invShadowMapSize.xy );             retVal += OGRE_SAMPLE_SHADOW( shadowMap, shadowSampler, uv, fDepth );
  596.                 uv += offsets[1] * SH_HALF2( invShadowMapSize.xy );             retVal += OGRE_SAMPLE_SHADOW( shadowMap, shadowSampler, uv, fDepth );
  597.                 uv += offsets[2] * SH_HALF2( invShadowMapSize.xy );             retVal += OGRE_SAMPLE_SHADOW( shadowMap, shadowSampler, uv, fDepth );
  598.                 uv += offsets[3] * SH_HALF2( invShadowMapSize.xy );             retVal += OGRE_SAMPLE_SHADOW( shadowMap, shadowSampler, uv, fDepth );      
  599.        
  600.             retVal *= 0.25;
  601.             ///! exponential_shadow_maps
  602.        ///! exponential_shadow_maps
  603.  
  604.    
  605.    
  606.         retVal = (uv.x <= minUV.x || uv.x >= maxUV.x ||
  607.                   uv.y <= minUV.y || uv.y >= maxUV.y) ? 1.0 : retVal;
  608.    
  609.         return retVal;
  610.     }
  611.  
  612.  
  613. void main()
  614. {
  615.    
  616.  
  617.    
  618.         uint materialId = instance.worldMaterialIdx[inPs.drawId].x & 0x1FFu;
  619.         material = materialArray.m[materialId];
  620.         diffuseIdx          = material.indices0_3.x & 0x0000FFFFu;  normalIdx           = material.indices0_3.x >> 16u; specularIdx         = material.indices0_3.y & 0x0000FFFFu;  roughnessIdx        = material.indices0_3.y >> 16u;
  621.    
  622.  
  623.    
  624.  
  625.  
  626.     /// Sample detail maps and weight them against the weight map in the next foreach loop.
  627.  
  628.  
  629.         diffuseCol = texture( textureMaps[0], vec3( inPs.uv0.xy, diffuseIdx ) );
  630.  
  631.  
  632.     /// 'insertpiece( SampleDiffuseMap )' must've written to diffuseCol. However if there are no
  633.     /// diffuse maps, we must initialize it to some value. If there are no diffuse or detail maps,
  634.     /// we must not access diffuseCol at all, but rather use material.kD directly (see piece( kD ) ).
  635.    
  636.     /// Blend the detail diffuse maps with the main diffuse.
  637.    
  638.         /// Apply the material's diffuse over the textures
  639.        
  640.             diffuseCol.xyz *= material.kD.xyz;
  641.        
  642.    
  643.  
  644.    
  645.         //Normal mapping.
  646.         vec3 geomNormal = normalize( inPs.normal ) ;
  647.         vec3 vTangent = normalize( inPs.tangent );
  648.  
  649.         //Get the TBN matrix
  650.         vec3 vBinormal  = normalize( cross( geomNormal, vTangent ) * inPs.biNormalReflection );
  651.         mat3 TBN        = mat3( vTangent, vBinormal, geomNormal );
  652.  
  653.         nNormal = getTSNormal( vec3( inPs.uv0.xy, normalIdx ) );           
  654.     /// If there is no normal map, the first iteration must
  655.     /// initialize nNormal instead of try to merge with it.
  656.    
  657.                    
  658.         /// Blend the detail normal maps with the main normal.
  659.        
  660.    
  661.         nNormal = normalize( TBN * nNormal );
  662.    
  663.    
  664.  
  665.         float fShadow = 1.0;
  666.    
  667.         if( inPs.depth <= passBuf.pssmSplitPoints0 )
  668.         {
  669.             fShadow = getShadow( hlms_shadowmap0,
  670.                                  inPs.posL0,
  671.                                  passBuf.shadowRcv[0].invShadowMapSize
  672.                                  hlms_shadowmap0_uv_param );
  673.                     }
  674.        
  675.         else if( inPs.depth <= passBuf.pssmSplitPoints1 )
  676.         {
  677.             fShadow = getShadow( hlms_shadowmap1,
  678.                                  inPs.posL1,
  679.                                  passBuf.shadowRcv[1].invShadowMapSize
  680.                                  hlms_shadowmap1_uv_param );
  681.                     }
  682.         else if( inPs.depth <= passBuf.pssmSplitPoints2 )
  683.         {
  684.             fShadow = getShadow( hlms_shadowmap2,
  685.                                  inPs.posL2,
  686.                                  passBuf.shadowRcv[2].invShadowMapSize
  687.                                  hlms_shadowmap2_uv_param );
  688.                     }  
  689.  
  690.     ROUGHNESS = material.kS.w * texture( textureMaps[0], vec3(inPs.uv0.xy, roughnessIdx) ).x;
  691. ROUGHNESS = max( ROUGHNESS, 0.001f );
  692.  
  693.  
  694.     specularCol = texture( textureMaps[0], vec3(inPs.uv0.xy, specularIdx) ).xyz * material.kS.xyz;
  695.  
  696.  
  697.     //Everything's in Camera space
  698.  
  699.     vec3 viewDir    = normalize( -inPs.pos );
  700.     float NdotV     = clamp( dot( nNormal, viewDir ), 0.0, 1.0 );
  701.  
  702.  
  703.     vec3 finalColour = vec3(0);
  704.  
  705.    
  706.  
  707.  
  708.  
  709.    
  710.         finalColour += BRDF( passBuf.lights[0].position.xyz, viewDir, NdotV, passBuf.lights[0].diffuse, passBuf.lights[0].specular ) * fShadow;
  711.  
  712.     vec3 lightDir;
  713.     float fDistance;
  714.     vec3 tmpColour;
  715.     float spotCosAngle;
  716.     //Point lights
  717.  
  718.     //Spot lights
  719.     //spotParams[0].x = 1.0 / cos( InnerAngle ) - cos( OuterAngle )
  720.     //spotParams[0].y = cos( OuterAngle / 2 )
  721.     //spotParams[0].z = falloff
  722.  
  723.  
  724.  
  725.  
  726.  
  727.     vec3 reflDir = 2.0 * dot( viewDir, nNormal ) * nNormal - viewDir;
  728.  
  729.    
  730.    
  731.    
  732.  
  733.    
  734.         float ambientWD = dot( passBuf.ambientHemisphereDir.xyz, nNormal ) * 0.5 + 0.5;
  735.         float ambientWS = dot( passBuf.ambientHemisphereDir.xyz, reflDir ) * 0.5 + 0.5;
  736.  
  737.        
  738.             vec3 envColourS = mix( passBuf.ambientLowerHemi.xyz, passBuf.ambientUpperHemi.xyz, ambientWD );
  739.             vec3 envColourD = mix( passBuf.ambientLowerHemi.xyz, passBuf.ambientUpperHemi.xyz, ambientWS );
  740.            
  741.    
  742.     float NdotL = clamp( dot( nNormal, reflDir ), 0.0, 1.0 );
  743.     float VdotH = clamp( dot( viewDir, normalize( reflDir + viewDir ) ), 0.0, 1.0 );
  744.     float fresnelS = material.F0.x + pow( 1.0 - VdotH, 5.0 ) * (max( 1.0 - ROUGHNESS, material.F0.x ) - material.F0.x);
  745.  
  746.    
  747.         float fresnelD = 1.0f - fresnelS;
  748.     finalColour += envColourD * diffuseCol.xyz * fresnelD +
  749.                     envColourS * specularCol.xyz * fresnelS;
  750.  
  751. ///!hlms_prepass
  752.  
  753.  
  754.    
  755.        
  756.             outColour.xyz   = finalColour;
  757.        
  758.        
  759.             outColour.w     = 1.0;
  760.        
  761.            
  762.    
  763. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top