diff options
Diffstat (limited to 'src/main/resources/assets/gregtech/shaders')
4 files changed, 195 insertions, 0 deletions
diff --git a/src/main/resources/assets/gregtech/shaders/blackhole.frag.glsl b/src/main/resources/assets/gregtech/shaders/blackhole.frag.glsl new file mode 100644 index 0000000000..4334dde59e --- /dev/null +++ b/src/main/resources/assets/gregtech/shaders/blackhole.frag.glsl @@ -0,0 +1,42 @@ +#version 120 + +uniform float u_Time; +uniform float u_Stability; +uniform sampler2D u_Texture; +varying vec2 v_TexCoord; + +const vec3 STABLE_COLOR = vec3(1,0.85,0.043); +const vec3 UNSTABLE_COLOR = vec3(.4,0,0); + +vec3 toYIQ(vec3 rgb){ + return mat3( 0.299, 1.0, 0.40462981, 0.587, -0.46081557, -1.0, 0.114, -0.53918443, 0.59537019 ) * rgb; +} + +vec3 toRGB(vec3 yiq){ + return mat3( 1.0, 1.0, 1.0, 0.5696804, -0.1620848, -0.6590654, 0.3235513, -0.3381869, 0.8901581 ) * yiq; +} + + +void main() { + //Extremely fragile system to deteriminte if isolate parts of the blackhole + //Would break with any uv remaping or atlas stiching + bool isDisk = (abs(v_TexCoord.y-.5f)>.245); + bool isBack = (abs(v_TexCoord.x-.5f)>.245) && isDisk; + bool isTinyRing = (v_TexCoord.y > .66) && !isDisk; + + vec2 texCoord = v_TexCoord; + if (isDisk || isTinyRing){ + texCoord.x = mod(texCoord.x+u_Time/30,1); + } + + vec4 texture = texture2D(u_Texture, texCoord); + if (isDisk || isTinyRing){ + vec3 targetYIQ = toYIQ(STABLE_COLOR); + vec3 originalYIQ = toYIQ(texture.xyz); + vec3 yiqColor = vec3(originalYIQ.x,normalize(targetYIQ.yz)*length(originalYIQ.yz)); + vec3 finalrgb = toRGB(yiqColor); + texture = vec4(mix(UNSTABLE_COLOR,finalrgb,pow(u_Stability,.5)),1); + } + + gl_FragColor = texture; +} diff --git a/src/main/resources/assets/gregtech/shaders/blackhole.vert.glsl b/src/main/resources/assets/gregtech/shaders/blackhole.vert.glsl new file mode 100644 index 0000000000..57cea0b81c --- /dev/null +++ b/src/main/resources/assets/gregtech/shaders/blackhole.vert.glsl @@ -0,0 +1,81 @@ +#version 120 + +uniform float u_Time; +uniform float u_Stability; +uniform float u_Scale; +uniform vec3 u_CameraPosition; + +varying vec2 v_TexCoord; + +const float PI = 3.14159265358979323846; + +const float HORIZON_EDGE = 2.6; + +mat4 rotateMatrix(float angle, vec3 axis){ + float x = axis.x; + float y = axis.y; + float z = axis.z; + + float c = cos(angle); + float s = sin(angle); + float t = 1.0 - c; + + return mat4( + c+x*x*t, t*x*y - s*z, t*x*z + s*y, 0.0, + t*x*y + s*z, t*y*y + c, t*y*z - s*x, 0.0, + t*x*z - s*y, t*y*z + s*x, t*z*z + c, 0.0, + 0.0, 0.0, 0.0, 1.0 + ); +} + + + + + +void main() { + + v_TexCoord = gl_MultiTexCoord0.xy; + + //Extremely fragile system to deteriminte if isolate parts of the blackhole + //Would break with any uv remaping or atlas stiching + bool isDisk = (abs(v_TexCoord.y-.5f)>.245); + bool isBack = (abs(v_TexCoord.x-.5f)>.245) && isDisk; + bool isFront = (abs(v_TexCoord.x-.5f)<.255) && isDisk; + bool isBot = (v_TexCoord.y < .5) && isBack; + + float yAngle = atan(u_CameraPosition.z,u_CameraPosition.x) - PI/2; + float c = cos(yAngle); + float s = sin(yAngle); + mat4 yRotate = mat4( + vec4(c, 0.0, s, 0.0), // First column + vec4(0.0, 1.0, 0.0, 0.0), // Second column + vec4(-s, 0.0, c, 0.0), // Third column + vec4(0.0, 0.0, 0.0, 1.0) // Fourth column + ); + + + float base = length(gl_Vertex.xyz); + float stab = (base>HORIZON_EDGE)?u_Stability:1; + + float scale = ((base-HORIZON_EDGE)*stab+HORIZON_EDGE)/base; + scale = max(scale, .1); + scale*=u_Scale; + + + vec4 rotated = yRotate * vec4((gl_Vertex.xyz*scale),1); + + vec3 cameraDirection = normalize(u_CameraPosition); + cameraDirection = !isBot?cameraDirection:-cameraDirection; + vec3 rotateAxis = cross(cameraDirection,vec3(0,1,0)); + float angle = acos(dot(cameraDirection,vec3(0,1,0))); + if (isFront) angle = 0; + + float instabilityRotation =(u_Stability<=0)?u_Time/10:0; + + mat4 rotate = rotateMatrix(angle,normalize(rotateAxis)); + + + mat4 rotateB = rotateMatrix(instabilityRotation,normalize(u_CameraPosition)); + + gl_Position = gl_ModelViewProjectionMatrix * (rotateB* (rotate * (rotated))); +} diff --git a/src/main/resources/assets/gregtech/shaders/laser.frag.glsl b/src/main/resources/assets/gregtech/shaders/laser.frag.glsl new file mode 100644 index 0000000000..45656e8767 --- /dev/null +++ b/src/main/resources/assets/gregtech/shaders/laser.frag.glsl @@ -0,0 +1,25 @@ +#version 120 + +uniform sampler2D u_Texture; +uniform vec3 u_Color; + +varying vec2 v_TexCoord; + +vec3 toYIQ(vec3 rgb){ + return mat3( 0.299, 1.0, 0.40462981, 0.587, -0.46081557, -1.0, 0.114, -0.53918443, 0.59537019 ) * rgb; +} + +vec3 toRGB(vec3 yiq){ + return mat3( 1.0, 1.0, 1.0, 0.5696804, -0.1620848, -0.6590654, 0.3235513, -0.3381869, 0.8901581 ) * yiq; +} + +void main() { + vec4 texture = texture2D(u_Texture, v_TexCoord); + + vec3 targetYIQ = toYIQ(u_Color); + vec3 originalYIQ = toYIQ(texture.xyz); + vec3 yiqColor = vec3(originalYIQ.x,normalize(targetYIQ.yz)*length(originalYIQ.yz)); + vec3 finalrgb = toRGB(yiqColor); + + gl_FragColor = vec4(finalrgb,1); +} diff --git a/src/main/resources/assets/gregtech/shaders/laser.vert.glsl b/src/main/resources/assets/gregtech/shaders/laser.vert.glsl new file mode 100644 index 0000000000..9acecf5da9 --- /dev/null +++ b/src/main/resources/assets/gregtech/shaders/laser.vert.glsl @@ -0,0 +1,47 @@ +#version 120 + +uniform vec3 u_CameraPosition; +uniform mat4 u_ModelMatrix; + +varying vec2 v_TexCoord; + +const float PI = 3.14159265358979323846; + + + +mat4 rotateMatrix(float angle, vec3 axis){ + float x = axis.x; + float y = axis.y; + float z = axis.z; + + float c = cos(angle); + float s = sin(angle); + float t = 1.0 - c; + + return mat4( + c+x*x*t, t*x*y - s*z, t*x*z + s*y, 0.0, + t*x*y + s*z, t*y*y + c, t*y*z - s*x, 0.0, + t*x*z - s*y, t*y*z + s*x, t*z*z + c, 0.0, + 0.0, 0.0, 0.0, 1.0 + ); +} + + +void main() { + + v_TexCoord = gl_MultiTexCoord0.xy; + + float xAngle = atan(u_CameraPosition.y,u_CameraPosition.z) - PI/2; + float c = cos(xAngle); + float s = sin(xAngle); + mat4 xRotate = mat4( + 1.0, 0.0, 0.0, 0.0, + 0.0, c, -s, 0.0, + 0.0, s, c, 0.0, + 0.0, 0.0, 0.0, 1.0 + ); + + + gl_Position = gl_ModelViewProjectionMatrix * (u_ModelMatrix*(xRotate*gl_Vertex)); +} + |