Skip to content

Instantly share code, notes, and snippets.

@jherico
Created June 12, 2018 19:15
Show Gist options
  • Save jherico/a4868b0992fff4c7732b119badbb08ce to your computer and use it in GitHub Desktop.
Save jherico/a4868b0992fff4c7732b119badbb08ce to your computer and use it in GitHub Desktop.
#version 450
struct LightingModel
{
vec4 _UnlitEmissiveLightmapBackground;
vec4 _ScatteringDiffuseSpecularAlbedo;
vec4 _AmbientDirectionalPointSpot;
vec4 _ShowContourObscuranceWireframe;
vec4 _Haze_spareyzw;
};
struct Material
{
vec4 _emissiveOpacity;
vec4 _albedoRoughness;
vec4 _fresnelMetallic;
vec4 _scatteringSpare2Key;
};
struct TexMapArray
{
mat4 _texcoordTransforms0;
mat4 _texcoordTransforms1;
vec4 _lightmapParams;
};
struct ScatteringParameters
{
vec4 normalBendInfo;
vec4 curvatureInfo;
vec4 debugFlags;
};
layout(binding = 3, std140) uniform lightingModelBuffer
{
LightingModel lightingModel;
} _222;
layout(binding = 1, std140) uniform materialBuffer
{
Material _mat;
} _275;
layout(binding = 2, std140) uniform texMapArrayBuffer
{
TexMapArray _texMapArray;
} _377;
layout(binding = 2, std140) uniform subsurfaceScatteringParametersBuffer
{
ScatteringParameters parameters;
} _576;
layout(binding = 0) uniform sampler2D albedoMap;
layout(binding = 4) uniform sampler2D roughnessMap;
layout(binding = 1) uniform sampler2D normalMap;
layout(binding = 2) uniform sampler2D metallicMap;
layout(binding = 3) uniform sampler2D emissiveMap;
layout(binding = 9) uniform sampler2D scatteringSpecularBeckmann;
layout(binding = 8) uniform sampler2D scatteringLUT;
layout(location = 0) out vec4 _fragColor0;
layout(location = 1) out vec4 _fragColor1;
layout(location = 2) out vec4 _fragColor2;
layout(location = 3) out vec4 _fragColor3;
layout(location = 0) in vec2 _texCoord0;
layout(location = 1) in vec2 _texCoord1;
layout(location = 5) in vec3 _normalWS;
layout(location = 6) in vec3 _tangentWS;
layout(location = 9) in vec4 _positionES;
layout(location = 2) in vec3 _color;
Material getMaterial()
{
Material _279;
_279._emissiveOpacity = _275._mat._emissiveOpacity;
_279._albedoRoughness = _275._mat._albedoRoughness;
_279._fresnelMetallic = _275._mat._fresnelMetallic;
_279._scatteringSpare2Key = _275._mat._scatteringSpare2Key;
return _279;
}
int getMaterialKey(Material m)
{
return floatBitsToInt(m._scatteringSpare2Key.w);
}
vec4 fetchAlbedoMap(vec2 uv)
{
return texture(albedoMap, uv, -1.0);
}
float fetchRoughnessMap(vec2 uv)
{
return texture(roughnessMap, uv, -1.0).x;
}
vec3 fetchNormalMap(vec2 uv)
{
vec2 t = (texture(normalMap, uv, -1.0).xy - vec2(0.5)) * 2.0;
vec2 t2 = t * t;
return vec3(t.x, sqrt((1.0 - t2.x) - t2.y), t.y);
}
float fetchMetallicMap(vec2 uv)
{
return texture(metallicMap, uv, -1.0).x;
}
TexMapArray getTexMapArray()
{
TexMapArray _382;
_382._texcoordTransforms0 = _377._texMapArray._texcoordTransforms0;
_382._texcoordTransforms1 = _377._texMapArray._texcoordTransforms1;
_382._lightmapParams = _377._texMapArray._lightmapParams;
return _382;
}
vec3 fetchLightmapMap(vec2 uv)
{
vec2 lightmapParams = getTexMapArray()._lightmapParams.xy;
return vec3(lightmapParams.x) + (texture(emissiveMap, uv).xyz * lightmapParams.y);
}
float getMaterialOpacity(Material m)
{
return m._emissiveOpacity.w;
}
float evalOpaqueFinalAlpha(float alpha, float mapAlpha)
{
return mix(alpha, 1.0 - alpha, step(mapAlpha, 0.5));
}
vec3 getMaterialAlbedo(Material m)
{
return m._albedoRoughness.xyz;
}
float getMaterialRoughness(Material m)
{
return m._albedoRoughness.w;
}
float getMaterialMetallic(Material m)
{
return m._fresnelMetallic.w;
}
vec3 getMaterialFresnel(Material m)
{
return m._fresnelMetallic.xyz;
}
float packLightmappedMetallic(float metallic)
{
return mix(0.20000000298023223876953125, 0.300000011920928955078125, metallic);
}
vec2 signNotZero(vec2 v)
{
return vec2((v.x >= 0.0) ? 1.0 : (-1.0), (v.y >= 0.0) ? 1.0 : (-1.0));
}
vec2 float32x3_to_oct(vec3 v)
{
vec2 p = v.xy * (1.0 / ((abs(v.x) + abs(v.y)) + abs(v.z)));
vec2 _138;
if (v.z <= 0.0)
{
vec2 param = p;
_138 = (vec2(1.0) - abs(p.yx)) * signNotZero(param);
}
else
{
_138 = p;
}
return _138;
}
vec3 snorm12x2_to_unorm8x3(vec2 f)
{
vec2 u = vec2(round((clamp(f, vec2(-1.0), vec2(1.0)) * 2047.0) + vec2(2047.0)));
float t = floor(u.y / 256.0);
return floor(vec3(u.x / 16.0, (fract(u.x / 16.0) * 256.0) + t, u.y - (t * 256.0))) / vec3(255.0);
}
vec3 packNormal(vec3 n)
{
vec3 param = n;
vec2 param_1 = float32x3_to_oct(param);
return snorm12x2_to_unorm8x3(param_1);
}
float isLightmapEnabled()
{
return _222.lightingModel._UnlitEmissiveLightmapBackground.z;
}
void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 albedo, float roughness, float metallic, vec3 fresnel, vec3 lightmap)
{
if (alpha != 1.0)
{
discard;
}
float param = metallic;
_fragColor0 = vec4(albedo, packLightmappedMetallic(param));
vec3 param_1 = normal;
_fragColor1 = vec4(packNormal(param_1), clamp(roughness, 0.0, 1.0));
_fragColor2 = vec4(lightmap * isLightmapEnabled(), 1.0);
_fragColor3 = vec4((lightmap * isLightmapEnabled()) * albedo, 1.0);
}
void main()
{
Material mat = getMaterial();
Material param = mat;
int matKey = getMaterialKey(param);
vec4 _423;
if ((matKey & 1216) != 0)
{
vec2 param_1 = _texCoord0;
_423 = fetchAlbedoMap(param_1);
}
else
{
_423 = vec4(1.0);
}
vec4 albedo = _423;
float _439;
if ((matKey & 4096) != 0)
{
vec2 param_2 = _texCoord0;
_439 = fetchRoughnessMap(param_2);
}
else
{
_439 = 1.0;
}
float roughness = _439;
vec3 _452;
if ((matKey & 8192) != 0)
{
vec2 param_3 = _texCoord0;
_452 = fetchNormalMap(param_3);
}
else
{
_452 = vec3(0.0, 1.0, 0.0);
}
vec3 normalTexel = _452;
float _466;
if ((matKey & 2048) != 0)
{
vec2 param_4 = _texCoord0;
_466 = fetchMetallicMap(param_4);
}
else
{
_466 = 0.0;
}
float metallicTex = _466;
vec2 param_5 = _texCoord1;
vec3 lightmapVal = fetchLightmapMap(param_5);
vec3 normalizedNormal = normalize(_normalWS);
vec3 normalizedTangent = normalize(_tangentWS);
vec3 normalizedBitangent = cross(normalizedNormal, normalizedTangent);
vec3 localNormal = mix(normalTexel, vec3(0.0, 1.0, 0.0), vec3(smoothstep(30.0, 100.0, (-_positionES).z)));
vec3 fragNormal = vec3(((normalizedBitangent * localNormal.x) + (normalizedNormal * localNormal.y)) + (normalizedTangent * localNormal.z));
Material param_6 = mat;
float param_7 = getMaterialOpacity(param_6);
float param_8 = albedo.w;
Material param_9 = mat;
Material param_10 = mat;
Material param_11 = mat;
Material param_12 = mat;
vec3 param_13 = normalize(fragNormal);
float param_14 = evalOpaqueFinalAlpha(param_7, param_8);
vec3 param_15 = (getMaterialAlbedo(param_9) * albedo.xyz) * _color;
float param_16 = getMaterialRoughness(param_10) * roughness;
float param_17 = getMaterialMetallic(param_11) * metallicTex;
vec3 param_18 = getMaterialFresnel(param_12);
vec3 param_19 = lightmapVal;
packDeferredFragmentLightmap(param_13, param_14, param_15, param_16, param_17, param_18, param_19);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment