Jump to content

Recommended Posts

Posted

Hi

I want to solve an error of a mod called MotionBlur that give player a blur effect but while toggling perspective, the blur disappear.

So, i created a method to when player toggle perspective, it give blur but it's buggy like it works with Third Person View but Third Person Rear View and First Person View doesn't work.

Here is the code:

@SubscribeEvent
    public void onKey(final InputEvent.KeyInputEvent event) {
        if (this.mc.thePlayer != null && MotionBlurMod.isEnabled && Keyboard.isKeyDown(this.mc.gameSettings.keyBindTogglePerspective.getKeyCode())) {
            try {
                //final Method method = ReflectionHelper.findMethod((Class)EntityRenderer.class, (Object)this.mc.entityRenderer, new String[] { "loadShader", "func_175069_a" }, new Class[] { ResourceLocation.class });
            	this.mc.entityRenderer.loadShader(new ResourceLocation("motionblur", "motionblur"));
                this.mc.entityRenderer.getShaderGroup().createBindFramebuffers(this.mc.displayWidth, this.mc.displayHeight);
            }
            catch (Exception ex) {}
        }
    }
Quote

Also, multiple error pop-up when toggling perspective: 

[Client thread/WARN]: Could not find uniform named InSize in the specified shader program.
 [Client thread/WARN]: Could not find uniform named InSize in the specified shader program.
 [Client thread/WARN]: Could not find uniform named InSize in the specified shader program.
 

 

Posted

more src code would be better for us to get a understanding how the code works. and taking a guess form the error message inside your shader program(i am assuming this is the motionblur file) you don't have a uniform with the InSize name.

Posted
17 hours ago, Discult said:

more src code would be better for us to get a understanding how the code works. and taking a guess form the error message inside your shader program(i am assuming this is the motionblur file) you don't have a uniform with the InSize name.

public void execute(final MinecraftServer server, final ICommandSender sender, final String[] args) {
        if (args.length == 0) {
        	sender.addChatMessage((ITextComponent)new TextComponentString("Usage: /motionblur <0 - 10>."));
        }
        else {
            final int amount = NumberUtils.toInt(args[0], -1);
            if (amount >= 0 && amount <= 10) {
                if (MotionBlurMod.isFastRenderEnabled()) {
                	sender.addChatMessage((ITextComponent)new TextComponentString("Motion blur does not work if Fast Render is enabled, please disable it in Options > Video Settings > Performance."));
                }
                else {
                    if (this.mc.entityRenderer.getShaderGroup() != null) {
                        this.mc.entityRenderer.getShaderGroup().deleteShaderGroup();
                    }
                    if (amount != 0) {
                        MotionBlurMod.isEnabled = true;
                        MotionBlurMod.blurAmount = amount;
                        try {
                        	final Method method = ReflectionHelper.findMethod((Class)EntityRenderer.class, (Object)this.mc.entityRenderer, new String[] { "loadShader", "loadShader" }, new Class[] { ResourceLocation.class });
                            method.invoke(this.mc.entityRenderer, new ResourceLocation("motionblur", "motionblur"));
                            this.mc.entityRenderer.getShaderGroup().createBindFramebuffers(this.mc.displayWidth, this.mc.displayHeight);
                            sender.addChatMessage((ITextComponent)new TextComponentString("Motion blur enabled."));
                        }
                        catch (Throwable ex) {
                        	sender.addChatMessage((ITextComponent)new TextComponentString("Failed to enable Motion blur."));
                            ex.printStackTrace();
                        }
                    }
                    else {
                        MotionBlurMod.isEnabled = false;
                        sender.addChatMessage((ITextComponent)new TextComponentString("Motion blur disabled."));
                    }
                }
            }
            else {
            	sender.addChatMessage((ITextComponent)new TextComponentString("Invalid amount."));
            }
        }
    }

Here is MotionBlurCommand class

@Mod(name = "MotionBlurMod", modid = "motionblurmod", version = "1.0", acceptedMinecraftVersions = "*")
public class MotionBlurMod
{
    private Minecraft mc;
    private Map domainResourceManagers;
    public static double blurAmount;
    public static boolean isEnabled;
    
    public MotionBlurMod() {
        this.mc = Minecraft.getMinecraft();
    }
    
    @Mod.EventHandler
    public void init(final FMLInitializationEvent event) {
        ClientCommandHandler.instance.registerCommand((ICommand)new MotionBlurCommand());
        MinecraftForge.EVENT_BUS.register((Object)this);
    }
    
    @SubscribeEvent
    public void onClientTick(final TickEvent.ClientTickEvent event) {
        if (this.domainResourceManagers == null) {
            try {
                for (final Field field : SimpleReloadableResourceManager.class.getDeclaredFields()) {
                    if (field.getType() == Map.class) {
                        field.setAccessible(true);
                        this.domainResourceManagers = (Map)field.get(Minecraft.getMinecraft().getResourceManager());
                        break;
                    }
                }
            }
            catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        if (!this.domainResourceManagers.containsKey("motionblur")) {
            this.domainResourceManagers.put("motionblur", new MotionBlurResourceManager());
        }
    }
    
    @SubscribeEvent
    public void onKey(final InputEvent.KeyInputEvent event) {
        if (this.mc.thePlayer != null && MotionBlurMod.isEnabled && Keyboard.isKeyDown(this.mc.gameSettings.keyBindTogglePerspective.getKeyCode())) {
            try {
            	final Method method = ReflectionHelper.findMethod((Class)EntityRenderer.class, (Object)this.mc.entityRenderer, new String[] { "loadShader", "loadShader" }, new Class[] { ResourceLocation.class });
                method.invoke(this.mc.entityRenderer, new ResourceLocation("motionblur", "motionblur"));
                this.mc.entityRenderer.getShaderGroup().createBindFramebuffers(this.mc.displayWidth, this.mc.displayHeight);
            }
            catch (Exception ex) {}
        }
    }
    
    public static boolean isFastRenderEnabled() {
        try {
            final Field fastRender = GameSettings.class.getDeclaredField("ofFastRender");
            return fastRender.getBoolean(Minecraft.getMinecraft().gameSettings);
        }
        catch (Exception var1) {
            return false;
        }
    }
    
    static {
        MotionBlurMod.blurAmount = 0.75;
        MotionBlurMod.isEnabled = false;
    }
}

Here MotionBlurMod main class

public class MotionBlurResource implements IResource
{
    private static final String JSON = "{\"targets\":[\"swap\",\"previous\"],\"passes\":[{\"name\":\"phosphor\",\"intarget\":\"minecraft:main\",\"outtarget\":\"swap\",\"auxtargets\":[{\"name\":\"PrevSampler\",\"id\":\"previous\"}],\"uniforms\":[{\"name\":\"Phosphor\",\"values\":[%.2f, %.2f, %.2f]}]},{\"name\":\"blit\",\"intarget\":\"swap\",\"outtarget\":\"previous\"},{\"name\":\"blit\",\"intarget\":\"swap\",\"outtarget\":\"minecraft:main\"}]}";
    
    public InputStream getInputStream() {
        final double amount = 0.7 + MotionBlurMod.blurAmount / 100.0 * 3.0 - 0.01;
        return IOUtils.toInputStream(String.format(Locale.ENGLISH, "{\"targets\":[\"swap\",\"previous\"],\"passes\":[{\"name\":\"phosphor\",\"intarget\":\"minecraft:main\",\"outtarget\":\"swap\",\"auxtargets\":[{\"name\":\"PrevSampler\",\"id\":\"previous\"}],\"uniforms\":[{\"name\":\"Phosphor\",\"values\":[%.2f, %.2f, %.2f]}]},{\"name\":\"blit\",\"intarget\":\"swap\",\"outtarget\":\"previous\"},{\"name\":\"blit\",\"intarget\":\"swap\",\"outtarget\":\"minecraft:main\"}]}", amount, amount, amount));
    }
    
    public boolean hasMetadata() {
        return false;
    }
    
    public IMetadataSection getMetadata(final String metadata) {
        return null;
    }
    
    public ResourceLocation getResourceLocation() {
        return null;
    }
    
    public String getResourcePackName() {
        return null;
    }

    public void close() throws IOException {
    }
}

Here MotionBlurRessource class 

public class MotionBlurResourceManager implements IResourceManager
{
    public Set<String> getResourceDomains() {
        return null;
    }
    
    public IResource getResource(final ResourceLocation location) throws IOException {
        return (IResource)new MotionBlurResource();
    }
    
    public List<IResource> getAllResources(final ResourceLocation location) throws IOException {
        return null;
    }
}

Then MotionBlurRessourceManager class

 

Anyways, what does it mean "don't have a uniform with the InSize name" ?

Thank you for replying

Posted

I found this explanation here

 
 
 
 
 
 
5
Quote

These are warnings when Minecraft tries to pass a Uniform variable (that is declared in the program json) to the fsh and vsh programs but either one or both never reference the uniform variable or OpenGL optimized out the variable for being unused. It shouldn't affect shader performance or compilation in any way. Perhaps the fix would be for the Minecraft code to just not output a warning when it fails to send a uniform to a specific shader program? Maybe only output the warning if both vsh and fsh do not use the uniform.

That's from here: https://bugs.mojang.com/browse/MC-103633

Posted

The main problem is motionblur disappear on toggling perspective but it's buggy like it works with Third Person View but Third Person Rear View and First Person View doesn't work.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.