mirror of
https://github.com/GTNewHorizons/Eternal-Singularity.git
synced 2026-11-22 12:59:52 +00:00
Merge remote-tracking branch 'origin/fix-universium' into dev
This commit is contained in:
12 files changed
+35
-794
No files matched your search
+4
-3
@@ -1,9 +1,10 @@
|
||||
// Add your dependencies here
|
||||
|
||||
dependencies {
|
||||
implementation("com.github.GTNewHorizons:NotEnoughItems:2.8.0-GTNH:dev")
|
||||
implementation("com.github.GTNewHorizons:Avaritia:1.75:dev")
|
||||
implementation("com.github.GTNewHorizons:Universal-Singularities:8.10.0:dev")
|
||||
api("com.github.GTNewHorizons:GTNHLib:0.8.34")
|
||||
implementation("com.github.GTNewHorizons:NotEnoughItems:2.8.44-GTNH:dev")
|
||||
implementation("com.github.GTNewHorizons:Avaritia:1.78:dev")
|
||||
implementation("com.github.GTNewHorizons:Universal-Singularities:8.12.0:dev")
|
||||
implementation("com.github.GTNewHorizons:WanionLib:1.10.0:dev")
|
||||
compileOnly("com.github.GTNewHorizons:CraftTweaker:3.4.2:dev") // optional
|
||||
}
|
||||
@@ -30,9 +30,6 @@ import singulariteam.eternalsingularity.proxy.CommonProxy;
|
||||
dependencies = "required-after:Avaritia;required-after:wanionlib@[1.7.10-1.3,);after:thermsingul;after:universalsingularities;after:aobdsingularities")
|
||||
public class EternalSingularityMod {
|
||||
|
||||
@Mod.Instance(MOD_ID)
|
||||
public static EternalSingularityMod instance;
|
||||
|
||||
public static Logger logger;
|
||||
|
||||
@SidedProxy(serverSide = COMMON_PROXY, clientSide = CLIENT_PROXY)
|
||||
|
||||
@@ -4,21 +4,14 @@ import net.minecraftforge.client.MinecraftForgeClient;
|
||||
|
||||
import singulariteam.eternalsingularity.item.EternalSingularityItem;
|
||||
import singulariteam.eternalsingularity.render.EternalItemRenderer;
|
||||
import singulariteam.eternalsingularity.render.ShaderHelper;
|
||||
|
||||
public final class ClientProxy extends CommonProxy {
|
||||
|
||||
EternalItemRenderer fancies = new EternalItemRenderer();
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
MinecraftForgeClient.registerItemRenderer(EternalSingularityItem.instance, fancies);
|
||||
ShaderHelper.initShaders();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postInit() {
|
||||
super.postInit();
|
||||
EternalItemRenderer fancies = new EternalItemRenderer();
|
||||
MinecraftForgeClient.registerItemRenderer(EternalSingularityItem.instance, fancies);
|
||||
if (compoundSingularityItem != null)
|
||||
MinecraftForgeClient.registerItemRenderer(compoundSingularityItem, fancies);
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ import singulariteam.eternalsingularity.item.EternalSingularityItem;
|
||||
public class CommonProxy {
|
||||
|
||||
private static ShapelessOreRecipe eternalSingularityRecipe = null;
|
||||
private static final Set<Class<?>> classSet = new HashSet<>();
|
||||
private static Set<Class<?>> classSet = new HashSet<>();
|
||||
protected CompoundSingularityItem compoundSingularityItem = null;
|
||||
private File configFile;
|
||||
|
||||
@@ -63,9 +63,11 @@ public class CommonProxy {
|
||||
return eternalSingularityRecipe;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void postInit() {
|
||||
if (classSet.isEmpty() || craftingOnly) return;
|
||||
if (classSet.isEmpty() || craftingOnly) {
|
||||
classSet = null; // Destroy reference
|
||||
return;
|
||||
}
|
||||
final List<ItemStack> singularities = new ArrayList<>();
|
||||
for (final Iterator<Object> catalystRecipeIterator = Grinder.catalyst.getInput()
|
||||
.iterator(); catalystRecipeIterator.hasNext();) {
|
||||
@@ -112,7 +114,7 @@ public class CommonProxy {
|
||||
if (!(input instanceof ItemStack)) continue;
|
||||
compoundRecipe.getInput().add(((ItemStack) input).copy());
|
||||
}
|
||||
if (compoundRecipe.getInput().size() > 0) GameRegistry.addRecipe(compoundRecipe);
|
||||
if (!compoundRecipe.getInput().isEmpty()) GameRegistry.addRecipe(compoundRecipe);
|
||||
}
|
||||
eternalSingularityRecipeInputs.clear();
|
||||
for (int i = 0; i < compoundMax; i++)
|
||||
@@ -120,5 +122,7 @@ public class CommonProxy {
|
||||
}
|
||||
ExtremeCraftingManager.getInstance().getRecipeList().add(eternalSingularityRecipe);
|
||||
Grinder.catalyst.getInput().add(new ItemStack(EternalSingularityItem.instance));
|
||||
|
||||
classSet = null; // Destroy reference
|
||||
}
|
||||
}
|
||||
@@ -1,112 +0,0 @@
|
||||
package singulariteam.eternalsingularity.render;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.EntityRenderer;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import org.lwjgl.opengl.ARBShaderObjects;
|
||||
|
||||
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||
import fox.spiteful.avaritia.render.LudicrousRenderEvents;
|
||||
|
||||
public class CosmicRenderStuffs {
|
||||
|
||||
public static final ShaderCallback shaderCallback;
|
||||
|
||||
public static float[] lightlevel = new float[3];
|
||||
|
||||
public static String[] lightmapobf = new String[] { "lightmapColors", "field_78504_Q", "U" };
|
||||
public static boolean inventoryRender = false;
|
||||
public static float cosmicOpacity = 1.0f;
|
||||
|
||||
static {
|
||||
shaderCallback = new ShaderCallback() {
|
||||
|
||||
@Override
|
||||
public void call(int shader) {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
float yaw = 0;
|
||||
float pitch = 0;
|
||||
float scale = 1.0f;
|
||||
|
||||
if (!inventoryRender) {
|
||||
yaw = (float) ((mc.thePlayer.rotationYaw * 2 * Math.PI) / 360.0);
|
||||
pitch = -(float) ((mc.thePlayer.rotationPitch * 2 * Math.PI) / 360.0);
|
||||
} else {
|
||||
scale = 25.0f;
|
||||
}
|
||||
|
||||
int time2 = ARBShaderObjects.glGetUniformLocationARB(shader, "time2");
|
||||
ARBShaderObjects.glUniform1fARB(time2, mc.thePlayer.ticksExisted);
|
||||
|
||||
int x = ARBShaderObjects.glGetUniformLocationARB(shader, "yaw");
|
||||
ARBShaderObjects.glUniform1fARB(x, yaw);
|
||||
|
||||
int z = ARBShaderObjects.glGetUniformLocationARB(shader, "pitch");
|
||||
ARBShaderObjects.glUniform1fARB(z, pitch);
|
||||
|
||||
int l = ARBShaderObjects.glGetUniformLocationARB(shader, "lightlevel");
|
||||
ARBShaderObjects.glUniform3fARB(l, lightlevel[0], lightlevel[1], lightlevel[2]);
|
||||
|
||||
int lightmix = ARBShaderObjects.glGetUniformLocationARB(shader, "lightmix");
|
||||
ARBShaderObjects.glUniform1fARB(lightmix, 0.2f);
|
||||
|
||||
int uvs = ARBShaderObjects.glGetUniformLocationARB(shader, "cosmicuvs");
|
||||
ARBShaderObjects.glUniformMatrix2ARB(uvs, false, LudicrousRenderEvents.cosmicUVs);
|
||||
|
||||
int s = ARBShaderObjects.glGetUniformLocationARB(shader, "externalScale");
|
||||
ARBShaderObjects.glUniform1fARB(s, scale);
|
||||
|
||||
int o = ARBShaderObjects.glGetUniformLocationARB(shader, "opacity");
|
||||
ARBShaderObjects.glUniform1fARB(o, cosmicOpacity);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static void useShader() {
|
||||
ShaderHelper.useShader(ShaderHelper.cosmicShader, shaderCallback);
|
||||
}
|
||||
|
||||
public static void releaseShader() {
|
||||
ShaderHelper.releaseShader();
|
||||
}
|
||||
|
||||
private static Field mapfield = ReflectionHelper.findField(EntityRenderer.class, lightmapobf);
|
||||
|
||||
public static void setLightFromLocation(World world, int x, int y, int z) {
|
||||
if (world == null) {
|
||||
setLightLevel(1.0f);
|
||||
return;
|
||||
}
|
||||
|
||||
int[] map = null;
|
||||
try {
|
||||
map = (int[]) mapfield.get(Minecraft.getMinecraft().entityRenderer);
|
||||
} catch (Exception e) {}
|
||||
if (map == null) {
|
||||
setLightLevel(1.0f);
|
||||
return;
|
||||
}
|
||||
|
||||
setLightLevel(1.0F, 1.0F, 1.0F);
|
||||
}
|
||||
|
||||
public static void setLightLevel(float level) {
|
||||
setLightLevel(level, level, level);
|
||||
}
|
||||
|
||||
public static void setLightLevel(float r, float g, float b) {
|
||||
lightlevel[0] = Math.max(0.0f, Math.min(1.0f, r));
|
||||
lightlevel[1] = Math.max(0.0f, Math.min(1.0f, g));
|
||||
lightlevel[2] = Math.max(0.0f, Math.min(1.0f, b));
|
||||
}
|
||||
|
||||
public static void bindItemTexture() {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
mc.renderEngine.bindTexture(TextureMap.locationItemsTexture);
|
||||
}
|
||||
}
|
||||
@@ -7,9 +7,9 @@ import net.minecraft.client.renderer.ItemRenderer;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.entity.RenderItem;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.MathHelper;
|
||||
@@ -18,16 +18,18 @@ import net.minecraftforge.client.IItemRenderer;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.postprocessing.shaders.UniversiumShader;
|
||||
import com.gtnewhorizon.gtnhlib.client.renderer.shader.ShaderProgram;
|
||||
|
||||
import fox.spiteful.avaritia.render.ICosmicRenderItem;
|
||||
import fox.spiteful.avaritia.render.IHaloRenderItem;
|
||||
|
||||
public class EternalItemRenderer implements IItemRenderer {
|
||||
|
||||
public Random rand = new Random();
|
||||
public final Random rand = new Random();
|
||||
|
||||
@Override
|
||||
public boolean handleRenderType(ItemStack item, ItemRenderType type) {
|
||||
// return type != ItemRenderType.INVENTORY;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -45,9 +47,8 @@ public class EternalItemRenderer implements IItemRenderer {
|
||||
IIcon halo = null;
|
||||
int haloColour = 0;
|
||||
|
||||
net.minecraft.item.Item itype = item.getItem();
|
||||
if (itype instanceof IHaloRenderItem) {
|
||||
IHaloRenderItem ihri = (IHaloRenderItem) itype;
|
||||
Item itype = item.getItem();
|
||||
if (itype instanceof IHaloRenderItem ihri) {
|
||||
|
||||
spread = ihri.getHaloSize(item);
|
||||
halo = ihri.getHaloTexture(item);
|
||||
@@ -61,7 +62,6 @@ public class EternalItemRenderer implements IItemRenderer {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
Tessellator t = Tessellator.instance;
|
||||
this.processLightLevel(type, item, data);
|
||||
// ShaderHelper.useShader(ShaderHelper.testShader, this.shaderCallback);
|
||||
switch (type) {
|
||||
case ENTITY: {
|
||||
GL11.glPushMatrix();
|
||||
@@ -69,19 +69,13 @@ public class EternalItemRenderer implements IItemRenderer {
|
||||
if (item.isOnItemFrame()) GL11.glTranslatef(0F, -0.3F, 0.01F);
|
||||
render(item, null);
|
||||
GL11.glPopMatrix();
|
||||
|
||||
break;
|
||||
}
|
||||
case EQUIPPED: {
|
||||
render(item, data[1] instanceof EntityPlayer ? (EntityPlayer) data[1] : null);
|
||||
break;
|
||||
}
|
||||
case EQUIPPED_FIRST_PERSON: {
|
||||
case EQUIPPED, EQUIPPED_FIRST_PERSON: {
|
||||
render(item, data[1] instanceof EntityPlayer ? (EntityPlayer) data[1] : null);
|
||||
break;
|
||||
}
|
||||
case INVENTORY: {
|
||||
GL11.glPushMatrix();
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
@@ -127,28 +121,7 @@ public class EternalItemRenderer implements IItemRenderer {
|
||||
|
||||
r.renderItemIntoGUI(mc.fontRenderer, mc.getTextureManager(), item, 0, 0, true);
|
||||
|
||||
GL11.glEnable(GL11.GL_ALPHA_TEST);
|
||||
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
|
||||
r.renderWithColor = true;
|
||||
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
GL11.glPopMatrix();
|
||||
|
||||
// middle?
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
|
||||
GL11.glDisable(GL11.GL_ALPHA_TEST);
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
|
||||
r.renderItemIntoGUI(mc.fontRenderer, mc.getTextureManager(), item, 0, 0, true);
|
||||
|
||||
if (item.getItem() instanceof ICosmicRenderItem) {
|
||||
if (item.getItem() instanceof ICosmicRenderItem icri) {
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
@@ -156,15 +129,12 @@ public class EternalItemRenderer implements IItemRenderer {
|
||||
GL11.glDisable(GL11.GL_ALPHA_TEST);
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
|
||||
ICosmicRenderItem icri = (ICosmicRenderItem) (item.getItem());
|
||||
|
||||
CosmicRenderStuffs.cosmicOpacity = icri.getMaskMultiplier(item, null);
|
||||
CosmicRenderStuffs.inventoryRender = true;
|
||||
CosmicRenderStuffs.useShader();
|
||||
final float opacity = icri.getMaskMultiplier(item, mc.thePlayer);
|
||||
UniversiumShader.getInstance().setCosmicOpacity(opacity).setRenderInInventory().use();
|
||||
|
||||
IIcon cosmicicon = icri.getMaskTexture(item, null);
|
||||
|
||||
GL11.glColor4d(1, 1, 1, 1);
|
||||
GL11.glColor4f(1, 1, 1, 1);
|
||||
|
||||
float minu = cosmicicon.getMinU();
|
||||
float maxu = cosmicicon.getMaxU();
|
||||
@@ -178,8 +148,7 @@ public class EternalItemRenderer implements IItemRenderer {
|
||||
t.addVertexWithUV(16, 0, 0, maxu, minv);
|
||||
t.draw();
|
||||
|
||||
CosmicRenderStuffs.releaseShader();
|
||||
CosmicRenderStuffs.inventoryRender = false;
|
||||
ShaderProgram.unbind();
|
||||
}
|
||||
|
||||
GL11.glEnable(GL11.GL_ALPHA_TEST);
|
||||
@@ -189,15 +158,11 @@ public class EternalItemRenderer implements IItemRenderer {
|
||||
r.renderWithColor = true;
|
||||
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
GL11.glPopMatrix();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// ShaderHelper.releaseShader();
|
||||
|
||||
// Lumberjack.log(Level.INFO, light+"");
|
||||
}
|
||||
|
||||
public void render(ItemStack item, EntityPlayer player) {
|
||||
@@ -206,24 +171,17 @@ public class EternalItemRenderer implements IItemRenderer {
|
||||
passes = item.getItem().getRenderPasses(item.getItemDamage());
|
||||
}
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
GL11.glColor4f(1F, 1F, 1F, 1F);
|
||||
// ItemRenderer.renderItemIn2D(Tessellator.instance, f1, f2, f, f3, icon.getIconWidth(), icon.getIconHeight(),
|
||||
// scale);
|
||||
|
||||
IIcon icon;
|
||||
float f, f1, f2, f3;
|
||||
float scale = 1F / 16F;
|
||||
|
||||
// Lumberjack.log(Level.INFO, "passes: "+passes);
|
||||
|
||||
for (int i = 0; i < passes; i++) {
|
||||
icon = this.getStackIcon(item, i, player);
|
||||
|
||||
// Lumberjack.log(Level.INFO, "icon "+i+": "+icon);
|
||||
|
||||
f = icon.getMinU();
|
||||
f1 = icon.getMaxU();
|
||||
f2 = icon.getMinV();
|
||||
@@ -245,8 +203,8 @@ public class EternalItemRenderer implements IItemRenderer {
|
||||
GL11.glDisable(GL11.GL_ALPHA_TEST);
|
||||
GL11.glDepthFunc(GL11.GL_EQUAL);
|
||||
ICosmicRenderItem icri = (ICosmicRenderItem) (item.getItem());
|
||||
CosmicRenderStuffs.cosmicOpacity = icri.getMaskMultiplier(item, player);
|
||||
CosmicRenderStuffs.useShader();
|
||||
final float opacity = icri.getMaskMultiplier(item, player);
|
||||
UniversiumShader.getInstance().setCosmicOpacity(opacity).use();
|
||||
|
||||
IIcon cosmicicon = icri.getMaskTexture(item, player);
|
||||
|
||||
@@ -263,23 +221,22 @@ public class EternalItemRenderer implements IItemRenderer {
|
||||
cosmicicon.getIconWidth(),
|
||||
cosmicicon.getIconHeight(),
|
||||
scale);
|
||||
CosmicRenderStuffs.releaseShader();
|
||||
ShaderProgram.unbind();
|
||||
GL11.glDepthFunc(GL11.GL_LEQUAL);
|
||||
GL11.glEnable(GL11.GL_ALPHA_TEST);
|
||||
}
|
||||
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
GL11.glPopMatrix();
|
||||
|
||||
GL11.glColor4f(1F, 1F, 1F, 1F);
|
||||
}
|
||||
|
||||
public void processLightLevel(ItemRenderType type, ItemStack item, Object... data) {
|
||||
switch (type) {
|
||||
case ENTITY: {
|
||||
EntityItem ent = (EntityItem) (data[1]);
|
||||
case ENTITY, EQUIPPED, EQUIPPED_FIRST_PERSON: {
|
||||
Entity ent = (Entity) (data[1]);
|
||||
if (ent != null) {
|
||||
CosmicRenderStuffs.setLightFromLocation(
|
||||
UniversiumShader.getInstance().setLightFromLocation(
|
||||
ent.worldObj,
|
||||
MathHelper.floor_double(ent.posX),
|
||||
MathHelper.floor_double(ent.posY),
|
||||
@@ -287,35 +244,8 @@ public class EternalItemRenderer implements IItemRenderer {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case EQUIPPED: {
|
||||
EntityLivingBase ent = (EntityLivingBase) (data[1]);
|
||||
if (ent != null) {
|
||||
CosmicRenderStuffs.setLightFromLocation(
|
||||
ent.worldObj,
|
||||
MathHelper.floor_double(ent.posX),
|
||||
MathHelper.floor_double(ent.posY),
|
||||
MathHelper.floor_double(ent.posZ));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case EQUIPPED_FIRST_PERSON: {
|
||||
EntityLivingBase ent = (EntityLivingBase) (data[1]);
|
||||
if (ent != null) {
|
||||
CosmicRenderStuffs.setLightFromLocation(
|
||||
ent.worldObj,
|
||||
MathHelper.floor_double(ent.posX),
|
||||
MathHelper.floor_double(ent.posY),
|
||||
MathHelper.floor_double(ent.posZ));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case INVENTORY: {
|
||||
CosmicRenderStuffs.setLightLevel(1.2f);
|
||||
return;
|
||||
}
|
||||
default: {
|
||||
CosmicRenderStuffs.setLightLevel(1.0f);
|
||||
return;
|
||||
UniversiumShader.getInstance().setLightLevel(1.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
package singulariteam.eternalsingularity.render;
|
||||
|
||||
public abstract class ShaderCallback {
|
||||
|
||||
public abstract void call(int paramInt);
|
||||
}
|
||||
@@ -1,160 +0,0 @@
|
||||
package singulariteam.eternalsingularity.render;
|
||||
|
||||
// import fox.spiteful.avaritia.Lumberjack;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
|
||||
import org.lwjgl.opengl.ARBFragmentShader;
|
||||
import org.lwjgl.opengl.ARBShaderObjects;
|
||||
import org.lwjgl.opengl.ARBVertexShader;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public final class ShaderHelper {
|
||||
|
||||
private static final int VERT = ARBVertexShader.GL_VERTEX_SHADER_ARB;
|
||||
private static final int FRAG = ARBFragmentShader.GL_FRAGMENT_SHADER_ARB;
|
||||
private static final String PREFIX = "/assets/eternalsingularity/shader/";
|
||||
|
||||
public static int cosmicShader = 0;
|
||||
|
||||
public static void initShaders() {
|
||||
if (!useShaders()) return;
|
||||
|
||||
cosmicShader = createProgram("cosmic.vert", "cosmic.frag");
|
||||
}
|
||||
|
||||
public static void useShader(int shader, ShaderCallback callback) {
|
||||
if (!useShaders()) return;
|
||||
|
||||
ARBShaderObjects.glUseProgramObjectARB(shader);
|
||||
|
||||
if (shader != 0) {
|
||||
int time = ARBShaderObjects.glGetUniformLocationARB(shader, "time");
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
if (mc.thePlayer != null && mc.thePlayer.worldObj != null) {
|
||||
ARBShaderObjects.glUniform1iARB(time, (int) (mc.thePlayer.worldObj.getWorldTime() % Integer.MAX_VALUE));
|
||||
}
|
||||
|
||||
if (callback != null) callback.call(shader);
|
||||
}
|
||||
}
|
||||
|
||||
public static void useShader(int shader) {
|
||||
useShader(shader, null);
|
||||
}
|
||||
|
||||
public static void releaseShader() {
|
||||
useShader(0);
|
||||
}
|
||||
|
||||
public static boolean useShaders() {
|
||||
return OpenGlHelper.shadersSupported;
|
||||
}
|
||||
|
||||
// Most of the code taken from the LWJGL wiki
|
||||
// http://lwjgl.org/wiki/index.php?title=GLSL_Shaders_with_LWJGL
|
||||
|
||||
private static int createProgram(String vert, String frag) {
|
||||
int vertId = 0, fragId = 0, program = 0;
|
||||
if (vert != null) vertId = createShader(PREFIX + vert, VERT);
|
||||
if (frag != null) fragId = createShader(PREFIX + frag, FRAG);
|
||||
|
||||
program = ARBShaderObjects.glCreateProgramObjectARB();
|
||||
if (program == 0) return 0;
|
||||
|
||||
if (vert != null) ARBShaderObjects.glAttachObjectARB(program, vertId);
|
||||
if (frag != null) ARBShaderObjects.glAttachObjectARB(program, fragId);
|
||||
|
||||
ARBShaderObjects.glLinkProgramARB(program);
|
||||
if (ARBShaderObjects.glGetObjectParameteriARB(program, ARBShaderObjects.GL_OBJECT_LINK_STATUS_ARB)
|
||||
== GL11.GL_FALSE) {
|
||||
// Lumberjack.log(Level.ERROR, getLogInfo(program));
|
||||
return 0;
|
||||
}
|
||||
|
||||
ARBShaderObjects.glValidateProgramARB(program);
|
||||
if (ARBShaderObjects.glGetObjectParameteriARB(program, ARBShaderObjects.GL_OBJECT_VALIDATE_STATUS_ARB)
|
||||
== GL11.GL_FALSE) {
|
||||
// Lumberjack.log(Level.ERROR, getLogInfo(program));
|
||||
return 0;
|
||||
}
|
||||
|
||||
return program;
|
||||
}
|
||||
|
||||
private static int createShader(String filename, int shaderType) {
|
||||
int shader = 0;
|
||||
try {
|
||||
shader = ARBShaderObjects.glCreateShaderObjectARB(shaderType);
|
||||
|
||||
if (shader == 0) return 0;
|
||||
|
||||
ARBShaderObjects.glShaderSourceARB(shader, readFileAsString(filename));
|
||||
ARBShaderObjects.glCompileShaderARB(shader);
|
||||
|
||||
if (ARBShaderObjects.glGetObjectParameteriARB(shader, ARBShaderObjects.GL_OBJECT_COMPILE_STATUS_ARB)
|
||||
== GL11.GL_FALSE)
|
||||
throw new RuntimeException("Error creating shader \"" + filename + "\": " + getLogInfo(shader));
|
||||
|
||||
return shader;
|
||||
} catch (Exception e) {
|
||||
ARBShaderObjects.glDeleteObjectARB(shader);
|
||||
e.printStackTrace();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
private static String getLogInfo(int obj) {
|
||||
return ARBShaderObjects.glGetInfoLogARB(
|
||||
obj,
|
||||
ARBShaderObjects.glGetObjectParameteriARB(obj, ARBShaderObjects.GL_OBJECT_INFO_LOG_LENGTH_ARB));
|
||||
}
|
||||
|
||||
private static String readFileAsString(String filename) throws Exception {
|
||||
StringBuilder source = new StringBuilder();
|
||||
InputStream in = ShaderHelper.class.getResourceAsStream(filename);
|
||||
Exception exception = null;
|
||||
BufferedReader reader;
|
||||
|
||||
if (in == null) return "";
|
||||
|
||||
try {
|
||||
reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
|
||||
|
||||
Exception innerExc = null;
|
||||
try {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) source.append(line).append('\n');
|
||||
} catch (Exception exc) {
|
||||
exception = exc;
|
||||
} finally {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (Exception exc) {
|
||||
if (innerExc == null) innerExc = exc;
|
||||
else exc.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (innerExc != null) throw innerExc;
|
||||
} catch (Exception exc) {
|
||||
exception = exc;
|
||||
} finally {
|
||||
try {
|
||||
in.close();
|
||||
} catch (Exception exc) {
|
||||
if (exception == null) exception = exc;
|
||||
else exc.printStackTrace();
|
||||
}
|
||||
|
||||
if (exception != null) throw exception;
|
||||
}
|
||||
|
||||
return source.toString();
|
||||
}
|
||||
}
|
||||
@@ -1,182 +0,0 @@
|
||||
#version 120
|
||||
|
||||
#define M_PI 3.1415926535897932384626433832795
|
||||
|
||||
const int cosmiccount = 10;
|
||||
const int cosmicoutof = 101;
|
||||
|
||||
uniform sampler2D texture0;
|
||||
uniform vec3 lightlevel;
|
||||
|
||||
uniform float time2;
|
||||
|
||||
uniform float yaw;
|
||||
uniform float pitch;
|
||||
uniform float externalScale;
|
||||
|
||||
uniform float lightmix;
|
||||
uniform float opacity;
|
||||
|
||||
uniform mat2 cosmicuvs[cosmiccount];
|
||||
|
||||
varying vec3 position;
|
||||
|
||||
float rand2d(vec2 x) {
|
||||
return fract(sin(mod(dot(x, vec2(12.9898, 78.233)), 3.14)) * 43758.5453);
|
||||
}
|
||||
|
||||
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 light = gl_Color;
|
||||
vec4 mask = texture2D(texture0, gl_TexCoord[0].xy);
|
||||
light.rgb *= lightlevel;
|
||||
float correctTime = mod(time2,12000);
|
||||
|
||||
float oneOverExternalScale = 1.0/externalScale;
|
||||
|
||||
int uvtiles = 16;
|
||||
|
||||
// background colour
|
||||
vec4 col = vec4(0.1,0.0,0.0,1.0);
|
||||
|
||||
float pulse = mod(correctTime,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));
|
||||
|
||||
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.0;
|
||||
int k = j + 1;
|
||||
float rand2 = (k * k * k * 239 + k * 37) * 3.6;
|
||||
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 * externalScale;
|
||||
//float v = (rawv + time * 0.00006) * scale * 0.6;
|
||||
float v = (rawv + correctTime * 0.0002 * oneOverExternalScale) * scale * 0.6 * externalScale;
|
||||
|
||||
vec2 tex = vec2( u, v );
|
||||
|
||||
// tile position of the current uv
|
||||
int tu = int(mod(floor(u*uvtiles),uvtiles));
|
||||
int tv = int(mod(floor(v*uvtiles),uvtiles));
|
||||
|
||||
// get pseudorandom variants
|
||||
int symbol = int(rand2d(vec2(tu, tv + i * 10.0)) * cosmicoutof);
|
||||
int rotation = int(mod(pow(tu,float(tv)) + tu + 3 + tv*i, 8));
|
||||
bool flip = false;
|
||||
if (rotation >= 4) {
|
||||
rotation -= 4;
|
||||
flip = true;
|
||||
}
|
||||
|
||||
// if it's an icon, then add the colour!
|
||||
if (symbol >= 0 && 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);
|
||||
|
||||
if (flip) {
|
||||
ru = 1.0 - ru;
|
||||
}
|
||||
|
||||
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 * opacity;
|
||||
|
||||
col = clamp(col,0.0,1.0);
|
||||
|
||||
gl_FragColor = col;
|
||||
}
|
||||
@@ -1,224 +0,0 @@
|
||||
#version 120
|
||||
|
||||
vec4 Ambient;
|
||||
vec4 Diffuse;
|
||||
vec4 Specular;
|
||||
|
||||
attribute float activelights;
|
||||
|
||||
varying vec3 position;
|
||||
|
||||
void pointLight(in int i, in vec3 normal, in vec3 eye, in vec3 ecPosition3)
|
||||
{
|
||||
float nDotVP; // normal . light direction
|
||||
float nDotHV; // normal . light half vector
|
||||
float pf; // power factor
|
||||
float attenuation; // computed attenuation factor
|
||||
float d; // distance from surface to light source
|
||||
vec3 VP; // direction from surface to light position
|
||||
vec3 halfVector; // direction of maximum highlights
|
||||
|
||||
// Compute vector from surface to light position
|
||||
VP = vec3 (gl_LightSource[i].position) - ecPosition3;
|
||||
|
||||
// Compute distance between surface and light position
|
||||
d = length(VP);
|
||||
|
||||
// Normalize the vector from surface to light position
|
||||
VP = normalize(VP);
|
||||
|
||||
// Compute attenuation
|
||||
attenuation = 1.0 / (gl_LightSource[i].constantAttenuation +
|
||||
gl_LightSource[i].linearAttenuation * d +
|
||||
gl_LightSource[i].quadraticAttenuation * d * d);
|
||||
|
||||
halfVector = normalize(VP + eye);
|
||||
|
||||
nDotVP = max(0.0, dot(normal, VP));
|
||||
//nDotHV = max(0.0, dot(normal, halfVector));
|
||||
|
||||
//if (nDotVP == 0.0)
|
||||
//{
|
||||
pf = 0.0;
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// pf = pow(nDotHV, gl_FrontMaterial.shininess);
|
||||
//}
|
||||
Ambient += gl_LightSource[i].ambient * attenuation;
|
||||
Diffuse += gl_LightSource[i].diffuse * nDotVP * attenuation;
|
||||
//Specular += gl_LightSource[i].specular * pf * attenuation;
|
||||
}
|
||||
|
||||
void spotLight(in int i, in vec3 normal, in vec3 eye, in vec3 ecPosition3)
|
||||
{
|
||||
float nDotVP; // normal . light direction
|
||||
float nDotHV; // normal . light half vector
|
||||
float pf; // power factor
|
||||
float spotDot; // cosine of angle between spotlight
|
||||
float spotAttenuation; // spotlight attenuation factor
|
||||
float attenuation; // computed attenuation factor
|
||||
float d; // distance from surface to light source
|
||||
vec3 VP; // direction from surface to light position
|
||||
vec3 halfVector; // direction of maximum highlights
|
||||
|
||||
// Compute vector from surface to light position
|
||||
VP = vec3 (gl_LightSource[i].position) - ecPosition3;
|
||||
|
||||
// Compute distance between surface and light position
|
||||
d = length(VP);
|
||||
|
||||
// Normalize the vector from surface to light position
|
||||
VP = normalize(VP);
|
||||
|
||||
// Compute attenuation
|
||||
attenuation = 1.0 / (gl_LightSource[i].constantAttenuation +
|
||||
gl_LightSource[i].linearAttenuation * d +
|
||||
gl_LightSource[i].quadraticAttenuation * d * d);
|
||||
|
||||
// See if point on surface is inside cone of illumination
|
||||
spotDot = dot(-VP, normalize(gl_LightSource[i].spotDirection));
|
||||
|
||||
if (spotDot < gl_LightSource[i].spotCosCutoff)
|
||||
{
|
||||
spotAttenuation = 0.0; // light adds no contribution
|
||||
}
|
||||
else
|
||||
{
|
||||
spotAttenuation = pow(spotDot, gl_LightSource[i].spotExponent);
|
||||
|
||||
}
|
||||
// Combine the spotlight and distance attenuation.
|
||||
attenuation *= spotAttenuation;
|
||||
|
||||
halfVector = normalize(VP + eye);
|
||||
|
||||
nDotVP = max(0.0, dot(normal, VP));
|
||||
//nDotHV = max(0.0, dot(normal, halfVector));
|
||||
|
||||
//if (nDotVP == 0.0)
|
||||
//{
|
||||
pf = 0.0;
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// pf = pow(nDotHV, gl_FrontMaterial.shininess);
|
||||
//
|
||||
// }
|
||||
Ambient += gl_LightSource[i].ambient * attenuation;
|
||||
Diffuse += gl_LightSource[i].diffuse * nDotVP * attenuation;
|
||||
//Specular += gl_LightSource[i].specular * pf * attenuation;
|
||||
|
||||
}
|
||||
|
||||
void directionalLight(in int i, in vec3 normal)
|
||||
{
|
||||
float nDotVP; // normal . light direction
|
||||
float nDotHV; // normal . light half vector
|
||||
float pf; // power factor
|
||||
|
||||
nDotVP = max(0.0, dot(normal, normalize(vec3 (gl_LightSource[i].position))));
|
||||
//nDotHV = max(0.0, dot(normal, vec3 (gl_LightSource[i].halfVector)));
|
||||
|
||||
//if (nDotVP == 0.0)
|
||||
//{
|
||||
pf = 0.0;
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// pf = pow(nDotHV, gl_FrontMaterial.shininess);
|
||||
//}
|
||||
Ambient += gl_LightSource[i].ambient;
|
||||
Diffuse += gl_LightSource[i].diffuse * nDotVP;
|
||||
//Specular += gl_LightSource[i].specular * pf;
|
||||
}
|
||||
|
||||
vec3 fnormal(void)
|
||||
{
|
||||
//Compute the normal
|
||||
vec3 normal = gl_NormalMatrix * gl_Normal;
|
||||
normal = normalize(normal);
|
||||
return normal;
|
||||
}
|
||||
|
||||
void ProcessLight(in int i, in vec3 normal, in vec3 eye, in vec3 ecPosition3)
|
||||
{
|
||||
if (gl_LightSource[i].spotCutoff==180.0)
|
||||
{
|
||||
if (gl_LightSource[i].position.w==0.0)
|
||||
{
|
||||
directionalLight(i, normal);
|
||||
}
|
||||
else
|
||||
{
|
||||
pointLight(i, normal, eye, ecPosition3);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
spotLight(i,normal,eye,ecPosition3);
|
||||
}
|
||||
}
|
||||
|
||||
void flight(in vec3 normal, in vec4 ecPosition, float alphaFade)
|
||||
{
|
||||
vec4 color;
|
||||
vec3 ecPosition3;
|
||||
vec3 eye;
|
||||
int i;
|
||||
|
||||
ecPosition3 = (vec3 (ecPosition)) / ecPosition.w;
|
||||
eye = vec3 (0.0, 0.0, 1.0);
|
||||
|
||||
// Clear the light intensity accumulators
|
||||
Ambient = vec4 (0.0);
|
||||
Diffuse = vec4 (0.0);
|
||||
Specular = vec4 (0.0);
|
||||
|
||||
if (activelights>0)
|
||||
{
|
||||
ProcessLight(0,normal,eye,ecPosition3);
|
||||
}
|
||||
if (activelights>1)
|
||||
{
|
||||
ProcessLight(1,normal,eye,ecPosition3);
|
||||
}
|
||||
//if (activelights>2)
|
||||
//{
|
||||
// ProcessLight(2,normal,eye,ecPosition3);
|
||||
//}
|
||||
//if (activelights>3)
|
||||
//{
|
||||
// ProcessLight(3,normal,eye,ecPosition3);
|
||||
//}
|
||||
|
||||
color = gl_FrontLightModelProduct.sceneColor +
|
||||
Ambient * gl_FrontMaterial.ambient +
|
||||
Diffuse * gl_FrontMaterial.diffuse;
|
||||
color += Specular * gl_FrontMaterial.specular;
|
||||
color = clamp( color, 0.0, 1.0 );
|
||||
gl_FrontColor = color;
|
||||
gl_FrontColor.a *= alphaFade;
|
||||
}
|
||||
|
||||
void main (void)
|
||||
{
|
||||
vec3 transformedNormal;
|
||||
float alphaFade = 1.0;
|
||||
|
||||
// Eye-coordinate position of vertex, needed in various calculations
|
||||
vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;
|
||||
|
||||
// Do fixed functionality vertex transform
|
||||
gl_Position = ftransform();
|
||||
transformedNormal = fnormal();
|
||||
flight(transformedNormal, ecPosition, alphaFade);
|
||||
|
||||
//Enable texture coordinates
|
||||
gl_TexCoord[0] = gl_MultiTexCoord0;
|
||||
//gl_TexCoord[1] = gl_MultiTexCoord1;
|
||||
//gl_TexCoord[2] = gl_MultiTexCoord2;
|
||||
//gl_TexCoord[3] = gl_MultiTexCoord3;
|
||||
|
||||
position = (gl_ModelViewMatrix * gl_Vertex).xyz;
|
||||
}
|
||||
BIN
Binary file not shown.
|
Before Width: | Height: | Size: 215 B After Width: | Height: | Size: 151 B |
BIN
Binary file not shown.
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.5 KiB |
Reference in new issue
Block a user