
#ifndef GL3
#define sampleShadow(map,pos) shadow2DProj(map,pos).r
#else
#define sampleShadow(map,pos) textureProj(map,pos)
#endif

#ifdef GL3
#define texture2D texture
#define texture2DProj textureProj
#define texture3D texture
#define textureCube texture
#define texture2DLod textureLod
#define texture2DLodOffset textureLodOffset
#endif

uniform sampler2D sSpecMap;

// ==================================== PREPASS ====================================
#if defined(PREPASS)
#if !defined(GLSL)
#define GLSL
#endif
#if defined(DX11)
#undef DX11
#endif

// ------------------- Vertex Shader ---------------

#if defined(DIRLIGHT) && (!defined(GL_ES) || defined(WEBGL))
    #define NUMCASCADES 4
#else
    #define NUMCASCADES 1
#endif

#ifdef COMPILEVS

// Silence GLSL 150 deprecation warnings
#ifdef GL3
#define attribute in
#define varying out
#endif

attribute vec4 iPos;
#if defined(SKINNED)
attribute vec4 iBlendWeights;
attribute vec4 iBlendIndices;
#endif
#if (!defined(SKINNED) && defined(INSTANCED))
attribute vec4 iTexCoord4;
attribute vec4 iTexCoord5;
attribute vec4 iTexCoord6;
#endif
uniform mat4 cModel;
uniform vec4 cSkinMatrices[MAXBONES*3];
uniform mat4 cViewProj;
uniform vec4 cDepthMode;
uniform vec4 cClipPlane;
varying float vVarying1;
varying float vVarying2;

attribute float iObjectIndex;




void VS()
{
vVarying1 = (vec4(0.0,0.0,0.0,0.0).w / 255.0);
#if (!defined(SKINNED) && defined(INSTANCED))
// based on node ifdef(mat4x3) INSTANCED (type:ifdef(mat4x3), id:8)
mat4 ifdef2 = mat4(iTexCoord4, iTexCoord5, iTexCoord6, vec4(0.0, 0.0, 0.0, 1.0));
#endif
#if (!defined(SKINNED) && !defined(INSTANCED))
// based on node ifdef(mat4x3) INSTANCED (type:ifdef(mat4x3), id:8)
mat4 ifdef2 = cModel;
#endif
#if defined(SKINNED)
// based on node ifdef(mat4x3) SKINNED (type:ifdef(mat4x3), id:8)
mat4 ifdef1 = (((mat4(cSkinMatrices[ivec4(iBlendIndices).x*3], cSkinMatrices[ivec4(iBlendIndices).x*3+1],cSkinMatrices[ivec4(iBlendIndices).x*3+2], vec4(0.0, 0.0, 0.0, 1.0)) * iBlendWeights.x) + (mat4(cSkinMatrices[ivec4(iBlendIndices).y*3], cSkinMatrices[ivec4(iBlendIndices).y*3+1],cSkinMatrices[ivec4(iBlendIndices).y*3+2], vec4(0.0, 0.0, 0.0, 1.0)) * iBlendWeights.y)) + ((mat4(cSkinMatrices[ivec4(iBlendIndices).z*3], cSkinMatrices[ivec4(iBlendIndices).z*3+1],cSkinMatrices[ivec4(iBlendIndices).z*3+2], vec4(0.0, 0.0, 0.0, 1.0)) * iBlendWeights.z) + (mat4(cSkinMatrices[ivec4(iBlendIndices).w*3], cSkinMatrices[ivec4(iBlendIndices).w*3+1],cSkinMatrices[ivec4(iBlendIndices).w*3+2], vec4(0.0, 0.0, 0.0, 1.0)) * iBlendWeights.w)));
#endif
#if !defined(SKINNED)
// based on node ifdef(mat4x3) SKINNED (type:ifdef(mat4x3), id:8)
mat4 ifdef1 = ifdef2;
#endif
// based on node vec4*mat4  (type:vec4*mat4, id:25)
vec4 var5 = (vec4(((iPos * ifdef1)).xyz, 1) * cViewProj);
vVarying2 = dot(var5.zw, cDepthMode.zw);
vec4 ret =  var5;


    // While getting the clip coordinate, also automatically set gl_ClipVertex for user clip planes
    #if !defined(GL_ES) && !defined(GL3)
       gl_ClipVertex = ret;
    #elif defined(GL3)
       gl_ClipDistance[0] = dot(cClipPlane, ret);
    #endif
    gl_Position = ret;
}

