The *FANCIEST* thing.

This commit is contained in:
Alex Spinks committed 2015-07-16 04:57:02 +01:00
1 parent db012a812e
commit d5f1d896ea
25 files changed
+406 -20

No files matched your search

@@ -4,8 +4,10 @@ import fox.spiteful.avaritia.compat.CompatClient;
import fox.spiteful.avaritia.items.LudicrousItems;
import fox.spiteful.avaritia.render.CosmicItemRenderer;
import fox.spiteful.avaritia.render.FancyHaloRenderer;
import fox.spiteful.avaritia.render.LudicrousRenderEvents;
import fox.spiteful.avaritia.render.ShaderHelper;
import net.minecraftforge.client.MinecraftForgeClient;
import net.minecraftforge.common.MinecraftForge;
public class ClientProxy extends CommonProxy {
@@ -22,6 +24,8 @@ public class ClientProxy extends CommonProxy {
CompatClient.comprettify();
MinecraftForge.EVENT_BUS.register(new LudicrousRenderEvents());
ShaderHelper.initShaders();
}
}
@@ -1,11 +1,16 @@
package fox.spiteful.avaritia.render;
import java.nio.FloatBuffer;
import org.apache.logging.log4j.Level;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.ARBShaderObjects;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import org.lwjgl.opengl.GL13;
import scala.actors.threadpool.Arrays;
import cpw.mods.fml.relauncher.ReflectionHelper;
import fox.spiteful.avaritia.Lumberjack;
@@ -29,7 +34,6 @@ public class CosmicItemRenderer implements IItemRenderer {
private final ShaderCallback shaderCallback;
private float[] lightlevel = new float[3];
private ItemStack renderStack;
private String[] lightmapobf = new String[] {"lightmapColors", "field_78504_Q", "U"};
@@ -39,22 +43,33 @@ public class CosmicItemRenderer implements IItemRenderer {
public void call(int shader) {
Minecraft mc = Minecraft.getMinecraft();
//int x = ARBShaderObjects.glGetUniformLocationARB(shader, "yaw");
//ARBShaderObjects.glUniform1fARB(x, (float)((mc.thePlayer.rotationYaw * 2 * Math.PI) / 360.0));
int x = ARBShaderObjects.glGetUniformLocationARB(shader, "yaw");
ARBShaderObjects.glUniform1fARB(x, (float)((mc.thePlayer.rotationYaw * 2 * Math.PI) / 360.0));
//int z = ARBShaderObjects.glGetUniformLocationARB(shader, "pitch");
//ARBShaderObjects.glUniform1fARB(z, - (float)((mc.thePlayer.rotationPitch * 2 * Math.PI) / 360.0));
int z = ARBShaderObjects.glGetUniformLocationARB(shader, "pitch");
ARBShaderObjects.glUniform1fARB(z, - (float)((mc.thePlayer.rotationPitch * 2 * Math.PI) / 360.0));
int l = ARBShaderObjects.glGetUniformLocationARB(shader, "lightlevel");
ARBShaderObjects.glUniform3fARB(l, lightlevel[0], lightlevel[1], lightlevel[2]);
/*if (renderStack != null && renderStack.getItem() != null && renderStack.getItem() instanceof ICosmicRenderItem) {
ICosmicRenderItem item = (ICosmicRenderItem)(renderStack.getItem());
IIcon maskicon = item.getMaskTexture(renderStack);
int m = ARBShaderObjects.glGetUniformLocationARB(shader, "maskUV");
ARBShaderObjects.glUniform4fARB(m, maskicon.getMinU(), maskicon.getMinV(), maskicon.getMaxU(), maskicon.getMaxV());
}*/
int lightmix = ARBShaderObjects.glGetUniformLocationARB(shader, "lightmix");
ARBShaderObjects.glUniform1fARB(lightmix, 0.2f);
IIcon[] icons = LudicrousRenderEvents.cosmicIcons;
FloatBuffer cosmicUVs = BufferUtils.createFloatBuffer(4 * icons.length);
IIcon icon;
for (int i=0; i<icons.length; i++) {
icon = icons[i];
cosmicUVs.put(icon.getMinU());
cosmicUVs.put(icon.getMinV());
cosmicUVs.put(icon.getMaxU());
cosmicUVs.put(icon.getMaxV());
}
cosmicUVs.flip();
int uvs = ARBShaderObjects.glGetUniformLocationARB(shader, "cosmicuvs");
ARBShaderObjects.glUniformMatrix2ARB(uvs, false, cosmicUVs);
}
};
}
@@ -0,0 +1,40 @@
package fox.spiteful.avaritia.render;
import java.nio.FloatBuffer;
import org.apache.logging.log4j.Level;
import org.lwjgl.BufferUtils;
import scala.actors.threadpool.Arrays;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import fox.spiteful.avaritia.Lumberjack;
import net.minecraft.util.IIcon;
import net.minecraftforge.client.event.TextureStitchEvent;
public class LudicrousRenderEvents {
private static final int cosmicCount = 10;
public static String[] cosmicTextures = new String[cosmicCount];
static {
for (int i=0; i<cosmicCount; i++) {
cosmicTextures[i] = "avaritia:cosmic"+i;
}
}
public static FloatBuffer cosmicUVs = null;
public static IIcon[] cosmicIcons = new IIcon[cosmicTextures.length];
@SubscribeEvent
public void letsMakeAQuilt(TextureStitchEvent.Pre event) {
if (event.map.getTextureType() == 0) { return; }
for (int i=0; i<cosmicTextures.length; i++) {
IIcon icon = event.map.registerIcon(cosmicTextures[i]);
cosmicIcons[i] = icon;
}
//Lumberjack.log(Level.INFO, "COSMIC QUILTING: "+Arrays.toString(cosmicIcons));
}
}
@@ -1,19 +1,163 @@
#define M_PI 3.1415926535897932384626433832795
const int cosmiccount = 10;
const int cosmicoutof = 101;
uniform sampler2D texture0;
uniform vec3 lightlevel;
uniform int time;
uniform float yaw;
uniform float pitch;
uniform float lightmix;
uniform mat2 cosmicuvs[cosmiccount];
varying vec3 position;
mat4 rotationMatrix(vec3 axis, float angle)
{
axis = normalize(axis);
float s = sin(angle);
float c = cos(angle);
float oc = 1.0 - c;
return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0.0,
oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0.0,
oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0.0,
0.0, 0.0, 0.0, 1.0);
}
void main (void)
{
vec4 color;
vec4 light = gl_Color;
vec4 mask = texture2D(texture0, gl_TexCoord[0].xy);
light.rgb *= lightlevel;
color = vec4(1.0,0.0,0.0,1.0);
color.a *= mask.r;
vec3 shade = light.rgb * 0.1 + vec3(0.9,0.9,0.9);
color.rgb *= shade;
color = clamp(color,0.0,1.0);
int uvtiles = 16;
// background colour
vec4 col = vec4(0.1,0.0,0.0,1.0);
float pulse = mod(time,400)/400.0;
col.g = sin(pulse*M_PI*2) * 0.075 + 0.225;
col.b = cos(pulse*M_PI*2) * 0.05 + 0.3;
// get ray from camera to fragment
vec4 dir = normalize(vec4( -position, 0));
// rotate the ray to show the right bit of the sphere for the angle
float sb = sin(pitch);
float cb = cos(pitch);
dir = normalize(vec4(dir.x, dir.y * cb - dir.z * sb, dir.y * sb + dir.z * cb, 0));
gl_FragColor = color;
float sa = sin(-yaw);
float ca = cos(-yaw);
dir = normalize(vec4(dir.z * sa + dir.x * ca, dir.y, dir.z * ca - dir.x * sa, 0));
vec4 ray;
// draw the layers
for (int i=0; i<16; i++) {
int mult = 16-i;
// get semi-random stuff
int j = i + 7;
float rand1 = (j * j * 4321 + j * 8) * 2.0F;
int k = j + 1;
float rand2 = (k * k * k * 239 + k * 37) * 3.6F;
float rand3 = rand1 * 347.4 + rand2 * 63.4;
// random rotation matrix by random rotation around random axis
vec3 axis = normalize(vec3(sin(rand1), sin(rand2) , cos(rand3)));
// apply
ray = dir * rotationMatrix(axis, mod(rand3, 2*M_PI));
// calcuate the UVs from the final ray
float rawu = 0.5 + (atan(ray.z,ray.x)/(2*M_PI));
float rawv = 0.5 + (asin(ray.y)/M_PI);
// get UV scaled for layers and offset by time;
float scale = mult*0.5 + 2.75;
float u = rawu * scale;
//float v = (rawv + time * 0.00006) * scale * 0.6;
float v = (rawv + time * 0.0002) * scale * 0.6;
vec2 tex = vec2( u, v );
// tile position of the current uv
int tu = mod(floor(u*uvtiles),uvtiles);
int tv = mod(floor(v*uvtiles),uvtiles);
// get pseudorandom variants
int position = ((1777541 * tu) + (7649689 * tv) + (3612703 * (i+31)) + 1723609 ) ^ 50943779;
int symbol = mod(position, cosmicoutof);
int rotation = mod (pow(tu,tv) + tu + 3 + tv*i, 4);
// if it's an icon, then add the colour!
if (symbol < cosmiccount) {
vec2 cosmictex = vec2(1.0,1.0);
vec4 tcol = vec4(1.0,0.0,0.0,1.0);
// get uv within the tile
float ru = clamp(mod(u,1.0)*uvtiles - tu, 0.0, 1.0);
float rv = clamp(mod(v,1.0)*uvtiles - tv, 0.0, 1.0);
float oru = ru;
float orv = rv;
// rotate uvs if necessary
if (rotation == 1) {
oru = 1.0-rv;
orv = ru;
} else if (rotation == 2) {
oru = 1.0-ru;
orv = 1.0-rv;
} else if (rotation == 3) {
oru = rv;
orv = 1.0-ru;
}
// get the iicon uvs for the tile
float umin = cosmicuvs[symbol][0][0];
float umax = cosmicuvs[symbol][1][0];
float vmin = cosmicuvs[symbol][0][1];
float vmax = cosmicuvs[symbol][1][1];
// interpolate based on tile uvs
cosmictex.x = umin * (1.0-oru) + umax * oru;
cosmictex.y = vmin * (1.0-orv) + vmax * orv;
tcol = texture2D(texture0, cosmictex);
// set the alpha, blending out at the bunched ends
float a = tcol.r * (0.5 + (1.0/mult) * 1.0) * (1.0-smoothstep(0.15, 0.48, abs(rawv-0.5)));
// get fancy colours
float r = (mod(rand1, 29.0)/29.0) * 0.3 + 0.4;
float g = (mod(rand2, 35.0)/35.0) * 0.4 + 0.6;
float b = (mod(rand1, 17.0)/17.0) * 0.3 + 0.7;
// mix the colours
//col = col*(1-a) + vec4(r,g,b,1)*a;
col = col + vec4(r,g,b,1)*a;
}
}
// apply lighting
vec3 shade = light.rgb * (lightmix) + vec3(1.0-lightmix,1.0-lightmix,1.0-lightmix);
col.rgb *= shade;
// apply mask
col.a *= mask.r;
col = clamp(col,0.0,1.0);
gl_FragColor = col;
}
@@ -3,6 +3,8 @@ vec4 Diffuse;
vec4 Specular;
attribute short activelights;
varying vec3 position;
void pointLight(in int i, in vec3 normal, in vec3 eye, in vec3 ecPosition3)
{
@@ -215,4 +217,6 @@ void main (void)
//gl_TexCoord[1] = gl_MultiTexCoord1;
//gl_TexCoord[2] = gl_MultiTexCoord2;
//gl_TexCoord[3] = gl_MultiTexCoord3;
position = (gl_ModelViewMatrix * gl_Vertex).xyz;
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

@@ -0,0 +1,14 @@
{
"animation": {
"frametime": 1,
"frames": [
{
"index": 0,
"time": 7
},
1,
2,
3
]
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

@@ -0,0 +1,22 @@
{
"animation": {
"frametime": 1,
"frames": [
{
"index": 0,
"time": 4
},
1,
{
"index": 0,
"time": 9
},
2,
{
"index": 0,
"time": 7
},
3
]
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

@@ -0,0 +1,26 @@
{
"animation": {
"frametime": 1,
"frames": [
{
"index": 0,
"time": 16
},
1,
1,
1,
2,
2,
3,
4,
3,
4,
3,
2,
2,
1,
1,
1
]
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

@@ -0,0 +1,27 @@
{
"animation": {
"frametime": 1,
"frames": [
{
"index": 0,
"time": 13
},
1,
{
"index": 0,
"time": 10
},
3,
{
"index": 0,
"time": 5
},
2,
{
"index": 0,
"time": 15
},
4
]
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

@@ -0,0 +1,14 @@
{
"animation": {
"frametime": 1,
"frames": [
{
"index": 0,
"time": 34
},
1,
2,
3
]
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

@@ -0,0 +1,23 @@
{
"animation": {
"frametime": 1,
"frames": [
{
"index": 0,
"time": 18
},
1,
{
"index": 0,
"time": 4
},
3,
{
"index": 0,
"time": 14
},
2
]
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

@@ -0,0 +1,5 @@
{
"animation": {
"frametime": 1
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

@@ -0,0 +1,5 @@
{
"animation": {
"frametime": 2
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

@@ -0,0 +1,38 @@
{
"animation": {
"frametime": 1,
"frames": [
1,
2,
3,
2,
3,
2,
1,
{
"index": 0,
"time": 22
},
4,
5,
6,
5,
6,
5,
4,
{
"index": 0,
"time": 31
},
1,
2,
3,
2,
1,
{
"index": 0,
"time": 12
}
]
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

@@ -0,0 +1,5 @@
{
"animation": {
"frametime": 2
}
}