mirror of
https://github.com/GTNewHorizons/Avaritia.git
synced 2026-11-18 03:15:00 +00:00
Super secret rendering (but actually public)
This commit is contained in:
1 parent
4c4ae5f4e1
commit
db012a812e
9 files changed
+709
-3
No files matched your search
@@ -2,7 +2,9 @@ package fox.spiteful.avaritia;
|
||||
|
||||
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.ShaderHelper;
|
||||
import net.minecraftforge.client.MinecraftForgeClient;
|
||||
|
||||
public class ClientProxy extends CommonProxy {
|
||||
@@ -14,6 +16,12 @@ public class ClientProxy extends CommonProxy {
|
||||
MinecraftForgeClient.registerItemRenderer(LudicrousItems.resource, shiny);
|
||||
MinecraftForgeClient.registerItemRenderer(LudicrousItems.singularity, shiny);
|
||||
|
||||
CosmicItemRenderer sparkly = new CosmicItemRenderer();
|
||||
|
||||
MinecraftForgeClient.registerItemRenderer(LudicrousItems.infinity_sword, sparkly);
|
||||
|
||||
CompatClient.comprettify();
|
||||
|
||||
ShaderHelper.initShaders();
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,13 @@
|
||||
package fox.spiteful.avaritia.items.tools;
|
||||
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import fox.spiteful.avaritia.Avaritia;
|
||||
import fox.spiteful.avaritia.items.LudicrousItems;
|
||||
import fox.spiteful.avaritia.render.ICosmicRenderItem;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.SharedMonsterAttributes;
|
||||
import net.minecraft.entity.ai.attributes.AttributeModifier;
|
||||
@@ -12,16 +17,20 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemSword;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.util.EntityDamageSource;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.util.EnumHelper;
|
||||
|
||||
public class ItemSwordInfinity extends ItemSword {
|
||||
public class ItemSwordInfinity extends ItemSword implements ICosmicRenderItem {
|
||||
|
||||
private static final ToolMaterial opSword = EnumHelper.addToolMaterial("INFINITY_SWORD", 32, 9999, 9999F, -3.0F, 200);
|
||||
|
||||
private IIcon cosmicMask;
|
||||
|
||||
public ItemSwordInfinity(){
|
||||
super(opSword);
|
||||
setUnlocalizedName("infinity_sword");
|
||||
setTextureName("avaritia:infinity_sword");
|
||||
//setTextureName("avaritia:infinity_sword");
|
||||
setTextureName("minecraft:diamond_sword");
|
||||
setCreativeTab(Avaritia.tab);
|
||||
}
|
||||
|
||||
@@ -53,4 +62,17 @@ public class ItemSwordInfinity extends ItemSword {
|
||||
public void setDamage(ItemStack stack, int damage){
|
||||
super.setDamage(stack, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getMaskTexture(ItemStack stack) {
|
||||
return cosmicMask;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void registerIcons(IIconRegister ir) {
|
||||
super.registerIcons(ir);
|
||||
|
||||
this.cosmicMask = ir.registerIcon("avaritia:infinity_sword_mask");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,245 @@
|
||||
package fox.spiteful.avaritia.render;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.lwjgl.opengl.ARBShaderObjects;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
import org.lwjgl.opengl.GL13;
|
||||
|
||||
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||
|
||||
import fox.spiteful.avaritia.Lumberjack;
|
||||
import fox.spiteful.avaritia.items.LudicrousItems;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.EntityRenderer;
|
||||
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.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.IItemRenderer;
|
||||
|
||||
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"};
|
||||
|
||||
public CosmicItemRenderer() {
|
||||
shaderCallback = new ShaderCallback() {
|
||||
@Override
|
||||
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 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());
|
||||
}*/
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleRenderType(ItemStack item, ItemRenderType type) {
|
||||
//return type != ItemRenderType.INVENTORY;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) {
|
||||
return helper == ItemRendererHelper.ENTITY_ROTATION || helper == ItemRendererHelper.ENTITY_BOBBING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
this.processLightLevel(type, item, data);
|
||||
//ShaderHelper.useShader(ShaderHelper.testShader, this.shaderCallback);
|
||||
switch(type) {
|
||||
case ENTITY : {
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(-0.5F, 0F, 0F);
|
||||
if(item.isOnItemFrame())
|
||||
GL11.glTranslatef(0F, -0.3F, 0.01F);
|
||||
render(item);
|
||||
GL11.glPopMatrix();
|
||||
|
||||
break;
|
||||
}
|
||||
case EQUIPPED : {
|
||||
render(item);
|
||||
break;
|
||||
}
|
||||
case EQUIPPED_FIRST_PERSON : {
|
||||
render(item);
|
||||
break;
|
||||
}
|
||||
case INVENTORY: {
|
||||
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);
|
||||
|
||||
RenderItem r = RenderItem.getInstance();
|
||||
r.renderItemIntoGUI(mc.fontRenderer, mc.getTextureManager(), item, 0, 0, true);
|
||||
|
||||
if (item.getItem() instanceof ICosmicRenderItem) {
|
||||
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);
|
||||
|
||||
ShaderHelper.useShader(ShaderHelper.testShader, this.shaderCallback);
|
||||
ICosmicRenderItem icri = (ICosmicRenderItem)(item.getItem());
|
||||
IIcon cosmicicon = icri.getMaskTexture(item);
|
||||
|
||||
GL11.glColor4d(1, 1, 1, 1);
|
||||
|
||||
float minu = cosmicicon.getMinU();
|
||||
float maxu = cosmicicon.getMaxU();
|
||||
float minv = cosmicicon.getMinV();
|
||||
float maxv = cosmicicon.getMaxV();
|
||||
|
||||
Tessellator t = Tessellator.instance;
|
||||
|
||||
t.startDrawingQuads();
|
||||
t.addVertexWithUV(0, 0, 0, minu, minv);
|
||||
t.addVertexWithUV(0, 16, 0, minu, maxv);
|
||||
t.addVertexWithUV(16, 16, 0, maxu, maxv);
|
||||
t.addVertexWithUV(16, 0, 0, maxu, minv);
|
||||
t.draw();
|
||||
|
||||
ShaderHelper.releaseShader();
|
||||
}
|
||||
|
||||
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();
|
||||
break;
|
||||
}
|
||||
default : break;
|
||||
}
|
||||
//ShaderHelper.releaseShader();
|
||||
|
||||
//Lumberjack.log(Level.INFO, light+"");
|
||||
}
|
||||
|
||||
public void render(ItemStack item) {
|
||||
int dmg = item.getItemDamage();
|
||||
IIcon icon = item.getItem().getIconFromDamageForRenderPass(dmg, 0);
|
||||
|
||||
float f = icon.getMinU();
|
||||
float f1 = icon.getMaxU();
|
||||
float f2 = icon.getMinV();
|
||||
float f3 = icon.getMaxV();
|
||||
float scale = 1F / 16F;
|
||||
|
||||
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);
|
||||
|
||||
if (item.getItem() instanceof ICosmicRenderItem) {
|
||||
ShaderHelper.useShader(ShaderHelper.testShader, this.shaderCallback);
|
||||
ICosmicRenderItem icri = (ICosmicRenderItem)(item.getItem());
|
||||
IIcon cosmicicon = icri.getMaskTexture(item);
|
||||
|
||||
float minu = cosmicicon.getMinU();
|
||||
float maxu = cosmicicon.getMaxU();
|
||||
float minv = cosmicicon.getMinV();
|
||||
float maxv = cosmicicon.getMaxV();
|
||||
ItemRenderer.renderItemIn2D(Tessellator.instance, maxu, minv, minu, maxv, cosmicicon.getIconWidth(), cosmicicon.getIconHeight(), scale);
|
||||
ShaderHelper.releaseShader();
|
||||
}
|
||||
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
GL11.glPopMatrix();
|
||||
|
||||
GL11.glColor4f(1F, 1F, 1F, 1F);
|
||||
}
|
||||
|
||||
public void processLightLevel(ItemRenderType type, ItemStack item, Object... data) {
|
||||
int lightcoord = 0;
|
||||
|
||||
switch(type) {
|
||||
case ENTITY : {
|
||||
EntityItem ent = (EntityItem)(data[1]);
|
||||
if (ent != null) {
|
||||
lightcoord = ent.worldObj.getLightBrightnessForSkyBlocks(MathHelper.floor_double(ent.posX), MathHelper.floor_double(ent.posY), MathHelper.floor_double(ent.posZ), 0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case EQUIPPED : {
|
||||
EntityLivingBase ent = (EntityLivingBase)(data[1]);
|
||||
if (ent != null) {
|
||||
lightcoord = ent.worldObj.getLightBrightnessForSkyBlocks(MathHelper.floor_double(ent.posX), MathHelper.floor_double(ent.posY), MathHelper.floor_double(ent.posZ), 0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case EQUIPPED_FIRST_PERSON : {
|
||||
EntityLivingBase ent = (EntityLivingBase)(data[1]);
|
||||
if (ent != null) {
|
||||
lightcoord = ent.worldObj.getLightBrightnessForSkyBlocks(MathHelper.floor_double(ent.posX), MathHelper.floor_double(ent.posY), MathHelper.floor_double(ent.posZ), 0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case INVENTORY: {
|
||||
lightcoord = 0;
|
||||
this.lightlevel[0] = 1.2f;
|
||||
this.lightlevel[1] = 1.2f;
|
||||
this.lightlevel[2] = 1.2f;
|
||||
return;
|
||||
}
|
||||
default : {
|
||||
lightcoord = 0;
|
||||
this.lightlevel[0] = 1.0f;
|
||||
this.lightlevel[1] = 1.0f;
|
||||
this.lightlevel[2] = 1.0f;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int x = (lightcoord % 65536) / 16;
|
||||
int y = (lightcoord / 65536) / 16;
|
||||
|
||||
int[] lightmap = ReflectionHelper.getPrivateValue(EntityRenderer.class, Minecraft.getMinecraft().entityRenderer, this.lightmapobf);
|
||||
|
||||
int lightcolour = lightmap[y*16+x];
|
||||
|
||||
this.lightlevel[0] = ((lightcolour >> 16) & 0xFF) / 256.0f;
|
||||
this.lightlevel[1] = ((lightcolour >> 8) & 0xFF) / 256.0f;
|
||||
this.lightlevel[2] = ((lightcolour) & 0xFF) / 256.0f;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package fox.spiteful.avaritia.render;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
|
||||
public interface ICosmicRenderItem {
|
||||
|
||||
public IIcon getMaskTexture(ItemStack stack);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package fox.spiteful.avaritia.render;
|
||||
|
||||
public abstract class ShaderCallback {
|
||||
|
||||
public abstract void call(int shader);
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
/**
|
||||
* Original class written by Vazkii for Botania.
|
||||
*/
|
||||
|
||||
// TEMA: this is the main shader stuff, where the programs are loaded and compiled for the card.
|
||||
// other relevant files are the shader in /assets/physis/shader/, and the tesr in /client/render/tile/
|
||||
// they have other comments like this in.
|
||||
|
||||
package fox.spiteful.avaritia.render;
|
||||
|
||||
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.apache.logging.log4j.Level;
|
||||
import org.lwjgl.opengl.ARBFragmentShader;
|
||||
import org.lwjgl.opengl.ARBShaderObjects;
|
||||
import org.lwjgl.opengl.ARBVertexShader;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import fox.spiteful.avaritia.Lumberjack;
|
||||
|
||||
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/avaritia/shader/";
|
||||
|
||||
public static int testShader = 0;
|
||||
|
||||
public static void initShaders() {
|
||||
if(!useShaders())
|
||||
return;
|
||||
|
||||
testShader = 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: " + 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
uniform sampler2D texture0;
|
||||
uniform vec3 lightlevel;
|
||||
|
||||
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);
|
||||
|
||||
gl_FragColor = color;
|
||||
}
|
||||
@@ -0,0 +1,218 @@
|
||||
vec4 Ambient;
|
||||
vec4 Diffuse;
|
||||
vec4 Specular;
|
||||
|
||||
attribute short activelights;
|
||||
|
||||
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;
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.9 KiB |
Reference in new issue
Block a user