#else
// ------------------- Pixel Shader ---------------

varying float vVarying2;
varying float vVarying1;



void PS()
{
// based on node per pixel float  (type:perPixelFloat, id:25)
float var0 = vVarying2;
// based on node float  (type:default, id:0)
float var6 = (0.0);
#if !defined(GL3)
// based on node float*float  (type:float*float, id:25)
float var1 = (var0 * 255.0);
// based on node floor(float)  (type:floor(float), id:25)
float var2 = floor(var1);
// based on node float*float  (type:float*float, id:25)
float var3 = ((var1 - var2) * 255.0);
// based on node floor(float)  (type:floor(float), id:25)
float var4 = floor(var3);
#endif
#if defined(GL3)
// based on node ifdef(vec3) GL3 (type:ifdef(vec3), id:25)
vec3 ifdef1 = vec3(var0, var6, var6);
#endif
#if !defined(GL3)
// based on node ifdef(vec3) GL3 (type:ifdef(vec3), id:25)
vec3 ifdef1 = vec3((var2 * 0.0039215686274509803921568627451), (var4 * 0.0039215686274509803921568627451), (var3 - var4));
#endif
gl_FragData[1] = vec4(ifdef1, var6);
gl_FragData[0] = vec4(((normalize(vec3(0.0,0.0,0.0)) * 0.5) + vec3(0.5, 0.5, 0.5)), vVarying1);

}
#endif
// ==================================== DEFERREDPASS ====================================
#elif defined(DEFERREDPASS)
#if !defined(GLSL)
#define GLSL
#endif
#if defined(DX11)
#undef DX11
#endif

// ------------------- Vertex Shader ---------------

#if defined(DIRLIGHT) && (!defined(GL_ES) || defined(WEBGL))
    #define NUMCASCADES 4
#else
    #define NUMCASCADES 1
#endif

#ifdef COMPILEVS

// Silence GLSL 150 deprecation warnings
#ifdef GL3
#define attribute in
#define varying out
#endif

attribute vec4 iPos;
#if defined(SKINNED)
attribute vec4 iBlendWeights;
attribute vec4 iBlendIndices;
#endif
#if (!defined(SKINNED) && defined(INSTANCED))
attribute vec4 iTexCoord4;
attribute vec4 iTexCoord5;
attribute vec4 iTexCoord6;
#endif
attribute vec3 iNormal;
uniform float cElapsedTime;
uniform mat4 cModel;
uniform vec4 cAmbientColor;
uniform vec4 cSkinMatrices[MAXBONES*3];
uniform mat4 cViewProj;
uniform vec4 cDepthMode;
uniform vec4 cClipPlane;
varying float vVarying1;
varying float vVarying7;
varying vec3 vVarying6;
varying vec3 vVarying2;
varying float vVarying10;
varying float vVarying9;
varying vec4 vVarying8;
varying vec3 vVarying5;
varying vec3 vVarying4;
varying float vVarying3;

attribute float iObjectIndex;


// --- GetNormalMatrix ---

mat3 GetNormalMatrix(mat4 modelMatrix)
{
    return mat3(modelMatrix[0].xyz, modelMatrix[1].xyz, modelMatrix[2].xyz);
}



void VS()
{
vVarying1 = (0.15 * cElapsedTime);
// based on node vec4  (type:default, id:0)
vec4 var6 = vec4(0.0,0.0,0.0,0.0);
// based on node break vec4 to vec3, float  (type:breakVec4toVec3Float, id:25)
float var18 = var6.w;
vVarying7 = (var18 / 255.0);
// based on node break vec4 to vec3, float  (type:breakVec4toVec3Float, id:25)
vec3 var9 = var6.xyz;
vVarying6 = (cAmbientColor.xyz * var9);
vVarying2 = iPos.xyz;
vVarying10 = var18;
#if (!defined(SKINNED) && defined(INSTANCED))
// based on node ifdef(mat4x3) INSTANCED (type:ifdef(mat4x3), id:177)
mat4 ifdef2 = mat4(iTexCoord4, iTexCoord5, iTexCoord6, vec4(0.0, 0.0, 0.0, 1.0));
#endif
#if (!defined(SKINNED) && !defined(INSTANCED))
// based on node ifdef(mat4x3) INSTANCED (type:ifdef(mat4x3), id:177)
mat4 ifdef2 = cModel;
#endif
#if defined(SKINNED)
// based on node ifdef(mat4x3) SKINNED (type:ifdef(mat4x3), id:177)
mat4 ifdef1 = (((mat4(cSkinMatrices[ivec4(iBlendIndices).x*3], cSkinMatrices[ivec4(iBlendIndices).x*3+1],cSkinMatrices[ivec4(iBlendIndices).x*3+2], vec4(0.0, 0.0, 0.0, 1.0)) * iBlendWeights.x) + (mat4(cSkinMatrices[ivec4(iBlendIndices).y*3], cSkinMatrices[ivec4(iBlendIndices).y*3+1],cSkinMatrices[ivec4(iBlendIndices).y*3+2], vec4(0.0, 0.0, 0.0, 1.0)) * iBlendWeights.y)) + ((mat4(cSkinMatrices[ivec4(iBlendIndices).z*3], cSkinMatrices[ivec4(iBlendIndices).z*3+1],cSkinMatrices[ivec4(iBlendIndices).z*3+2], vec4(0.0, 0.0, 0.0, 1.0)) * iBlendWeights.z) + (mat4(cSkinMatrices[ivec4(iBlendIndices).w*3], cSkinMatrices[ivec4(iBlendIndices).w*3+1],cSkinMatrices[ivec4(iBlendIndices).w*3+2], vec4(0.0, 0.0, 0.0, 1.0)) * iBlendWeights.w)));
#endif
#if !defined(SKINNED)
// based on node ifdef(mat4x3) SKINNED (type:ifdef(mat4x3), id:177)
mat4 ifdef1 = ifdef2;
#endif
// based on node ifdef(mat4x3)  (type:ifdef(mat4x3), id:177)
mat4 var8 = ifdef1;
// based on node vec4*mat4x3  (type:vec4*mat4x3, id:8)
vec3 var5 = ((iPos * var8)).xyz;
// based on node vec4*mat4  (type:vec4*mat4, id:25)
vec4 var15 = (vec4(var5, 1) * cViewProj);
vVarying9 = dot(var15.zw, cDepthMode.zw);
vVarying8 = vec4(var9, var18);
vVarying5 = (iNormal * GetNormalMatrix(var8));
vVarying4 = var5;
vVarying3 = (sin(cElapsedTime) * 0.02);
vec4 ret =  var15;


    // While getting the clip coordinate, also automatically set gl_ClipVertex for user clip planes
    #if !defined(GL_ES) && !defined(GL3)
       gl_ClipVertex = ret;
    #elif defined(GL3)
       gl_ClipDistance[0] = dot(cClipPlane, ret);
    #endif
    gl_Position = ret;
}

#else
// ------------------- Pixel Shader ---------------

