Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.10.2][UNSOLVED] Help With Custom OpenGL Shader


Kaiodenic
 Share

Recommended Posts

Hey! I made a GLSL shader in C++ a while back which takes a model (.obj) and paints it using an a skybox-like cubemap. It would also mix that on a 50/50 ratio with a standard texture it had. Made it look really nice and mystical. I've spent hours trying to find out how to apply custom shaders to Forge custom model blocks in Java and I'm no closer replicating that effect in Minecraft. How would I override the renderer and shader for my block? How would I make it use a .obj file (any TileEntitySpecialRenderer code I've seen uses block ModelRenderers in a ModelBase extending class) ?

 

I'm new new to Minecraft modding (only just came back to it a week ago) but I'm definitely not new to programming. Any help would be greatly appreciated!

Edited by Kaiodenic
Link to comment
Share on other sites

4 hours ago, Kaiodenic said:

How would I make it use a .obj file

To render .Obj models:

Call OBJLoader.INSTANCE.addDomain(modid) before you register your models, either in preInit or preferably in the ModelRegistryEvent.

After that, you can create your blockstate/model json as normal, but remember to point the variant to modid:somename.obj

The .mtl file also has to be in the same folder as the .obj, and share the same name (supermodel.obj & supermodel.mtl, for example)

Edited by Matryoshika

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Link to comment
Share on other sites

56 minutes ago, Kaiodenic said:

I know how to render .obj models in a typical situation. I was asking how it's done in a TileEntitySpecialRenderer because it seems like that's the only way to add custom OpenGL code to  it.

Getting a BakedModel object
Rendering BakedModel

  • Like 1

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Link to comment
Share on other sites

This should help a lot. Thank you!

 

As for the other points, does anyone know how to the renderer to use a custom shader? The code I've seen thus far was pure Java and only enabled/disabled effects used by vanilla, not using fully custom-written shaders. For my project I specifically need to override the fragment shader.

Link to comment
Share on other sites

1 hour ago, Kaiodenic said:

As for the other points, does anyone know how to the renderer to use a custom shader? The code I've seen thus far was pure Java and only enabled/disabled effects used by vanilla, not using fully custom-written shaders. For my project I specifically need to override the fragment shader.

Vanilla does not support custom shaders by itself (except ones activated when you spectate as a spider/creeper/enderman). So you have to use LWJGL and Open GL directly. But be ready to either completely change the way you draw model in-code or the way your shaders accept data. Because how vanilla MC pushes stuff to GL and how shaders normally work do not match at all.

Link to comment
Share on other sites

28 minutes ago, Elix_x said:

Vanilla does not support custom shaders by itself (except ones activated when you spectate as a spider/creeper/enderman). So you have to use LWJGL and Open GL directly. But be ready to either completely change the way you draw model in-code or the way your shaders accept data. Because how vanilla MC pushes stuff to GL and how shaders normally work do not match at all.

Fair enough, I'm alright with that. Would you happen to know where Minecraft initially pushes things to OpenGL based on what it is (block type, or block/entity)?

Unless it uses the same settings for everything, in which case I'll probably have to pass. I feel like changing that would make it incompatible with a lot of mods.

Edited by Kaiodenic
Link to comment
Share on other sites

10 hours ago, Kaiodenic said:

Fair enough, I'm alright with that. Would you happen to know where Minecraft initially pushes things to OpenGL based on what it is (block type, or block/entity)?

Unless it uses the same settings for everything, in which case I'll probably have to pass. I feel like changing that would make it incompatible with a lot of mods.

It would not make it incompatible with other mods. Just make sure to "save" GL state before you start rendering with shaders to restore it after.

 

First, create custom shader helper class, that sets all uniforms, uploads shader, binds, etc... Now, if you want your shader to be customizable with resource packs, implement and register IResourceManagerReloadListener, in which you load/reload shaders. Otherwise, just upload it in post init.

 

Now, when your TESR is called, bind your shader, render OBJ model and then unbind the shader.

Seems easy? It isn't.

 

For the rendering part, as i said previously, you can either change how you upload things to shader or how you shader reads things.

The first option is easier. Just create all necessary classes using modern GL functions - Mesh, Matrix Handler, etc... For the mesh, it is recommended to use VAO with indexed position VBO and non-indexed texture & normal VBOs, because that's how OBJ model is encoded. Now you just have to write your own OBJ reader and compiler (which compiles it into a mesh). There are plenty of tutorials online on how to do this.

Read, compile and upload your model into mesh either in resource reload listener or post init and render this mesh in TESR.

 

Now just make sure that you inform users of your mod that at least GL3 support is required ;) (all modern graphics cards support it, so no much worries).

 

Note: Rendering performance can be improved very much, by binding shader once... But i'll let you think on how that can be done :) .

  • Like 1
Link to comment
Share on other sites

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
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.

 Share



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • show the code your use for this is the Event called?, use debugger to check the values in the condition
    • if you add your Biome to the Overworld via BiomeManager#addAdditionalOverworldBiomes, you need to register your Biome via DeferredRegister or RegistryEvent unfortunately a json only Biome does not work in this case
    • use debugger to check the conditions you are using before you render your Entity
    • yes, and then post the correct logs
    • Good Morning, I tried overriding one of the vanilla rock blocks according to instructions in this old thread, but failed for the same reason the org TM did, even though I got a tiny bit farther than he did. I can remove the original block entirely from world spawn, and replace it with custom version, which I want to prevent due to following up workload(adapting recipes etc. to custom block). What I tried solving the issue/actually making replacing(partially) work: 1. I had to use the original Forge variant of registering the block in main class, like that: which actually did use the custom granite block as replacer(not exactly illustrated in the old thread), but didn't consider it on world feature generation... 2. I then believed it was due to not using correct path variables for assets texture/models/blockstates etc., so I created missing asset packets for both, vanilla asset path, and my mod path. This also did not fix the issue with creating holes filled up with Items.AIR on world feature generation. 3. I then tried to remove the vanilla granite block during feature generation, and reimported it after with my replacement set up, during feature generation as well(according to @Luis_ST advice). But the holes were still there, only this time I got my replaced granite block spawned as well. What do I want to achieve(asking myself and you in hope maybe there's a better solution)? Mojang found it a good idea, to give one of the hardest rock materials on this planet, the .harvestLevel(soft as a pillow), so I can harvest it with a wooden pickaxes(which technically is even worth, but doesn't matter since wooden "pickaxe" tools do not exist in my mod). I really just want to compare harvestLevel of any of my tools, against the harvestLevel of the targetBlock, so I can automatically disallow harvesting it, if the tool doesn't match the harvestLevel(which for whatever reason does not work as intended in 1.16.5 Minecraft). Edit: and before you shout "doPlayerHarvestCheck". Yes, I do that! Edit2: Also, why are there Manga Comic Girls, on the right upper corner of my Monitor, stating how can it be that big?(whatever "it" is?)
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.