Jump to content

Recommended Posts

Posted (edited)

[EDITED]

Question about my "favorite" subject in minecraft, rendering. I wish to use a custom shader on a generated texture that is displayed by a TESR. 

public class RenderTileInscription extends TileEntitySpecialRenderer<TileInscription>{

	@Override
	public void renderTileEntityAt(TileInscription te, double x, double y, double z, float partialTicks,
			int destroyStage) {
		final MagicCircle circle = HandlerModel.getInstance().tester;//this gets an instance of a object that holdes a holds a TextureAtlasSprite
		
		if(circle != null){
			bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
			
			GlStateManager.pushMatrix();
			GlStateManager.disableCull();
			GlStateManager.enableBlend();
			GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
			GlStateManager.disableAlpha();
			GlStateManager.translate(x, y+0.0001f, z);
			GlStateManager.rotate(90f, 1f, 0f, 0f);
			GlStateManager.scale(0.3625f, 0.3625f, 0.3625f);
			
			UtilRender.renderStandQuadTexture(circle.getTextureSprite());//renderQuadTexture metho
			
			GlStateManager.enableAlpha();
			GlStateManager.disableBlend();
			GlStateManager.enableCull();
			GlStateManager.popMatrix();
		}
	}
	
}
////methods from UtilRender//////
public static void renderQuadTexture(TextureAtlasSprite texture, int par1, int par2, int par3, int par4, int brightness){
		Tessellator tes = Tessellator.getInstance();
		tes.getBuffer().begin(GL11.GL_QUADS, ClientProxy.POSITION_TEX_S_COMP);
		tes.getBuffer().pos(par1, par2 + par4, 0).tex(texture.getMinU(), texture.getMaxV()).lightmap(brightness, brightness).endVertex();
		tes.getBuffer().pos(par1 + par3, par2 + par4, 0).tex(texture.getMaxU(), texture.getMaxV()).lightmap(brightness, brightness).endVertex();
		tes.getBuffer().pos(par1 + par3, par2, 0).tex(texture.getMaxU(), texture.getMinV()).lightmap(brightness, brightness).endVertex();
		tes.getBuffer().pos(par1, par2, 0).tex(texture.getMinU(), texture.getMinV()).lightmap(brightness, brightness).endVertex();
		tes.draw();
}
  
public static void renderStandQuadTexture(TextureAtlasSprite texture, int brightness){	
  	renderQuadTexture(texture, 0, 0, 16, 16, brightness);
}
public static void renderStandQuadTexture(TextureAtlasSprite texture){
	renderQuadTexture(texture, 0, 0, 16, 16, 240);
}

The above code will display the correct drawn texture (made larger than a standard block for ease of sight), now the question is how to implement custom shaders. The specific shading effect I am looking to make is where an EntityPlayer instance will activate (right click) the block, that will send the information of the specified held item and the exact position relative to the bounding box where the player clicked. This will then be used by the TESR so as to display the predefined texture (the circle.getTextureSprite() part) with a "light" source of a specific color, with source position (starting point) being at the point where the player originally right clicked the block. This color will then gradually fade (like a light) over a specific area. To summarize, I wish to use a shader to create a gradual light fate effect, with passed in vars of a color (vec3 or 4), and a position relative to the texture (vec2) (these variables being provided via uniforms to a fragment shader). This should look (of better quality) like the transition (from the attached pictures) of pic1 -> pic2. Needless to say, compatible for multiple "light" sources.

 

Now from what I understand, I don't believe I need to use a vertex shader, and only a fragment shader. More so, I really don't think I need anything overly fancy, and while in non-minecraft opengl, I would use a normal mapping, for this, I would prefer to not, as the base picture should be uniform color (more or less), and I am only looking for a simple lighting overlay, not any ultra-realism. 

 

Thus, thats more or less my question: how do I do this form of effect within minecraft, preferably in a relatively simple fashion. 

 

 

state0.png pic1

state1.pngpic2

state2.pngpic3

Edited by draganz
make easier for one to read
Posted
22 hours ago, draganz said:

Question relating toward implementation within minecraft (forge). How does one go about this: I wish to have a texture (lets say a white square) that will be rendered via a TESR; lets say it looks like this (I do hope this posts correctly):

 

(p1)                 (p2)                       (p3)

      XooooooooooXoooooooooooX

      oooooooooooooooooooooooo

(p4)XoooooooooUooooooooooooX (p5)

      oooooooooooooooooooooooo 

      XoooooooooXooooooooooooX

(p6)                (p7)                          (p8)

, with the center being "U," and different points being labeled p(n) and designated with "X." So lets begin: I wish to have say p2 render (like a light) of red from its point to (creating like a  gradually fading triangle) from p1, p3, and U. This looking like (with "R being a strong red color, and "r" being a lighter, use your imagination for the gradual fading from strong to weak):

 

(p1)                 (p2)                       (p3)

      Xo rrrrrRRRRXRRRRrrrrrrrrr oX

      oooo rrrrRRRRRRRrrrr oooooo

(p4)XoooooooooUooooooooooooX (p5)

      oooooooooooooooooooooooo 

      XoooooooooXooooooooooooX

(p6)                (p7)                          (p8)

 

With p2 having the strongest point of red, and the outer "r" points being near white, needless to say, other p(n) points remaining white as well (non coloring) ; from there, it should also be possible to do the like with other colors and also using the same implementation for the remaining points on the texture, to create similar effects. How to do this is known for me going from scratch (no from within a mod in Minecraft; and as aside note, so do I know how to change the entire textures color (at once)); my question being more on the line of how to do specific vector (color) shadings on the texture, prefereably via minecrafts implementations, should it be possible.

 

example in picture format as follows (beginning texture [state0.png] => after first point shading [state1.png] => further implementation [state2.png]):

state0.png

state1.png

state2.png

Can you explain what you are trying to do? You give examples of what you have in mind, but nothing truly explaining what it is you want to do in the TESR. Rendering something through a TESR is easy if you know what you are doing, but we are gonna need a little more info about what it is you are trying to do before we can help.

Posted
On 6/1/2017 at 9:42 PM, draganz said:

I wish to use a custom shader on a generated texture that is displayed by a TESR. 

If you want to use a GLSL shader... use a GLSL shader. There is nothing stopping you. The game uses OpenGL after all and all normal GL calls are available to you. Load your shader, compile it, link to a shader program, delete the shader, bind the program, upload your data, render and you are done. Yes, you are absolutely free to use modern OpenGL(by that I mean ~<=3.3) with buffers and stuff, MC somewhat uses them already and If I recall correctly the game even requires GL3.0+ support to launch. Yes it is going to be a pain to implement with vanilla provided Tessellator's VertexBuffer as the way it uploads data is... weird. Yes, you can allocate your own buffer, put stuff in, bind and render, just like you would do for normal gl rendering. If you want more specific details you should browse lwjgl's tutorials and wiki as MC uses lwjgl.

Note that there is no guarantee that other mods will not mess stuff up(thinking about the shadersmod for example) so you should be as cautious as possible and not forget to reset all GL states and binds after you are done.

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.