uniform vec4 cPortalColor_2;
uniform vec3 cCameraPos;
uniform vec4 cAnotherWorldColorMul;
uniform float cAnotherWorldGlowMul;
uniform vec4 cPortalColor_1;
uniform sampler2D sEmissiveMap;
uniform samplerCube sEnvCubeMap;
uniform sampler2D sDiffMap;
varying float vVarying1;
varying float vVarying10;
varying float vVarying9;
varying vec4 vVarying8;
varying vec3 vVarying5;
varying vec3 vVarying4;
varying float vVarying3;
varying vec3 vVarying2;
varying float vVarying7;
varying vec3 vVarying6;



void PS()
{
// based on node per pixel vec3  (type:perPixelVec3, id:170)
vec3 var4 = vVarying2;
// based on node break vec3  (type:breakVec3, id:31)
float var0 = var4.x;
// based on node break vec3  (type:breakVec3, id:31)
float var17 = var4.z;
// based on node float+float  (type:float+float, id:70)
float var3 = (((0.3183098862 * atan(var0, var17)) * 0.5) + 0.5);
// based on node float-float  (type:float-float, id:59)
float var7 = (1.0 - (length(vec2(var0, var17)) * 0.5));
// based on node texture2D(sampler2D,vec2)  (type:texture2D(sampler2D,vec2), id:54)
vec4 var2 = texture2D(sEmissiveMap, vec2(var3, (var7 + vVarying3)));
// based on node break vec4  (type:breakVec4, id:58)
float var1 = var2.x;
gl_FragData[0] = vec4(vec4((vVarying6 + (vec4(0.0,0.0,0.0,0.0) + mix(((cAnotherWorldColorMul * (textureCube(sEnvCubeMap, reflect(normalize((cCameraPos - vVarying4)), vVarying5)) * var2.z)) * cAnotherWorldGlowMul), mix(cPortalColor_1, cPortalColor_2, texture2D(sDiffMap, vec2(var3, (vVarying1 + (2 * var7)))).x), mix((var1 * var2.y), var1, float(gl_FrontFacing)))).xyz), vVarying10).xyz, 1.0);
gl_FragData[1] = vVarying8;
gl_FragData[2] = vec4(((normalize(vec3(0.0,0.0,0.0)) * 0.5) + vec3(0.5, 0.5, 0.5)), vVarying7);
// based on node per pixel float  (type:perPixelFloat, id:25)
float var10 = vVarying9;
// based on node float  (type:default, id:0)
float var16 = (0.0);
#if !defined(GL3)
// based on node float*float  (type:float*float, id:25)
float var11 = (var10 * 255.0);
// based on node floor(float)  (type:floor(float), id:25)
float var12 = floor(var11);
// based on node float*float  (type:float*float, id:25)
float var13 = ((var11 - var12) * 255.0);
// based on node floor(float)  (type:floor(float), id:25)
float var14 = floor(var13);
#endif
#if defined(GL3)
// based on node ifdef(vec3) GL3 (type:ifdef(vec3), id:25)
vec3 ifdef1 = vec3(var10, var16, var16);
#endif
#if !defined(GL3)
// based on node ifdef(vec3) GL3 (type:ifdef(vec3), id:25)
vec3 ifdef1 = vec3((var12 * 0.0039215686274509803921568627451), (var14 * 0.0039215686274509803921568627451), (var13 - var14));
#endif
gl_FragData[3] = vec4(ifdef1, var16);

}
#endif
// ==================================== ALPHAPASS ====================================
#elif defined(ALPHAPASS)
#if !defined(GLSL)
#define GLSL
#endif
#if defined(DX11)
#undef DX11
#endif

// ------------------- Vertex Shader ---------------

#if defined(DIRLIGHT) && (!defined(GL_ES) || defined(WEBGL))
    #define NUMCASCADES 4
#else
    #define NUMCASCADES 1
#endif

#ifdef COMPILEVS

// Silence GLSL 150 deprecation warnings
#ifdef GL3
#define attribute in
#define varying out
#endif

