Search in sources :

Example 1 with ShaderCase

use of blusunrize.immersiveengineering.api.shader.ShaderCase in project ImmersiveEngineering by BluSunrize.

the class IESmartObjModel method buildQuads.

private ImmutableList<BakedQuad> buildQuads() {
    List<BakedQuad> quads = Lists.newArrayList();
    ItemStack shader = null;
    ShaderCase sCase = null;
    IOBJModelCallback callback = null;
    Object callbackObject = null;
    if (this.tempStack != null && tempStack.hasCapability(CapabilityShader.SHADER_CAPABILITY, null)) {
        ShaderWrapper wrapper = tempStack.getCapability(CapabilityShader.SHADER_CAPABILITY, null);
        shader = wrapper.getShaderItem();
        if (shader != null && shader.getItem() instanceof IShaderItem)
            sCase = ((IShaderItem) shader.getItem()).getShaderCase(shader, tempStack, wrapper.getShaderType());
    } else if (this.tempState != null && this.tempState instanceof IExtendedBlockState && ((IExtendedBlockState) this.tempState).getUnlistedNames().contains(CapabilityShader.BLOCKSTATE_PROPERTY)) {
        ShaderWrapper wrapper = ((IExtendedBlockState) this.tempState).getValue(CapabilityShader.BLOCKSTATE_PROPERTY);
        shader = wrapper.getShaderItem();
        if (shader != null && shader.getItem() instanceof IShaderItem)
            sCase = ((IShaderItem) shader.getItem()).getShaderCase(shader, null, wrapper.getShaderType());
    }
    if (this.tempStack != null && tempStack.getItem() instanceof IOBJModelCallback) {
        callback = (IOBJModelCallback) tempStack.getItem();
        callbackObject = this.tempStack;
    } else if (this.tempState != null && this.tempState instanceof IExtendedBlockState && ((IExtendedBlockState) this.tempState).getUnlistedNames().contains(IOBJModelCallback.PROPERTY)) {
        callback = ((IExtendedBlockState) this.tempState).getValue(IOBJModelCallback.PROPERTY);
        callbackObject = this.tempState;
    }
    int maxPasses = 1;
    if (sCase != null)
        maxPasses = sCase.getLayers().length;
    for (int pass = 0; pass < maxPasses; pass++) {
        ShaderLayer shaderLayer = sCase != null ? sCase.getLayers()[pass] : null;
        for (Group g : getModel().getMatLib().getGroups().values()) {
            if (callback != null)
                if (!callback.shouldRenderGroup(callbackObject, g.getName()))
                    continue;
            if (sCase != null)
                if (!sCase.renderModelPartForPass(shader, tempStack, g.getName(), pass))
                    continue;
            Set<Face> faces = Collections.synchronizedSet(new LinkedHashSet<Face>());
            Optional<TRSRTransformation> transform = Optional.absent();
            if (this.getState() instanceof OBJState) {
                OBJState state = (OBJState) this.getState();
                if (state.parent != null)
                    transform = state.parent.apply(Optional.absent());
                if (callback != null)
                    transform = callback.applyTransformations(callbackObject, g.getName(), transform);
                if (state.getGroupsWithVisibility(true).contains(g.getName()))
                    faces.addAll(g.applyTransform(transform));
            } else {
                transform = getState().apply(Optional.absent());
                if (callback != null)
                    transform = callback.applyTransformations(callbackObject, g.getName(), transform);
                faces.addAll(g.applyTransform(transform));
            }
            int argb = 0xffffffff;
            if (sCase != null)
                argb = sCase.getARGBColourModifier(shader, tempStack, g.getName(), pass);
            else if (callback != null)
                argb = callback.getRenderColour(callbackObject, g.getName());
            float[] colour = { (argb >> 16 & 255) / 255f, (argb >> 8 & 255) / 255f, (argb & 255) / 255f, (argb >> 24 & 255) / 255f };
            for (Face f : faces) {
                tempSprite = null;
                if (this.getModel().getMatLib().getMaterial(f.getMaterialName()).isWhite() && !"null".equals(f.getMaterialName())) {
                    for (Vertex v : f.getVertices()) if (!v.getMaterial().equals(this.getModel().getMatLib().getMaterial(v.getMaterial().getName())))
                        v.setMaterial(this.getModel().getMatLib().getMaterial(v.getMaterial().getName()));
                    tempSprite = ModelLoader.White.INSTANCE;
                } else {
                    if (sCase != null) {
                        ResourceLocation rl = sCase.getReplacementSprite(shader, tempStack, g.getName(), pass);
                        if (rl != null)
                            tempSprite = ClientUtils.getSprite(rl);
                    }
                    if (tempSprite == null && callback != null)
                        tempSprite = callback.getTextureReplacement(callbackObject, f.getMaterialName());
                    if (tempSprite == null && tempState != null && texReplace != null) {
                        String s = texReplace.get(g.getName());
                        if (s != null)
                            tempSprite = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(s);
                    }
                    if (tempSprite == null && !"null".equals(f.getMaterialName()))
                        tempSprite = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(this.getModel().getMatLib().getMaterial(f.getMaterialName()).getTexture().getTextureLocation().toString());
                }
                if (tempSprite != null) {
                    UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder(getFormat());
                    builder.setQuadOrientation(EnumFacing.getFacingFromVector(f.getNormal().x, f.getNormal().y, f.getNormal().z));
                    builder.setTexture(tempSprite);
                    builder.setQuadTint(pass);
                    Normal faceNormal = f.getNormal();
                    TextureCoordinate[] uvs = new TextureCoordinate[4];
                    boolean renderFace = true;
                    for (int i = 0; i < 4; i++) {
                        Vertex vertex = f.getVertices()[i];
                        //V-Flip is processed here already, rather than in the later method, since it's needed for easy UV comparissons on the Shader Layers
                        uvs[i] = vertex.hasTextureCoordinate() ? new TextureCoordinate(vertex.getTextureCoordinate().u, 1 - vertex.getTextureCoordinate().v, vertex.getTextureCoordinate().w) : TextureCoordinate.getDefaultUVs()[i];
                        if (shaderLayer != null) {
                            double[] texBounds = shaderLayer.getTextureBounds();
                            if (texBounds != null) {
                                if (//if any uvs are outside the layers bounds
                                texBounds[0] > uvs[i].u || uvs[i].u > texBounds[2] || texBounds[1] > uvs[i].v || uvs[i].v > texBounds[3]) {
                                    renderFace = false;
                                    break;
                                }
                                double dU = texBounds[2] - texBounds[0];
                                double dV = texBounds[3] - texBounds[1];
                                //Rescaling to the partial bounds that the texture represents
                                uvs[i].u = (float) ((uvs[i].u - texBounds[0]) / dU);
                                uvs[i].v = (float) ((uvs[i].v - texBounds[1]) / dV);
                            }
                            //Rescaling to the selective area of the texture that is used
                            double[] cutBounds = shaderLayer.getCutoutBounds();
                            if (cutBounds != null) {
                                double dU = cutBounds[2] - cutBounds[0];
                                double dV = cutBounds[3] - cutBounds[1];
                                uvs[i].u = (float) (cutBounds[0] + dU * uvs[i].u);
                                uvs[i].v = (float) (cutBounds[1] + dV * uvs[i].v);
                            }
                        }
                    }
                    if (renderFace) {
                        for (int i = 0; i < 4; i++) putVertexData(builder, f.getVertices()[i], faceNormal, uvs[i], tempSprite, colour);
                        quads.add(builder.build());
                    }
                }
            }
        }
    }
    if (callback != null)
        quads = callback.modifyQuads(callbackObject, quads);
    return ImmutableList.copyOf(quads);
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) UnpackedBakedQuad(net.minecraftforge.client.model.pipeline.UnpackedBakedQuad) TRSRTransformation(net.minecraftforge.common.model.TRSRTransformation) UnpackedBakedQuad(net.minecraftforge.client.model.pipeline.UnpackedBakedQuad) ShaderCase(blusunrize.immersiveengineering.api.shader.ShaderCase) IShaderItem(blusunrize.immersiveengineering.api.shader.IShaderItem) ShaderLayer(blusunrize.immersiveengineering.api.shader.ShaderCase.ShaderLayer) ResourceLocation(net.minecraft.util.ResourceLocation) ShaderWrapper(blusunrize.immersiveengineering.api.shader.CapabilityShader.ShaderWrapper) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) ItemStack(net.minecraft.item.ItemStack) ComparableItemStack(blusunrize.immersiveengineering.api.ComparableItemStack)

Example 2 with ShaderCase

use of blusunrize.immersiveengineering.api.shader.ShaderCase in project ImmersiveEngineering by BluSunrize.

the class ModelShaderMinecart method render.

@Override
public void render(Entity entity, float f0, float f1, float f2, float f3, float f4, float f5) {
    ShaderCase sCase = null;
    ItemStack shader = null;
    if (shadedCarts.containsKey(entity.getEntityId())) {
        shader = shadedCarts.get(entity.getEntityId());
        if (shader != null && shader.getItem() instanceof IShaderItem)
            sCase = ((IShaderItem) shader.getItem()).getShaderCase(shader, null, "immersiveengineering:minecart");
    }
    if (sCase != null) {
        GL11.glEnable(GL11.GL_BLEND);
        OpenGlHelper.glBlendFunc(770, 771, 0, 1);
        sideModels[5].rotationPointY = 4.0F - f2;
        sideModelsMirrored[5].rotationPointY = 4.0F - f2;
        for (int part = 0; part < sideModels.length - 1; part++) if (sideModels[part] != null) {
            float scale = 1;
            ShaderLayer[] layers = sCase.getLayers();
            for (int pass = 0; pass < layers.length; pass++) if (sCase.renderModelPartForPass(shader, null, "" + part, pass)) {
                int col = sCase.getARGBColourModifier(shader, null, "" + part, pass);
                boolean upScale = pass != layers.length - 2;
                GL11.glScalef(scale, scale, scale);
                GL11.glColor4f((col >> 16 & 255) / 255f, (col >> 8 & 255) / 255f, (col & 255) / 255f, (col >> 24 & 255) / 255f);
                //							if(pass==maxPasses-1)
                //								ClientUtils.bindTexture("immersiveengineering:textures/models/shaders/minecart_uncoloured.png");
                //							else if(pass==maxPasses-2 && ((ShaderCaseMinecart)sCase).additionalTexture!=null)
                //								ClientUtils.bindTexture(sCase.getBaseTexturePath()+((ShaderCaseMinecart)sCase).additionalTexture+".png");
                //							else if(pass==0)
                //								ClientUtils.bindTexture("immersiveengineering:textures/models/shaders/minecart_0.png");
                //							else
                //							{
                //								ClientUtils.bindTexture(sCase.getBaseTexturePath()+"1_"+sCase.getOverlayType()+".png");
                //								upScale = false;
                //							}
                ClientUtils.mc().getTextureManager().bindTexture(sCase.getReplacementSprite(shader, null, "" + part, pass));
                sCase.modifyRender(shader, null, "" + part, pass, true, false);
                if (((ShaderCaseMinecart) sCase).mirrorSideForPass[pass])
                    sideModelsMirrored[part].render(f5);
                else
                    sideModels[part].render(f5);
                sCase.modifyRender(shader, null, "" + part, pass, false, false);
                GL11.glColor4f(1, 1, 1, 1);
                GL11.glScalef(1 / scale, 1 / scale, 1 / scale);
                if (upScale)
                    scale += .001f;
            }
        }
        GL11.glDisable(GL11.GL_BLEND);
    } else
        super.render(entity, f0, f1, f2, f3, f4, f5);
}
Also used : IShaderItem(blusunrize.immersiveengineering.api.shader.IShaderItem) ShaderCase(blusunrize.immersiveengineering.api.shader.ShaderCase) ItemStack(net.minecraft.item.ItemStack)

Example 3 with ShaderCase

use of blusunrize.immersiveengineering.api.shader.ShaderCase in project ImmersiveEngineering by BluSunrize.

the class ClientProxy method textureStich.

@SubscribeEvent
public void textureStich(TextureStitchEvent.Pre event) {
    IELogger.info("Stitching Revolver Textures!");
    ((ItemRevolver) IEContent.itemRevolver).stichRevolverTextures(event.getMap());
    for (ShaderRegistry.ShaderRegistryEntry entry : ShaderRegistry.shaderRegistry.values()) for (ShaderCase sCase : entry.getCases()) if (sCase.stitchIntoSheet())
        for (ShaderLayer layer : sCase.getLayers()) if (layer.getTexture() != null)
            ApiUtils.getRegisterSprite(event.getMap(), layer.getTexture());
    for (DrillHeadPerm p : ((ItemDrillhead) IEContent.itemDrillhead).perms) p.sprite = ApiUtils.getRegisterSprite(event.getMap(), p.texture);
    WireType.iconDefaultWire = ApiUtils.getRegisterSprite(event.getMap(), "immersiveengineering:blocks/wire");
    ApiUtils.getRegisterSprite(event.getMap(), "immersiveengineering:blocks/shaders/greyscaleFire");
    for (BulletHandler.IBullet bullet : BulletHandler.registry.values()) for (ResourceLocation rl : bullet.getTextures()) ApiUtils.getRegisterSprite(event.getMap(), rl);
    for (ResourceLocation rl : ModelConveyor.rl_casing) ApiUtils.getRegisterSprite(event.getMap(), rl);
    ApiUtils.getRegisterSprite(event.getMap(), ConveyorHandler.textureConveyorColour);
    ApiUtils.getRegisterSprite(event.getMap(), ConveyorBasic.texture_off);
    ApiUtils.getRegisterSprite(event.getMap(), ConveyorBasic.texture_on);
    ApiUtils.getRegisterSprite(event.getMap(), ConveyorDrop.texture_off);
    ApiUtils.getRegisterSprite(event.getMap(), ConveyorDrop.texture_on);
    ApiUtils.getRegisterSprite(event.getMap(), ConveyorVertical.texture_off);
    ApiUtils.getRegisterSprite(event.getMap(), ConveyorVertical.texture_on);
    ApiUtils.getRegisterSprite(event.getMap(), ConveyorSplit.texture_off);
    ApiUtils.getRegisterSprite(event.getMap(), ConveyorSplit.texture_on);
    ApiUtils.getRegisterSprite(event.getMap(), ConveyorSplit.texture_casing);
    ApiUtils.getRegisterSprite(event.getMap(), IEContent.fluidPotion.getStill());
    ApiUtils.getRegisterSprite(event.getMap(), IEContent.fluidPotion.getFlowing());
    ApiUtils.getRegisterSprite(event.getMap(), "immersiveengineering:items/shader_slot");
}
Also used : ShaderRegistry(blusunrize.immersiveengineering.api.shader.ShaderRegistry) DrillHeadPerm(blusunrize.immersiveengineering.common.items.ItemDrillhead.DrillHeadPerm) BulletHandler(blusunrize.immersiveengineering.api.tool.BulletHandler) ShaderLayer(blusunrize.immersiveengineering.api.shader.ShaderCase.ShaderLayer) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ShaderCase(blusunrize.immersiveengineering.api.shader.ShaderCase) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

ShaderCase (blusunrize.immersiveengineering.api.shader.ShaderCase)3 IShaderItem (blusunrize.immersiveengineering.api.shader.IShaderItem)2 ShaderLayer (blusunrize.immersiveengineering.api.shader.ShaderCase.ShaderLayer)2 ItemStack (net.minecraft.item.ItemStack)2 ComparableItemStack (blusunrize.immersiveengineering.api.ComparableItemStack)1 ShaderWrapper (blusunrize.immersiveengineering.api.shader.CapabilityShader.ShaderWrapper)1 ShaderRegistry (blusunrize.immersiveengineering.api.shader.ShaderRegistry)1 BulletHandler (blusunrize.immersiveengineering.api.tool.BulletHandler)1 DrillHeadPerm (blusunrize.immersiveengineering.common.items.ItemDrillhead.DrillHeadPerm)1 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)1 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 UnpackedBakedQuad (net.minecraftforge.client.model.pipeline.UnpackedBakedQuad)1 TRSRTransformation (net.minecraftforge.common.model.TRSRTransformation)1 IExtendedBlockState (net.minecraftforge.common.property.IExtendedBlockState)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1