Jump to content

Recommended Posts

Posted

Hello everyone,

Recently I have encoutered a problem with my mod (or maybe the way minecraft work), and after searching for days without any solution, I post here in case any of you can help me.

My goal : Change the color of a mob depending on a custom tag.

What I have done : Within a function that I have register to the RenderLivingEvent#Pre event, I checked the entity tag and change the value of the corresponding shader's(rendertype_entity_cutout_no_cull) Uniform that I have added (specific value = appeared in flat color). Then in another one registered to RenderLivingEvent#Post, I set back the Uniform to the base value (base value = appeared black and white).

The result : it worked, kind of...

VaUQlu4WQi5V.png?o=1
Case 1 : This is the basic result.

W6IhLxyr1SNO.png?o=1
Case 1bis : This is the same iteration but I have cleared the zombie item.

LNXTTlUEgnZb.png?o=1
Case 2 : This is the result when I don't reset the Unifom in the RenderLivingEvent#Post event.

cbcykb3cTike.png?o=1
Case 3 : This is the base result when I am 16 block away from entities.

jLJ2f2B3zMxj.png?o=1
Case 4 : This is the result when I am 16 block away from entities and I don't reset the Unifom in the RenderLivingEvent#Post event.

Some explanation :

  • I spawned the mobs in a specific order so they render in that order (Stray->Skeleton->Zombie->Witch->Blaze).
  • As showed in case 1 and 3, simple entities (without object or layers) are rendered after the RenderLivingEvent#Post event (since I call the uniform in there to make them black and white). If the entity has objects or layers, then the base model is rendered before the Post event and the layers are rendered after (look at the stray an zombie in case 1).
  • From case 2, I assumed that the entity is complitely rendered (base and layers/objects) before the next RenderLivingEvent#Pre.
  • From case 3 and 4, I assumed that rendering change when entities are 16 block away from the player. Here you can see that the entity will finish rendering after the next RenderLivingEvent#Pre. The base model is still rendered before the Post event.

My conclusion :
The rendering of entities are slightly delayed, permitting the CPU to modified the Uniform before the GPU has finished rendering it. From what I have tested it's not a problem with my code.

I don't know if there is a solution to my problem.

Thanks in advance for any help !

PS : English is not my mother tongue, so excuse my writing.

  • 1 month later...
Posted

I'm looking to do a very similar thing but for blocks instead of entities. Could you please share the code where you actually applied the coloured shading?

Also, do you know an event similar to RenderLivingEvent but for blocks instead that I can use to apply this kind of shading?

Posted
On 6/7/2022 at 12:48 PM, SoLegendary said:

I'm looking to do a very similar thing but for blocks instead of entities. Could you please share the code where you actually applied the coloured shading?

Here is what I do :

In a function that I subscibe to RenderLivingEvent$Pre, I change the value of the uniform in the corresponding shader.

@SubscribeEvent
public static void renderEntityPre(RenderLivingEvent.Pre event) {
...
ECNC_Shader = GameRenderer.getRendertypeEntityCutoutNoCullShader(); // Access to the shader
ECNC_Uniform_RenderValue = ECNC_Shader.getUniform("RenderValue"); // Access to the shader uniform
ECNC_Uniform_RenderValue.set(1); // Change the uniform value
...
}

I have modified the vanilla fragment shader "rendertype_entity_cutout_no_cull.fsh" to process the new uniform.

...
uniform int RenderValue;
...
void main() {
...
if(RenderValue == 0)
{
	color.r = 0.0;
	color.g = 0.0;
	color.b = 1.0;
}
...
}

 

On 6/7/2022 at 12:48 PM, SoLegendary said:

Also, do you know an event similar to RenderLivingEvent but for blocks instead that I can use to apply this kind of shading?

I can't give you either the shader or the function used to render blocks, but you can probably find them if you take a look in the vanilla code (that is how I find what I used).

 

Hope it can help you :)

  • 8 months later...
Posted

Hello again,

So after many trials and error I manage to do something that work, even if it's not perfect.

For everyone who ever want to achieve something like me here is an advice : forget about shaders, at least for now.

My way to go is to create a custom renderer class based of "LivingEntityRenderer", then on the "RenderLivingEvent.Pre" event I switch the rendering method to mine.
Now you have an access to change vanilla rendering method of entity that shoul be compatible with other mod (I didn't test much). For changing the colors I played with the "MultiBufferSource".

finalcase.png

It's not perfect but it work !

 

Hope that it help someone one day.

  • 5 months later...
Posted
On 2/10/2023 at 12:15 PM, Brunk said:

Hello again,

So after many trials and error I manage to do something that work, even if it's not perfect.

For everyone who ever want to achieve something like me here is an advice : forget about shaders, at least for now.

My way to go is to create a custom renderer class based of "LivingEntityRenderer", then on the "RenderLivingEvent.Pre" event I switch the rendering method to mine.
Now you have an access to change vanilla rendering method of entity that shoul be compatible with other mod (I didn't test much). For changing the colors I played with the "MultiBufferSource".

finalcase.png

It's not perfect but it work !

 

Hope that it help someone one day.

i actually wanted to do something similar, apply some rendering to the player to make something like a blur, im looking at some shaders with .frag and .vert, but i dont know how would I apply them, do you know something that may help me?

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.