Dax's Wiki
Advertisement

Shaders 2.0 makes use of a deferred rendering pipeline. The gbuffer shaders come first in the pipeline. They render data to textures that will be sent to the composite shader. The composite shader then renders to textures that will be sent to the final shader. The final shader renders directly to the screen.

Color Attachments[]

The data is passed from shader to shader using color attachments. There are at least 4 for all machines. For machines that can support it, there are 7. In the composite and final shaders, these are referenced by the gcolor, gdepth, gnormal, composite, gaux1, gaux2, and gaux3 uniforms. Despite the naming, all of these color attachments are the same and can be used for any purpose with the exception of the first two. The first one, gcolor has its color cleared to the current fog color before rendering. The second one, gdepth has its color cleared to solid white before rendering and uses a higher precision storage buffer suitable for storing depth values. The rest have their color cleared to black with 0 alpha.

When writing to the color attachments in the composite shader, blending is disabled. Writing to color attachments that the composite shader also reads from will generate artifacts (unless you just copy the original contents)

Vertex Attributes[]

mc_Entity - This attribute holds fundamental information about the entity to which the vertex belongs. mc_Entity.x represents the item id. mc_Entity.y, mc_Entity.z, and mc_Entity.w are reserved. Currently it is only guaranteed to be valid for terrain.

Uniforms[]

All Shaders[]

All shaders receive the following uniforms:

heldItemId - An integer indicating the id of the currently held item or -1 if there is none.

heldBlockLightValue - An integer indicating the light emission value of the held block. Typically ranges from 0 to 15.

fogMode - An integer indicating the type of fog (usually linear or exponential) or 0 if there is no fog. Equivalent to glGetInteger(GL_FOG_MODE).

worldTime - An integer indicating the current world time. For the over-world this number ranges from 0 to 24000 and loops.

viewWidth - A float indicating the width of the viewport.

viewHeight - A float indicating the height of the viewport.

aspectRatio - A float derived from viewWidth / viewHeight.

near - A float indicating the near viewing plane distance.

far - A float indicating the far viewing plane distance.

rainStrength - A float indicating the strength of the rain (or in cold biomes, snow).

sunPosition - A vec3 indicating the position of the sun in eye space.

moonPosition - A vec3 indicating the position of the moon in eye space.

cameraPosition - A vec3 indicating the position in world space of the entity to which the camera is attached.

previousCameraPosition - A vec3 indicating the position in world space of the entity to which the camera was attached during the previous frame.

gbufferModelView - The 4x4 modelview matrix after setting up the camera transformations. This uniform previously had a slightly different purpose in mind, so the name is a bit ambiguous.

gbufferModelViewInverse - The inverse of gbufferModelView.

gbuffers_textured[]

The gbuffers_textured shader receives the following uniforms:

texture - A sampler2D referencing the geometry's base texture.

gbuffers_textured_lit / gbuffers_hand / gbuffers_weather[]

The gbuffers_textured_lit, gbuffers_hand, and gbuffers_weather shaders receive the following uniforms:

texture - A sampler2D referencing the geometry's base texture.

lightmap - A sampler2D referencing the geometry's lighting texture.

gbuffers_terrain / gbuffers_water[]

The gbuffers_terrain and gbuffers_water shaders receive the following uniforms:

texture - A sampler2D referencing the geometry's base texture.

lightmap - A sampler2D referencing the geometry's lighting texture.

normals - A sampler2D referencing the texture pack's 'terrain_n.png' file.

specular - A sampler2D referencing the texture pack's 'terrain_s.png' file.

composite final[]

The composite and final shaders receive the following uniforms:

gbufferProjection - The 4x4 projection matrix that was used when the gbuffers were generated.

gbufferProjectionInverse - The inverse of gbufferProjection.

gbufferPreviousProjection - The 4x4 projection matrix that was used when the gbuffers were generated for the previous frame.

gbufferPreviousModelView - The 4x4 modelview matrix that was used after setting up the camera transformations when the gbuffers were generated for the previous frame.

shadowProjection - The 4x4 projection matrix that was used when the shadow map was generated.

shadowProjectionInverse - The inverse of shadowProjection.

shadowModelView - The 4x4 modelview matrix that was used when the shadow map was generated.

shadowModelViewInverse - The inverse of shadowModelView.

gcolor, gdepth, gnormal, composite, gaux1, gaux2, gaux3 - The textures bound to color attachments 0 through 6.

shadow - The shadow map texture. Including this uniform declaration in a shader triggers the rendering of shadows to the shadow map.

Advertisement