├── .gitignore ├── LICENSE ├── README.md ├── RenderChunk └── src │ ├── RenderChunk.fragment.sc │ ├── RenderChunk.varying.def.sc │ └── RenderChunk.vertex.sc ├── RenderChunkPrepass └── src │ ├── RenderChunkPrepass.fragment.sc │ ├── RenderChunkPrepass.varying.def.sc │ └── RenderChunkPrepass.vertex.sc ├── Sky └── src │ ├── Sky.fragment.sc │ ├── Sky.varying.def.sc │ └── Sky.vertex.sc ├── Stars └── src │ ├── Stars.fragment.sc │ ├── Stars.varying.def.sc │ └── Stars.vertex.sc ├── SunMoon └── src │ ├── SunMoon.fragment.sc │ ├── SunMoon.varying.def.sc │ └── SunMoon.vertex.sc ├── entity.fragment └── entity.vertex /.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AbbottMc/RenderDragonSourceCodeInv/d0fa0ece7f15b72a48c180ece57e7bbc55b9ee5f/.gitignore -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 OEOTYAN 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RenderDragonSorceCodeInv 2 | 3 | Forked from [OEOTYAN/RenderDragonSourceCodeInv](https://github.com/OEOTYAN/RenderDragonSourceCodeInv) 4 | 5 | Reverse render dragon shaders source code from .bin file 6 | -------------------------------------------------------------------------------- /RenderChunk/src/RenderChunk.fragment.sc: -------------------------------------------------------------------------------- 1 | $input v_color0, v_fog, v_texcoord0, v_lightmapUV 2 | 3 | #include 4 | 5 | SAMPLER2D(s_MatTexture, 0); 6 | SAMPLER2D(s_LightMapTexture, 1); 7 | SAMPLER2D(s_SeasonsTexture, 2); 8 | 9 | void main() { 10 | vec4 diffuse; 11 | 12 | #if defined(DEPTH_ONLY_OPAQUE) || defined(DEPTH_ONLY) 13 | diffuse.rgb = vec3(1.0, 1.0, 1.0); 14 | #else 15 | diffuse = texture2D(s_MatTexture, v_texcoord0); 16 | 17 | #if defined(ALPHA_TEST) 18 | if (diffuse.a < 0.5) { 19 | discard; 20 | } 21 | #endif 22 | 23 | #if defined(SEASONS) && (defined(OPAQUE) || defined(ALPHA_TEST)) 24 | diffuse.rgb *= 25 | mix(vec3(1.0, 1.0, 1.0), 26 | texture2D(s_SeasonsTexture, v_color0.xy).rgb * 2.0, v_color0.b); 27 | diffuse.rgb *= v_color0.aaa; 28 | #else 29 | diffuse *= v_color0; 30 | #endif 31 | #endif 32 | 33 | #ifndef TRANSPARENT 34 | diffuse.a = 1.0; 35 | #endif 36 | 37 | diffuse.rgb *= texture2D(s_LightMapTexture, v_lightmapUV).rgb; 38 | 39 | diffuse.rgb = mix(diffuse.rgb,v_fog.rgb,v_fog.a); 40 | gl_FragColor = diffuse; 41 | } -------------------------------------------------------------------------------- /RenderChunk/src/RenderChunk.varying.def.sc: -------------------------------------------------------------------------------- 1 | vec4 a_color0 : COLOR0; 2 | vec3 a_position : POSITION; 3 | vec2 a_texcoord0 : TEXCOORD0; 4 | vec2 a_texcoord1 : TEXCOORD1; 5 | 6 | vec4 i_data0 : TEXCOORD8; 7 | vec4 i_data1 : TEXCOORD7; 8 | vec4 i_data2 : TEXCOORD6; 9 | vec4 i_data3 : TEXCOORD5; 10 | 11 | vec4 v_color0 : COLOR0; 12 | vec4 v_fog : COLOR2; 13 | vec2 v_texcoord0 : TEXCOORD0; 14 | vec2 v_lightmapUV : TEXCOORD1; 15 | vec3 v_position : TEXCOORD2; -------------------------------------------------------------------------------- /RenderChunk/src/RenderChunk.vertex.sc: -------------------------------------------------------------------------------- 1 | $input a_color0, a_position, a_texcoord0, a_texcoord1 2 | #ifdef INSTANCING 3 | $input i_data0, i_data1, i_data2, i_data3 4 | #endif 5 | $output v_color0, v_fog, v_texcoord0, v_lightmapUV 6 | 7 | #include 8 | 9 | uniform vec4 RenderChunkFogAlpha; 10 | uniform vec4 FogAndDistanceControl; 11 | uniform vec4 ViewPositionAndTime; 12 | uniform vec4 FogColor; 13 | 14 | void main() { 15 | mat4 model; 16 | #ifdef INSTANCING 17 | model = mtxFromCols(i_data0, i_data1, i_data2, i_data3); 18 | #else 19 | model = u_model[0]; 20 | #endif 21 | 22 | vec3 worldPos = mul(model, vec4(a_position, 1.0)).xyz; 23 | vec4 color; 24 | #ifdef RENDER_AS_BILLBOARDS 25 | worldPos += vec3(0.5, 0.5, 0.5); 26 | vec3 viewDir = normalize(worldPos - ViewPositionAndTime.xyz); 27 | vec3 boardPlane = normalize(vec3(viewDir.z, 0.0, -viewDir.x)); 28 | worldPos = (worldPos - 29 | ((((viewDir.yzx * boardPlane.zxy) - (viewDir.zxy * boardPlane.yzx)) * 30 | (a_color0.z - 0.5)) + 31 | (boardPlane * (a_color0.x - 0.5)))); 32 | color = vec4(1.0, 1.0, 1.0, 1.0); 33 | #else 34 | color = a_color0; 35 | #endif 36 | 37 | vec3 modelCamPos = (ViewPositionAndTime.xyz - worldPos); 38 | float camDis = length(modelCamPos); 39 | vec4 fogColor; 40 | fogColor.rgb = FogColor.rgb; 41 | fogColor.a = clamp(((((camDis / FogAndDistanceControl.z) + RenderChunkFogAlpha.x) - 42 | FogAndDistanceControl.x) / (FogAndDistanceControl.y - FogAndDistanceControl.x)), 0.0, 1.0); 43 | 44 | #ifdef TRANSPARENT 45 | if(a_color0.a < 0.95) { 46 | color.a = mix(a_color0.a, 1.0, clamp((camDis / FogAndDistanceControl.w), 0.0, 1.0)); 47 | }; 48 | #endif 49 | 50 | v_texcoord0 = a_texcoord0; 51 | v_lightmapUV = a_texcoord1; 52 | v_color0 = color; 53 | v_fog = fogColor; 54 | gl_Position = mul(u_viewProj, vec4(worldPos, 1.0)); 55 | } 56 | -------------------------------------------------------------------------------- /RenderChunkPrepass/src/RenderChunkPrepass.fragment.sc: -------------------------------------------------------------------------------- 1 | $input v_color0, v_fog, v_normal, v_tangent, v_bitangent, v_texcoord0, v_lightmapUV, v_worldPos, v_pbrTextureId 2 | #include 3 | 4 | struct PBRTextureData { 5 | highp float colourToMaterialUvScale0; 6 | highp float colourToMaterialUvScale1; 7 | highp float colourToMaterialUvBias0; 8 | highp float colourToMaterialUvBias1; 9 | highp float colourToNormalUvScale0; 10 | highp float colourToNormalUvScale1; 11 | highp float colourToNormalUvBias0; 12 | highp float colourToNormalUvBias1; 13 | int flags; 14 | highp float uniformRoughness; 15 | highp float uniformEmissive; 16 | highp float uniformMetalness; 17 | highp float maxMipColour; 18 | highp float maxMipMer; 19 | highp float maxMipNormal; 20 | highp float pad; 21 | }; 22 | 23 | layout(binding = 67, std430) readonly buffer s_PBRData { 24 | PBRTextureData data[]; 25 | } PBRData; 26 | 27 | SAMPLER2D(s_MatTexture, 0); 28 | SAMPLER2D(s_LightMapTexture, 1); 29 | SAMPLER2D(s_SeasonsTexture, 2); 30 | 31 | void main() { 32 | int pbrTextureId = v_pbrTextureId; 33 | vec3 worldPos = v_worldPos.xyz; 34 | vec4 albedo = texture2D(s_MatTexture, v_texcoord0); 35 | 36 | #ifdef ALPHA_TEST 37 | if (albedo.a < 0.5) { 38 | discard; 39 | } 40 | #endif 41 | 42 | #ifdef SEASONS 43 | albedo.rgb *= mix(vec3(1.0, 1.0, 1.0), texture2D(s_SeasonsTexture, v_color0.xy).rgb * 2.0, v_color0.b); 44 | albedo.rgb *= v_color0.aaa; 45 | #else 46 | albedo *= v_color0; 47 | #endif 48 | 49 | vec4 vanillaLight = 50 | Texture2D(s_LightMapTexture, min(BlockSkyAmbientContribution.xy * v_lightmapUV.xy, vec2(1.0, 1.0))); 51 | float emissive; 52 | float metallic; 53 | float roughness; 54 | if ((PBRData.data[pbrTextureId].flags & 1) == 1) /*have mer texture*/ { 55 | vec3 merTex = 56 | texture2D(s_MatTexture, fma(v_texcoord0, vec2(PBRData.data[pbrTextureId].colourToMaterialUvScale0, 57 | PBRData.data[pbrTextureId].colourToMaterialUvScale1), 58 | vec2(PBRData.data[pbrTextureId].colourToMaterialUvBias0, 59 | PBRData.data[pbrTextureId].colourToMaterialUvBias1))).xyz; 60 | metallic = merTex.x; 61 | emissive = merTex.y; 62 | roughness = merTex.z; 63 | } else { 64 | metallic = PBRData.data[pbrTextureId].uniformMetalness; 65 | emissive = PBRData.data[pbrTextureId].uniformEmissive; 66 | roughness = PBRData.data[pbrTextureId].uniformRoughness; 67 | } 68 | vec3 GNormal = normalize(v_normal.xyz); 69 | float rGNormalManhattanLength = 1.0f / (abs(GNormal.x) + abs(GNormal.y) + abs(GNormal.z)); 70 | float NX = rGNormalManhattanLength * GNormal.x; 71 | float NY = rGNormalManhattanLength * GNormal.y; 72 | bool isDownFace = GNormal.z < 0.0; 73 | vec3 modelCamPos = (ViewPositionAndTime.xyz - worldPos); 74 | float camDis = length(modelCamPos); 75 | vec3 viewDir = normalize(-modelCamPos); 76 | 77 | ivec3 intGNormal = ivec3(fma(GNormal, vec3(0.5), vec3(0.5)) * 1023.0) & ivec3(1023); 78 | 79 | gl_FragData[0].xyz = sqrt(albedo.xyz); // FUCK YOU MOJANG gamma 2.0 80 | gl_FragData[0].w = metallic; 81 | 82 | gl_FragData[1].x = isDownFace ? ((1.0f - abs(NY)) * ((NX >= 0.0f) ? 1.0f : (-1.0f))) : NX; 83 | gl_FragData[1].y = isDownFace ? ((1.0f - abs(NX)) * ((NY >= 0.0f) ? 1.0f : (-1.0f))) : NY; 84 | gl_FragData[1].zw = 0.0f; 85 | 86 | gl_FragData[2].xy = emissive; 87 | gl_FragData[2].z = dot(vec3(0.299, 0.587, 0.114), vec3(vanillaLight.xyz)); 88 | gl_FragData[2].w = roughness; 89 | 90 | gl_FragData[3].x = intBitsToFloat((((0 ^ (intGNormal.x << 22)) ^ (intGNormal.y << 18)) ^ (intGNormal.z << 14)) + 91 | int(dot(GNormal, worldPos))); 92 | 93 | gl_FragData[3].yzw = 0.0f; 94 | 95 | gl_FragData[4].xyz = worldPos; 96 | gl_FragData[4].w = camDis; 97 | 98 | gl_FragData[5].xyz = worldPos; 99 | gl_FragData[5].w = camDis; 100 | 101 | gl_FragData[6].xyz = viewDir; 102 | gl_FragData[6].w = float( 103 | #ifndef SEASONS 104 | (albedo.a < 0.8) || 105 | #endif 106 | ((metallic == 1.0) && (roughness < 0.01))); // is specular 107 | } 108 | -------------------------------------------------------------------------------- /RenderChunkPrepass/src/RenderChunkPrepass.varying.def.sc: -------------------------------------------------------------------------------- 1 | vec4 a_color0 : COLOR0; 2 | vec4 a_normal : NORMAL; 3 | vec4 a_tangent : TANGENT; 4 | vec3 a_position : POSITION; 5 | vec2 a_texcoord0 : TEXCOORD0; 6 | vec2 a_texcoord1 : TEXCOORD1; 7 | int a_pbrTextureId : TEXCOORD4; 8 | 9 | vec4 i_data0 : TEXCOORD8; 10 | vec4 i_data1 : TEXCOORD7; 11 | vec4 i_data2 : TEXCOORD6; 12 | vec4 i_data3 : TEXCOORD5; 13 | 14 | vec4 v_color0 : COLOR0; 15 | vec4 v_fog : COLOR2; 16 | vec3 v_normal : NORMAL; 17 | vec3 v_tangent : TANGENT; 18 | vec3 v_bitangent : BITANGENT; 19 | vec2 v_texcoord0 : TEXCOORD0; 20 | vec2 v_lightmapUV : TEXCOORD1; 21 | vec3 v_worldPos : TEXCOORD3; 22 | int v_pbrTextureId : TEXCOORD4; -------------------------------------------------------------------------------- /RenderChunkPrepass/src/RenderChunkPrepass.vertex.sc: -------------------------------------------------------------------------------- 1 | $input a_color0, a_normal, a_tangent, a_position, a_texcoord0, a_texcoord1, a_pbrTextureId 2 | #ifdef INSTANCING 3 | $input i_data0, i_data1, i_data2, i_data3 4 | #endif 5 | $output v_color0, v_fog, v_normal, v_tangent, v_bitangent, v_texcoord0, v_lightmapUV, v_worldPos, v_pbrTextureId 6 | 7 | #include 8 | 9 | uniform vec4 RenderChunkFogAlpha; 10 | uniform vec4 FogAndDistanceControl; 11 | uniform vec4 ViewPositionAndTime; 12 | uniform vec4 FogColor; 13 | 14 | void main() { 15 | mat4 model; 16 | #ifdef INSTANCING 17 | model = mtxFromCols(i_data0, i_data1, i_data2, i_data3); 18 | #else 19 | model = u_model[0]; 20 | #endif 21 | vec3 worldPos = mul(model, vec4(a_position, 1.0)).xyz; 22 | vec3 modelCamPos = (ViewPositionAndTime.xyz - worldPos); 23 | float camDis = length(modelCamPos); 24 | v_texcoord0 = a_texcoord0; 25 | v_lightmapUV = a_texcoord1; 26 | v_color0 = a_color0; 27 | v_normal = a_normal; 28 | v_tangent = a_tangent; 29 | v_bitangent = cross(a_normal.xyz, a_tangent.xyz); 30 | v_worldPos = worldPos; 31 | v_pbrTextureId = a_pbrTextureId & 65535; 32 | v_fog.xyz = FogColor.xyz; 33 | v_fog.w = clamp(((RenderChunkFogAlpha.x - FogAndDistanceControl.x) + (camDis / FogAndDistanceControl.z)) / 34 | (FogAndDistanceControl.y - FogAndDistanceControl.x), 0.0, 1.0); 35 | gl_Position = mul(u_viewProj, vec4(worldPos, 1.0)); 36 | } 37 | -------------------------------------------------------------------------------- /Sky/src/Sky.fragment.sc: -------------------------------------------------------------------------------- 1 | $input v_color0 2 | 3 | #include 4 | 5 | void main() { 6 | gl_FragColor = v_color0; 7 | } -------------------------------------------------------------------------------- /Sky/src/Sky.varying.def.sc: -------------------------------------------------------------------------------- 1 | vec4 a_color0 : COLOR0; 2 | vec3 a_position : POSITION; 3 | 4 | vec4 v_color0 : COLOR0; -------------------------------------------------------------------------------- /Sky/src/Sky.vertex.sc: -------------------------------------------------------------------------------- 1 | $input a_color0, a_position 2 | $output v_color0 3 | 4 | #include 5 | 6 | uniform highp vec4 SkyColor; 7 | uniform highp vec4 FogColor; 8 | void main() { 9 | v_color0 = mix(SkyColor, FogColor, a_color0.x); 10 | gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0)); 11 | } -------------------------------------------------------------------------------- /Stars/src/Stars.fragment.sc: -------------------------------------------------------------------------------- 1 | $input v_color0, v_starsColor 2 | 3 | #include 4 | 5 | void main() { 6 | vec4 starColor; 7 | starColor.w = v_color0.w; 8 | starColor.xyz = v_color0.xyz * v_starsColor.xyz * v_color0.w; 9 | gl_FragColor = starColor; 10 | } -------------------------------------------------------------------------------- /Stars/src/Stars.varying.def.sc: -------------------------------------------------------------------------------- 1 | vec4 a_color0 : COLOR0; 2 | vec3 a_position : POSITION; 3 | 4 | vec4 v_color0 : COLOR0; 5 | vec4 v_starsColor : COLOR2; -------------------------------------------------------------------------------- /Stars/src/Stars.vertex.sc: -------------------------------------------------------------------------------- 1 | $input a_color0, a_position 2 | $output v_color0, v_starsColor 3 | 4 | #include 5 | 6 | uniform vec4 StarsColor; 7 | 8 | void main() { 9 | v_color0 = a_color0; 10 | v_starsColor = StarsColor; 11 | gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0)); 12 | } -------------------------------------------------------------------------------- /SunMoon/src/SunMoon.fragment.sc: -------------------------------------------------------------------------------- 1 | $input v_texcoord0, v_sunMoonColor 2 | 3 | #include 4 | 5 | SAMPLER2D(s_SunMoonTexture, 0); 6 | 7 | void main() { 8 | gl_FragColor = v_sunMoonColor * texture2D(s_SunMoonTexture, v_texcoord0); 9 | } -------------------------------------------------------------------------------- /SunMoon/src/SunMoon.varying.def.sc: -------------------------------------------------------------------------------- 1 | vec3 a_position : POSITION; 2 | vec2 a_texcoord0 : TEXCOORD0; 3 | 4 | vec2 v_texcoord0 : TEXCOORD0; 5 | vec4 v_sunMoonColor : TEXCOORD2; -------------------------------------------------------------------------------- /SunMoon/src/SunMoon.vertex.sc: -------------------------------------------------------------------------------- 1 | $input a_position, a_texcoord0 2 | $output v_texcoord0, v_sunMoonColor 3 | 4 | #include 5 | 6 | uniform vec4 SunMoonColor; 7 | 8 | void main() { 9 | v_texcoord0 = a_texcoord0; 10 | v_sunMoonColor = SunMoonColor; 11 | gl_Position = u_modelViewProj * vec4(a_position, 1.0); 12 | } -------------------------------------------------------------------------------- /entity.fragment: -------------------------------------------------------------------------------- 1 | //for Actor ActorTint ActorMultiTexture ActorGlint Entity 2 | //Entity.Fragment 3 | 4 | //#define EMISSIVE 5 | //#define EMISSIVE_ONLY 6 | //#define CHANGE_COLOR 7 | //#define CHANGE_COLOR_MULTI 8 | //#define MASKED_MULTITEXTURE 9 | //#define ALPHA_TEST 10 | //#define COLOR_SECOND_TEXTURE 11 | 12 | //#define GLINT 13 | //#define TINT 14 | //#define MULTITEXTURE 15 | 16 | varying highp vec4 v_color0; 17 | varying highp vec4 v_fog; 18 | varying highp vec4 v_layerUv; 19 | varying highp vec4 v_light; 20 | varying highp vec2 v_texcoord0; 21 | uniform highp vec4 UseAlphaRewrite; 22 | uniform highp vec4 ChangeColor; 23 | uniform highp vec4 OverlayColor; 24 | uniform highp vec4 TintedAlphaTestEnabled; 25 | uniform highp vec4 ColorBased; 26 | uniform highp vec4 MatColor; 27 | uniform highp vec4 MultiplicativeTintColor; 28 | uniform highp vec4 TileLightColor; 29 | uniform highp vec4 GlintColor; 30 | uniform sampler2D s_MatTexture; 31 | uniform sampler2D s_MatTexture1; 32 | uniform sampler2D s_MatTexture2; 33 | 34 | highp vec4 glintBlend(highp vec4 dest, highp vec4 source) { 35 | // glBlendFuncSeparate(GL_SRC_COLOR, GL_ONE, GL_ONE, GL_ZERO) 36 | return vec4(source.rgb * source.rgb, abs(source.a)) + vec4(dest.rgb, 0.0); 37 | } 38 | 39 | #ifdef EMISSIVE 40 | #ifdef EMISSIVE_ONLY 41 | #define NEEDS_DISCARD(C) (C.a < 0.00390625 || C.a > 0.9960938 ) 42 | #else 43 | #define NEEDS_DISCARD(C) (dot (C,vec4(1.0, 1.0, 1.0, 1.0)) < 0.00390625) 44 | #endif 45 | #else 46 | #if defined(CHANGE_COLOR)||defined(CHANGE_COLOR_MULTI) 47 | #define NEEDS_DISCARD(C) (C.a < 0.5) 48 | #else 49 | #define NEEDS_DISCARD(C) (C.a < 0.00390625) 50 | #endif 51 | #endif 52 | 53 | void main() { 54 | highp vec4 color; 55 | 56 | color = MatColor * texture2D(s_MatTexture, v_texcoord0); 57 | 58 | #ifdef MASKED_MULTITEXTURE 59 | highp vec4 markings = texture2D(s_MatTexture1, v_texcoord0); 60 | 61 | // If markings has a non-black color and no alpha, use color; otherwise use markings 62 | highp float maskedTexture = float(dot(markings.rgb, vec3(1.0, 1.0, 1.0)) * (1.0 - markings.a) > 0.0); 63 | color = mix(markings, color, maskedTexture); 64 | #endif // MASKED_MULTITEXTURE 65 | 66 | #if defined(ALPHA_TEST) && !defined(MULTITEXTURE) && !defined(TINT) 67 | highp vec4 color_cmp; 68 | color_cmp.rgb = color.rgb; 69 | color_cmp.a = mix(color.a, (color.a * OverlayColor.a), TintedAlphaTestEnabled.r); 70 | if(NEEDS_DISCARD(color_cmp)) 71 | discard; 72 | #endif // ALPHA_TEST 73 | 74 | #ifdef CHANGE_COLOR_MULTI 75 | // Texture is a mask for tinting with two colors 76 | highp vec2 colorMask = color.rg; 77 | 78 | // Apply the base color tint 79 | color.rgb = colorMask.rrr * ChangeColor.rgb; 80 | 81 | // Apply the secondary color mask and tint so long as its grayscale value is not 0 82 | color.rgb = mix(color.rgb, colorMask.ggg * MultiplicativeTintColor.rgb, ceil(colorMask.g)); 83 | #else 84 | 85 | #ifdef CHANGE_COLOR 86 | color.rgb = mix(color.rgb, color.rgb * ChangeColor.rgb, color.a); 87 | color.a *= ChangeColor.a; 88 | #endif 89 | 90 | #endif// CHANGE_COLOR_MULTI 91 | 92 | #ifdef MULTITEXTURE 93 | highp vec4 tex1 = texture2D(s_MatTexture1, v_texcoord0); 94 | highp vec4 armor = texture2D(s_MatTexture2, v_texcoord0); 95 | color.rgb = mix(color.rgb, tex1.rgb, tex1.a); 96 | 97 | #ifdef COLOR_SECOND_TEXTURE 98 | if(armor.a > 0.0) { 99 | color.rgb =mix(armor.rgb, armor.rgb * ChangeColor.rgb, armor.a) 100 | } 101 | #else 102 | color.rgb = mix(color.rgb, armor.rgb, armor.a); 103 | #endif 104 | #ifdef ALPHA_TEST 105 | if(color.a < 0.5 && tex1.a < 0.00390625) { 106 | discard; 107 | } 108 | #endif 109 | #endif// MULTITEXTURE 110 | 111 | #ifdef TINT 112 | highp vec4 tintTex = texture2D(s_MatTexture1, v_texcoord0); 113 | tintTex.rgb = tintTex.rgb * MultiplicativeTintColor.rgb; 114 | 115 | #ifdef ALPHA_TEST 116 | color.rgb = mix(color.rgb, tintTex.rgb, tintTex.a); 117 | if(color.a + tintTex.a < 0.00390625) { 118 | discard; 119 | } 120 | #endif 121 | #endif// TINT 122 | 123 | #ifdef ALPHA_TEST 124 | color.a = max(UseAlphaRewrite.r, color.a); 125 | #endif 126 | color.rgb = color.rgb * mix(vec3(1.0, 1.0, 1.0), v_color0.rgb, ColorBased.r); 127 | color.rgb = mix(color.rgb, OverlayColor.rgb, OverlayColor.a); 128 | 129 | #if defined(EMISSIVE)||defined(EMISSIVE_ONLY) 130 | //make glowy stuff 131 | color.rgb *= mix(vec3(1.0, 1.0, 1.0), v_light.rgb, color.a); 132 | #else 133 | color.rgb *= v_light.rgb; 134 | #endif 135 | 136 | //apply fog 137 | color.rgb = mix(color.rgb, v_fog.rgb, v_fog.a); 138 | 139 | #ifdef GLINT 140 | // Applies color mask to glint texture instead and blends with original color 141 | highp vec4 layer1 = texture2D(s_MatTexture1, fract(v_layerUv.xy)).rgbr * GlintColor; 142 | highp vec4 layer2 = texture2D(s_MatTexture1, fract(v_layerUv.zw)).rgbr * GlintColor; 143 | highp vec4 glint = (layer1 + layer2) * TileLightColor; 144 | color = glintBlend(color, glint); 145 | #endif 146 | gl_FragColor = color; 147 | } -------------------------------------------------------------------------------- /entity.vertex: -------------------------------------------------------------------------------- 1 | //for Actor ActorTint ActorMultiTexture ActorGlint Entity BeaconBeam 2 | //Entity.vertex 3 | 4 | //#define SKINNING 5 | //#define INSTANCING 6 | //#define TRANSPARENT 7 | //#define ALPHA_TEST 8 | //#define GLINT 9 | //#define FANCY 10 | //#define DEPTH_ONLY 11 | //#define ENTITY 12 | //#define BEACON_BEAM 13 | 14 | attribute highp vec4 a_color0; 15 | attribute highp float a_indices; 16 | attribute highp vec4 a_normal; 17 | attribute highp vec3 a_position; 18 | attribute highp vec2 a_texcoord0; 19 | attribute highp vec4 i_data0; 20 | attribute highp vec4 i_data1; 21 | attribute highp vec4 i_data2; 22 | attribute highp vec4 i_data3; 23 | varying highp vec4 v_color0; 24 | varying highp vec4 v_fog; 25 | varying highp vec4 v_layerUv; 26 | varying highp vec4 v_light; 27 | varying highp vec2 v_texcoord0; 28 | varying highp vec4 v_texcoords; 29 | uniform highp vec4 FogControl; 30 | uniform highp mat4 u_viewProj; 31 | uniform highp mat4 u_modelViewProj; 32 | uniform highp vec4 OverlayColor; 33 | uniform mat4 u_model[4]; 34 | uniform mat4 Bones[8]; 35 | uniform highp vec4 UVAnimation; 36 | uniform highp vec4 FogColor; 37 | uniform highp vec4 TileLightColor; 38 | uniform highp vec4 UVScale; 39 | uniform vec4 BannerColors[7]; 40 | uniform vec4 BannerUVOffsetsAndScales[7]; 41 | 42 | #define AMBIENT (0.45) 43 | 44 | #define XFAC (-0.1) 45 | #define ZFAC (0.1) 46 | 47 | highp float lightIntensity(highp vec4 normal) { 48 | #ifdef FANCY 49 | highp vec3 N = normalize(u_model[0] * normal).xyz; 50 | N.y *= TileLightColor.w; 51 | highp float yLight = (1.0 + N.y) * 0.5; 52 | return yLight * (1.0 - AMBIENT) + N.x * N.x * XFAC + N.z * N.z * ZFAC + AMBIENT; 53 | #else 54 | return 1.0; 55 | #endif 56 | } 57 | 58 | #ifdef GLINT 59 | highp vec2 calculateLayerUV(highp float offset, highp float rotation) { 60 | highp vec2 uv = a_texcoord0; 61 | uv -= 0.5; 62 | highp float rsin = sin(rotation); 63 | highp float rcos = cos(rotation); 64 | uv = mat2(rcos, -rsin, rsin, rcos) * uv; 65 | uv.x += offset; 66 | uv += 0.5; 67 | 68 | return uv * UVScale; 69 | } 70 | #endif 71 | 72 | void main() { 73 | highp vec4 entitySpacePosition; 74 | highp vec4 position; 75 | #ifndef ENTITY 76 | #ifndef BEACON_BEAM 77 | highp mat4 World; 78 | #ifdef INSTANCING 79 | World[0] = i_data0; 80 | World[1] = i_data1; 81 | World[2] = i_data2; 82 | World[3] = i_data3; 83 | #else 84 | World = u_model[0]; 85 | #ifdef SKINNING 86 | World = World * Bones[int(a_indices)]; 87 | #endif 88 | #endif 89 | entitySpacePosition = World * vec4(a_position, 1.0); 90 | position = u_viewProj * entitySpacePosition; 91 | #else 92 | position = u_modelViewProj * vec4(a_position, 1.0); 93 | #endif 94 | #else 95 | position = u_modelViewProj * Bones[int(a_indices)] * vec4(a_position, 1.0); 96 | #endif 97 | 98 | highp float L = lightIntensity(a_normal); 99 | 100 | L += OverlayColor.a * 0.35; 101 | 102 | highp vec4 light = vec4(vec3(L) * TileLightColor.xyz, 1.0); 103 | 104 | highp vec4 fogColor; 105 | fogColor.rgb = FogColor.rgb; 106 | fogColor.a = clamp(((position.z / FogControl.z) - FogControl.x) / (FogControl.y - FogControl.x), 0.0, 1.0); 107 | 108 | #if defined(DEPTH_ONLY)&&!defined(BANNER) 109 | v_texcoord0 = vec2(0.0, 0.0); 110 | v_color0 = vec4(0.0, 0.0, 0.0, 0.0); 111 | #else 112 | highp vec2 uv = a_texcoord0; 113 | #ifdef GLINT 114 | v_layerUv.xy = calculateLayerUV(UVAnimation.x, UVAnimation.z); 115 | v_layerUv.zw = calculateLayerUV(UVAnimation.y, UVAnimation.w); 116 | #else 117 | #ifdef ENTITY 118 | v_layerUv = vec4(0.0, 0.0, 0.0, 0.0); 119 | #endif 120 | #if !(defined(TRANSPARENT)&&defined(BEACON_BEAM)) 121 | uv.xy = UVAnimation.xy + (uv.xy * UVAnimation.zw); 122 | #endif 123 | #endif 124 | v_texcoord0 = uv; 125 | v_color0 = a_color0; 126 | #endif 127 | #ifdef BANNER 128 | #ifdef ALPHA_TEST 129 | v_texcoords = vec4(0.0, 0.0, 0.0, 0.0); 130 | #else 131 | 132 | #endif 133 | #endif 134 | #if defined(TRANSPARENT)&&defined(BEACON_BEAM) 135 | v_fog = vec4(0.0, 0.0, 0.0, 0.0); 136 | v_light = vec4(0.0, 0.0, 0.0, 0.0); 137 | #else 138 | v_fog = fogColor; 139 | v_light = light; 140 | #endif 141 | gl_Position = position; 142 | } --------------------------------------------------------------------------------