attribute vec4 iPos;
#if defined(SKINNED)
attribute vec4 iBlendWeights;
attribute vec4 iBlendIndices;
#endif
#if (!defined(SKINNED) && defined(INSTANCED))
attribute vec4 iTexCoord4;
attribute vec4 iTexCoord5;
attribute vec4 iTexCoord6;
#endif
attribute vec3 iNormal;
uniform float cElapsedTime;
uniform mat4 cModel;
uniform vec4 cAmbientColor;
uniform vec4 cSkinMatrices[MAXBONES*3];
uniform mat4 cViewProj;
uniform vec4 cClipPlane;
uniform vec2 cGBufferInvSize;
varying float vVarying1;
varying float vVarying7;
varying vec3 vVarying6;
varying vec3 vVarying2;
varying vec3 vVarying5;
varying vec3 vVarying4;
varying float vVarying3;

attribute float iObjectIndex;


// --- GetNormalMatrix ---

mat3 GetNormalMatrix(mat4 modelMatrix)
{
    return mat3(modelMatrix[0].xyz, modelMatrix[1].xyz, modelMatrix[2].xyz);
}



void VS()
{
vVarying1 = (0.15 * cElapsedTime);
// based on node vec4  (type:default, id:0)
vec4 var6 = vec4(0.0,0.0,0.0,0.0);
vVarying7 = var6.w;
vVarying6 = (cAmbientColor.xyz * var6.xyz);
vVarying2 = iPos.xyz;
#if (!defined(SKINNED) && defined(INSTANCED))
// based on node ifdef(mat4x3) INSTANCED (type:ifdef(mat4x3), id:177)
mat4 ifdef2 = mat4(iTexCoord4, iTexCoord5, iTexCoord6, vec4(0.0, 0.0, 0.0, 1.0));
#endif
#if (!defined(SKINNED) && !defined(INSTANCED))
// based on node ifdef(mat4x3) INSTANCED (type:ifdef(mat4x3), id:177)
mat4 ifdef2 = cModel;
#endif
#if defined(SKINNED)
// based on node ifdef(mat4x3) SKINNED (type:ifdef(mat4x3), id:177)
mat4 ifdef1 = (((mat4(cSkinMatrices[ivec4(iBlendIndices).x*3], cSkinMatrices[ivec4(iBlendIndices).x*3+1],cSkinMatrices[ivec4(iBlendIndices).x*3+2], vec4(0.0, 0.0, 0.0, 1.0)) * iBlendWeights.x) + (mat4(cSkinMatrices[ivec4(iBlendIndices).y*3], cSkinMatrices[ivec4(iBlendIndices).y*3+1],cSkinMatrices[ivec4(iBlendIndices).y*3+2], vec4(0.0, 0.0, 0.0, 1.0)) * iBlendWeights.y)) + ((mat4(cSkinMatrices[ivec4(iBlendIndices).z*3], cSkinMatrices[ivec4(iBlendIndices).z*3+1],cSkinMatrices[ivec4(iBlendIndices).z*3+2], vec4(0.0, 0.0, 0.0, 1.0)) * iBlendWeights.z) + (mat4(cSkinMatrices[ivec4(iBlendIndices).w*3], cSkinMatrices[ivec4(iBlendIndices).w*3+1],cSkinMatrices[ivec4(iBlendIndices).w*3+2], vec4(0.0, 0.0, 0.0, 1.0)) * iBlendWeights.w)));
#endif
#if !defined(SKINNED)
// based on node ifdef(mat4x3) SKINNED (type:ifdef(mat4x3), id:177)
mat4 ifdef1 = ifdef2;
#endif
// based on node ifdef(mat4x3)  (type:ifdef(mat4x3), id:177)
mat4 var8 = ifdef1;
vVarying5 = (iNormal * GetNormalMatrix(var8));
// based on node vec4*mat4x3  (type:vec4*mat4x3, id:8)
vec3 var5 = ((iPos * var8)).xyz;
vVarying4 = var5;
vVarying3 = (sin(cElapsedTime) * 0.02);
vec4 ret =  (vec4(var5, 1) * cViewProj);


    // While getting the clip coordinate, also automatically set gl_ClipVertex for user clip planes
    #if !defined(GL_ES) && !defined(GL3)
       gl_ClipVertex = ret;
    #elif defined(GL3)
       gl_ClipDistance[0] = dot(cClipPlane, ret);
    #endif
    gl_Position = ret;
}

