Skip to content

Legion Shading

fallenoak edited this page Sep 10, 2016 · 6 revisions

Structs

PSFog

struct PSFog
{
    vec4 densityParams;                    // vec4(start, end, density, bias)
    vec4 heightPlane;                      // vec4(?)
    vec4 color_and_heightRate;             // vec4(r, g, b, heightRate)
    vec4 heightDensity_and_endColor;       // vec4(heightDensity, r, g, b)
    vec4 sunAngle_and_sunColor;            // vec4(sunAngle, r, g, b)
    vec4 heightColor_and_endFogDistance;   // vec4(r, g, b, endFogDistance)
    vec4 sunPercentage;                    // vec4(?)
};

PSFogTransition

struct PSFogTransition
{
    vec4 densityParams;                    // vec4(start, end, density, bias)
    vec4 color;                            // vec4(?)
};

Vertex Shaders

MapObjDiffuse_T1

Permutation 36

#version 150

#extension GL_ARB_separate_shader_objects : require
#extension GL_ARB_explicit_attrib_location : require

layout(location = 0) in vec3 in_pos; // Binding: 0
layout(location = 3) in vec3 in_normal; // Binding: 3
layout(location = 4) in vec4 in_col0; // Binding: 4
layout(location = 6) in vec2 in_tc0; // Binding: 6

layout(location = 1) out vec4 out_col0; // Binding: 1
layout(location = 2) out vec4 out_vpos; // Binding: 2
layout(location = 3) out vec3 out_vnrml; // Binding: 3
layout(location = 4) out vec2 out_tc0; // Binding: 4

layout(std140) uniform vs_cb0 // Size: 3264
{
    mat4x4 vc_projection; // Offset: 0
    mat2x4 vc_texTransform[2]; // Offset: 4
    vec4 v_padding8[4]; // Offset: 8
    mat3x4 vc_worldView[64]; // Offset: 12
};

out gl_PerVertex
{
    vec4 gl_Position;
};

void main()
{
    vec3 position_410 = vec4(in_pos, 1.0) * vc_worldView[0];

    mat3x3 worldView = mat3x3(
        vc_worldView[0][0].xyz, 
        vc_worldView[0][1].xyz, 
        vc_worldView[0][2].xyz
    );

    out_col0 = vec4(in_col0.rgb, 1.0);

    out_vpos = vec4(position_410, 1.0 - in_col0.a);

    vec3 normal_420 = normalize((in_normal * worldView));
    out_vnrml = normal_420;

    out_tc0 = vec4(in_tc0, 0.0, 1.0) * vc_texTransform[0];

    gl_Position = vec4(position_410, 1.0) * vc_projection;
    gl_Position.y *= -1.0;
}

Pixel Shaders

MapObjOpaque

Permutation: 199

#version 150

#extension GL_ARB_separate_shader_objects : require
#extension GL_ARB_explicit_attrib_location : require

struct PSFog
{
    vec4 densityParams;
    vec4 heightPlane;
    vec4 color_and_heightRate;
    vec4 heightDensity_and_endColor;
    vec4 sunAngle_and_sunColor;
    vec4 heightColor_and_endFogDistance;
    vec4 sunPercentage;
};

struct PSFogTransition
{
    vec4 densityParams;
    vec4 color;
};

layout(location = 1) in vec4 in_col0; // Binding: 1
layout(location = 2) in vec4 in_col1; // Binding: 2
layout(location = 3) in vec4 in_vpos; // Binding: 3
layout(location = 4) in vec3 in_vnrml; // Binding: 4
layout(location = 5) in vec2 in_tc0; // Binding: 5

layout(location = 0) out vec4 out_col0; // Binding: 0

layout(std140) uniform ps_cb0 // Size: 368
{
    vec4 p_padding0[7]; // Offset: 0
    vec4 pc_sunDir; // Offset: 7
    vec4 p_padding8; // Offset: 8
    PSFog pc_fog; // Offset: 9
    PSFogTransition pc_fog2; // Offset: 16
    vec4 p_padding18[4]; // Offset: 18
    vec4 pc_visParams; // Offset: 22
};

uniform sampler2D pt_map0; // Binding: 0

void main()
{
    vec3 matDiffuse_775 = ((in_col0.rgb * 2.0) * texture(pt_map0, in_tc0).rgb);

    float opacity = in_col0.w * pc_visParams.x;
    vec4 t678 = vec4(matDiffuse_775.rgb, opacity);

    float vLength = length(in_vpos.xyz);

    # Fog

    vec4 fogHeightPlane = pc_fog.heightPlane;

    vec3 fogColor = pc_fog.color_and_heightRate.xyz;
    float fogHeightRate = pc_fog.color_and_heightRate.w;

    float fogHeightDensity = pc_fog.heightDensity_and_endColor.x;
    vec3 fogEndColor = pc_fog.heightDensity_and_endColor.yzw;

    float fogStart = pc_fog.densityParams.x;
    float fogEnd = pc_fog.densityParams.y;
    float fogDensity = pc_fog.densityParams.z;
    float fogBias = pc_fog.densityParams.w;

    float z_868 = vLength - fogBias;

    float expMax_870 = max(0.0, (z_868 - fogStart));
    float expFog_873 = 1 / (exp((expMax_870 * fogDensity)));
    float expFogHeight_876 = 1 / (exp((expMax_870 * fogHeightDensity)));

    float height_880 = dot(fogHeightPlane.xyz, in_vpos.xyz) + fogHeightPlane.w;
    float heightFog_882 = clamp((height_880 * fogHeightRate), 0, 1);
    float finalFog_883 = mix(expFog_873, expFogHeight_876, heightFog_882);
    float endFadeFog_887 = clamp((1.42857146 * (1.0 - (vLength / fogEnd))), 0, 1);

    # Fog Transition

    vec3 fogTransitionColor = pc_fog2.color.rgb;

    float fogTransitionStart = pc_fog2.densityParams.x;
    float fogTransitionEnd = pc_fog2.densityParams.y;
    float fogTransitionDensity = pc_fog2.densityParams.z;
    float fogTransitionBias = pc_fog2.densityParams.w;

    float z_907 = vLength - fogTransitionBias;

    float expMax_909 = max(0.0, (z_907 - fogTransitionStart));
    float expFog_912 = 1 / (exp((expMax_909 * fogTransitionDensity)));
    float expFogHeight_915 = 1 / (exp((expMax_909 * fogHeightDensity)));

    float height_919 = (dot(fogHeightPlane.xyz, in_vpos.xyz) + fogHeightPlane.w);
    float heightFog_921 = clamp((height_919 * fogHeightRate), 0, 1);
    float finalFog_922 = mix(expFog_912, expFogHeight_915, heightFog_921);
    float endFadeFog_926 = clamp(1.42857146 * (1.0 - (vLength / fogTransitionEnd)), 0, 1);

    # Fog Mixing

    float density_343 = mix(min(finalFog_883, endFadeFog_887), min(finalFog_922, endFadeFog_926), in_vpos.w);

    float heightFog_344 = mix(heightFog_882, heightFog_921, in_vpos.w);

    vec3 fogColor_349 = mix(fogColor, fogTransitionColor, vec3(in_vpos.w));

    float sunAngle = pc_fog.sunAngle_and_sunColor.x;
    vec3 sunColor = pc_fog.sunAngle_and_sunColor.yzw;

    vec3 fogHeightColor = pc_fog.heightColor_and_endFogDistance.xyz;
    float endFogDistance = pc_fog.heightColor_and_endFogDistance.w;

    float end2_948 = vLength / endFogDistance;
    float end_950 = (end2_948 * (end2_948 * end2_948));

    vec3 heightColor_953 = mix(fogHeightColor, fogEndColor, vec3(clamp(end2_948, 0, 1)));
    vec3 fogFinal_956 = mix(fogColor_349, fogEndColor, vec3(clamp(end_950, 0, 1)));
    vec3 fogFinal_958 = mix(fogFinal_956, heightColor_953, vec3(heightFog_344));

    # Sun

    vec3 sunColor_962 = mix(fogFinal_958, sunColor, vec3(pc_fog.sunPercentage.x));

    float nDotSun_960 = dot(normalize(in_vpos.xyz), -(pc_sunDir.xyz));
    float nDotSun_964 = clamp((nDotSun_960 - sunAngle), 0, 1);

    vec3 fogFinal_1042;

    if (nDotSun_964 > 0.0) {
        float nDotSun_969 = ((1.0 / (1.0 - sunAngle)) * nDotSun_964);
        float nDotSun_971 = ((nDotSun_969 * nDotSun_969) * nDotSun_969);
        fogFinal_1042 = mix(fogFinal_958, sunColor_962, vec3(nDotSun_971));
    } else {
        fogFinal_1042 = fogFinal_958;
    }

    // Final Mixing

    vec4 t980 = vec4(mix(fogFinal_1042, t678.xyz, vec3(density_343)), opacity);

    out_col0 = t980;
}
Clone this wiki locally