1#version 460 2uniform int uTDInstanceIDOffset; 3uniform int uTDNumInstances; 4uniform float uTDAlphaTestVal; 5#define TD_NUM_COLOR_BUFFERS 1 6#define TD_NUM_LIGHTS 0 7#define TD_NUM_SHADOWED_LIGHTS 0 8#define TD_NUM_ENV_LIGHTS 0 9#define TD_LIGHTS_ARRAY_SIZE 1 10#define TD_ENV_LIGHTS_ARRAY_SIZE 1 11#define TD_NUM_CAMERAS 1 12struct TDPhongResult 13{ 14 vec3 diffuse; 15 vec3 specular; 16 vec3 specular2; 17 float shadowStrength; 18}; 19struct TDPBRResult 20{ 21 vec3 diffuse; 22 vec3 specular; 23 float shadowStrength; 24}; 25struct TDMatrix 26{ 27 mat4 world; 28 mat4 worldInverse; 29 mat4 worldCam; 30 mat4 worldCamInverse; 31 mat4 cam; 32 mat4 camInverse; 33 mat4 camProj; 34 mat4 camProjInverse; 35 mat4 proj; 36 mat4 projInverse; 37 mat4 worldCamProj; 38 mat4 worldCamProjInverse; 39 mat4 quadReproject; 40 mat3 worldForNormals; 41 mat3 camForNormals; 42 mat3 worldCamForNormals; 43}; 44layout(std140) uniform TDMatricesBlock { 45 TDMatrix uTDMats[TD_NUM_CAMERAS]; 46}; 47struct TDCameraInfo 48{ 49 vec4 nearFar; 50 vec4 fog; 51 vec4 fogColor; 52 int renderTOPCameraIndex; 53}; 54layout(std140) uniform TDCameraInfoBlock { 55 TDCameraInfo uTDCamInfos[TD_NUM_CAMERAS]; 56}; 57struct TDGeneral 58{ 59 vec4 ambientColor; 60 vec4 nearFar; 61 vec4 viewport; 62 vec4 viewportRes; 63 vec4 fog; 64 vec4 fogColor; 65}; 66layout(std140) uniform TDGeneralBlock { 67 TDGeneral uTDGeneral; 68}; 69 70void TDAlphaTest(float alpha); 71vec4 TDDither(vec4 color); 72vec4 TDOutputSwizzle(vec4 v); 73uvec4 TDOutputSwizzle(uvec4 v); 74void TDCheckOrderIndTrans(); 75void TDCheckDiscard(); 76uniform vec3 uConstant; 77uniform float uShadowStrength; 78uniform vec3 uShadowColor; 79uniform vec4 uDiffuseColor; 80uniform vec4 uAmbientColor; 81 82uniform sampler2DArray sColorMap; 83 84in Vertex 85{ 86 vec4 color; 87 vec3 worldSpacePos; 88 vec3 texCoord0; 89 flat int cameraIndex; 90 flat int instance; 91} iVert; 92 93// Output variable for the color 94layout(location = 0) out vec4 oFragColor[TD_NUM_COLOR_BUFFERS]; 95void main() 96{ 97 // This allows things such as order independent transparency 98 // and Dual-Paraboloid rendering to work properly 99 TDCheckDiscard(); 100 101 vec4 outcol = vec4(0.0, 0.0, 0.0, 0.0); 102 103 vec3 texCoord0 = iVert.texCoord0.stp; 104 float actualTexZ = mod(int(texCoord0.z),2048); 105 float instanceLoop = floor(int(texCoord0.z)/2048); 106 texCoord0.z = actualTexZ; 107 vec4 colorMapColor = texture(sColorMap, texCoord0.stp); 108 109 float red = colorMapColor[int(instanceLoop)]; 110 colorMapColor = vec4(red); 111 // Constant Light Contribution 112 outcol.rgb += uConstant * iVert.color.rgb; 113 114 outcol *= colorMapColor; 115 116 // Alpha Calculation 117 float alpha = iVert.color.a * colorMapColor.a ; 118 119 // Dithering, does nothing if dithering is disabled 120 outcol = TDDither(outcol); 121 122 outcol.rgb *= alpha; 123 124 // Modern GL removed the implicit alpha test, so we need to apply 125 // it manually here. This function does nothing if alpha test is disabled. 126 TDAlphaTest(alpha); 127 128 outcol.a = alpha; 129 oFragColor[0] = TDOutputSwizzle(outcol); 130 131 132 // TD_NUM_COLOR_BUFFERS will be set to the number of color buffers 133 // active in the render. By default we want to output zero to every 134 // buffer except the first one. 135 for (int i = 1; i < TD_NUM_COLOR_BUFFERS; i++) 136 { 137 oFragColor[i] = vec4(0.0); 138 } 139} 140