#else
// ------------------- Pixel Shader ---------------

uniform vec4 cPortalColor_2;
uniform vec3 cCameraPos;
uniform vec4 cAnotherWorldColorMul;
uniform float cAnotherWorldGlowMul;
uniform vec4 cPortalColor_1;
uniform sampler2D sEmissiveMap;
uniform samplerCube sEnvCubeMap;
uniform sampler2D sDiffMap;
varying float vVarying1;
varying vec3 vVarying5;
varying vec3 vVarying4;
varying float vVarying3;
varying vec3 vVarying2;
varying float vVarying7;
varying vec3 vVarying6;

uniform CameraPS
{
    vec3 cCameraPosPS;
    vec4 cDepthReconstruct;
    vec2 cGBufferInvSize;
    float cNearClipPS;
    float cFarClipPS;
};

void PS()
{
// based on node per pixel vec3  (type:perPixelVec3, id:170)
vec3 var4 = vVarying2;
// based on node break vec3  (type:breakVec3, id:31)
float var0 = var4.x;
// based on node break vec3  (type:breakVec3, id:31)
float var9 = var4.z;
// based on node float+float  (type:float+float, id:70)
float var3 = (((0.3183098862 * atan(var0, var9)) * 0.5) + 0.5);
// based on node float-float  (type:float-float, id:59)
float var7 = (1.0 - (length(vec2(var0, var9)) * 0.5));
// based on node texture2D(sampler2D,vec2)  (type:texture2D(sampler2D,vec2), id:54)
vec4 var2 = texture2D(sEmissiveMap, vec2(var3, (var7 + vVarying3)));
// based on node break vec4  (type:breakVec4, id:58)
float var1 = var2.x;

// read custom ctencil buffer
vec2 position = gl_FragCoord.xy * cGBufferInvSize;
float stencil = 1.0 - texture2D(sSpecMap, position).r;

float opacity = (stencil + var2.g) * var2.r;

gl_FragColor = vec4(vec4((vVarying6 + (vec4(0.0,0.0,0.0,0.0) + mix(((cAnotherWorldColorMul * (textureCube(sEnvCubeMap, reflect(normalize((cCameraPos - vVarying4)), vVarying5)) * var2.z)) * cAnotherWorldGlowMul), mix(cPortalColor_1, cPortalColor_2, texture2D(sDiffMap, vec2(var3, (vVarying1 + (2 * var7)))).x), mix((var1 * var2.y), var1, float(gl_FrontFacing)))).xyz), vVarying7).xyz, opacity);

}
#endif
#elif
#ifdef COMPILEVS

attribute vec4 iPos;
uniform mat4 cModel;
uniform mat4 cViewProj;
uniform vec4 cClipPlane;

void VS()
{
	mat4 var1 = cModel;
	vec4 ret =  (vec4((iPos * var1).xyz, 1.0) * cViewProj);

    // While getting the clip coordinate, also automatically set gl_ClipVertex for user clip planes
    #if !defined(GL_ES) && !defined(GL3)
       gl_ClipVertex = ret;
    #elif defined(GL3)
       gl_ClipDistance[0] = dot(cClipPlane, ret);
    #endif
    gl_Position = ret;
}

#else
// ------------------- Pixel Shader ---------------

void PS()
{
    gl_FragColor = vec4(1.0, 0.0, 0.0, 0.5);
}
#endif
#endif
