Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import "MatDefs/ShaderLib/noise3D.glsllib"
- #import "MatDefs/ShaderLib/utils.glsllib"
- #import "MatDefs/ShaderLib/shadowmap.glsllib"
- varying vec3 vecPositionInWorld;
- varying vec3 vecPosition;
- varying vec3 vecNormal;
- //diffuse
- varying vec3 texCoord;
- //glow + specular + specular with sparkling
- varying vec3 texCoord2;
- #ifdef LIGHTMAPSHADING
- uniform sampler3D m_LightMap0;
- uniform sampler3D m_LightMap1;
- uniform sampler3D m_LightMap2;
- uniform sampler3D m_LightMap3;
- uniform sampler3D m_LightMap4;
- uniform sampler3D m_LightMap5;
- uniform sampler3D m_LightMap6;
- uniform sampler3D m_LightMap7;
- uniform sampler3D m_LightMap8;
- uniform sampler2D m_GlobalAttributesMap;
- uniform float m_LightMapNormalMultiplicator;
- #else
- uniform bool m_Holographic;
- uniform vec4 m_HolographicColor;
- #endif
- uniform vec3 g_CameraPosition;
- uniform float g_Time;
- #ifdef TEXTUREATLAS
- uniform sampler2DArray m_DiffuseTextures;
- uniform sampler2DArray m_GlowTextures;
- uniform sampler2DArray m_SpecularTextures;
- uniform sampler2DArray m_SpecularWithSparklingTextures;
- #else
- uniform sampler2D m_DiffuseTexture;
- #endif
- #ifdef MIPMAPPING
- varying float mipMapDepth;
- uniform vec2[5] m_MipMapPositions;
- uniform vec2[5] m_MipMapSizes;
- #endif
- /**
- * returns a sigmoid distributed mix of val0 and val1. It is quite
- * similar to the mix() function but it uses a stronger
- * non-linear transition that is based on a variation of the sigmoid
- * function. the factor should be greater or equal to 5.
- */
- vec4 getSigMix(vec4 val0, vec4 val1, float pos, float factor) {
- float mixFactor = 1.0 / (1 + exp(-((pos * 2 * factor) - factor)));
- return mix(val0, val1, max(0.0, min(1.0, mixFactor)));
- }
- float rand(vec2 co){
- return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
- }
- void main() {
- vec3 normal = vecNormal;
- vec4 diffuseColor = vec4(0.0, 0.0, 0.0, 1.0);
- vec4 glowColor = vec4(0.0, 0.0, 0.0, 0.0);
- vec4 specularColor = vec4(0.0, 0.0, 0.0, 0.0);
- vec3 currentTexCoords = vec3(texCoord);
- vec3 currentTexCoords2 = vec3(texCoord2);
- #ifdef TEXTUREATLAS
- diffuseColor = texture(m_DiffuseTextures, currentTexCoords);
- #else
- diffuseColor = texture(m_DiffuseTexture, vec2(currentTexCoords));
- #endif
- #ifdef LIGHTMAPSHADING
- vec4 globalLight = getAttributeAt(m_GlobalAttributesMap, ivec2(0.0, 0.0));
- vec4 globalColor = getAttributeAt(m_GlobalAttributesMap, ivec2(1.0, 0.0));
- float depthFogDistance = decodeFloat(getAttributeAt(m_GlobalAttributesMap, ivec2(2.0, 0.0))) / 1000.0;
- //glow + specular
- #ifdef TEXTUREATLAS
- //glow
- if (currentTexCoords2.x > 0) {
- glowColor = texture(m_GlowTextures, vec3(currentTexCoords.x, currentTexCoords.y, currentTexCoords2.x));
- }
- //specular + sparkle
- if (currentTexCoords2.y > 0 || currentTexCoords2.z > 0) {
- bool sparkle = currentTexCoords2.z > 0;
- vec4 specularValueBox;
- if (!sparkle) {
- specularValueBox = texture(m_SpecularTextures, vec3(currentTexCoords.x, currentTexCoords.y, currentTexCoords2.y));
- } else {
- specularValueBox = texture(m_SpecularWithSparklingTextures, vec3(currentTexCoords.x, currentTexCoords.y, currentTexCoords2.z));
- }
- vec3 reflectionVector = reflect(normalize(vecPositionInWorld - g_CameraPosition), normalize(normal));
- float sparkleFactor = 1.0;
- if (sparkle) {
- sparkleFactor = (snoise((reflectionVector + vec3(texCoord.x, texCoord.y, 0.0)) * 20.0) + 1.0);
- }
- vec3 specularLightPosition = vecPosition + reflectionVector;
- float blockLightAtSpecularPosition = getCubedMixedLightMapValueAt(specularLightPosition,
- m_LightMap0, m_LightMap1, m_LightMap2, m_LightMap3, m_LightMap4, m_LightMap5, m_LightMap6, m_LightMap7, m_LightMap8).g;
- specularColor = blockLightAtSpecularPosition * specularValueBox;
- specularColor = specularColor * sparkleFactor;
- specularColor.a = specularValueBox.a;
- }
- #endif
- float alpha = diffuseColor.a;
- //important for transparent materials!
- if(alpha < 0.10){
- discard;
- }
- vec3 lightMapSamplePosition = vecPosition + m_LightMapNormalMultiplicator * normal;
- vec4 lightMapValueIn = getCubedMixedLightMapValueAt(vecPosition - 0.05 * normal,
- m_LightMap0, m_LightMap1, m_LightMap2, m_LightMap3, m_LightMap4, m_LightMap5, m_LightMap6, m_LightMap7, m_LightMap8);
- vec4 lightMapValue = getCubedMixedLightMapValueAt(lightMapSamplePosition,
- m_LightMap0, m_LightMap1, m_LightMap2, m_LightMap3, m_LightMap4, m_LightMap5, m_LightMap6, m_LightMap7, m_LightMap8);
- float dayLight = lightMapValue.r;
- float blockLight = lightMapValue.g;
- float energyGlow = min(0.8, (lightMapValue.b + lightMapValueIn.b) * 0.8);
- float dayLightValue = min(dayLight, 1.0);
- float blockLightValue = min(blockLight, 1.0);
- //it's allways bright on the top most level
- if (lightMapSamplePosition.y >= 128) {
- dayLightValue = 1.0;
- }
- vec4 totalLighting = vec4(dayLightValue, dayLightValue, dayLightValue, 1.0);
- totalLighting = totalLighting * globalLight + blockLightValue;
- totalLighting = max(totalLighting, vec4(0.02, 0.02, 0.02, 1.0));
- gl_FragColor = totalLighting * diffuseColor + specularColor * specularColor.a + glowColor;
- gl_FragColor = mix(gl_FragColor, mix(diffuseColor, vec4(1.0, 0.0, 0.0, 1.0), 0.75), energyGlow);
- #else
- if (m_Holographic) {
- //vec4 scanline = vec4(diffuseColor.r * 0.3, min(1.0, diffuseColor.g * 1.3), diffuseColor.b * 0.3, 0.8);
- vec4 scanline = diffuseColor * m_HolographicColor;
- float time = g_Time / 16.0;
- float noise = (snoise(vec3(vecPosition.y + time, vecPosition.y + time, vecPosition.y + time) * 20.0) + 1.0) / 2.0;
- if (noise > 0.5) {
- scanline.a = 0.85;
- } else {
- scanline.a = 0.4;
- }
- gl_FragColor = scanline;
- } else {
- gl_FragColor = diffuseColor;
- }
- #endif
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement