Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions shaders/composite1.fsh
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,12 @@ vec3 AerialPerspective(float dist, float skyLightmap) {
}

void main() {
vec2 texure4 = ScreenTex(colortex4).rg;
vec3 texure4 = ScreenTex(colortex4).rgb;

vec4 decode4 = Decode4x8F(texure4.r);
vec4 decodeMat = Decode4x8F(texure4.b);
Mask mask = CalculateMasks(decode4.r);
Material mat = GetMaterial(decodeMat);
float smoothness = decode4.g;
float torchLightmap = decode4.b;
float skyLightmap = decode4.a;
Expand All @@ -142,10 +144,10 @@ void main() {
mask.bits.xy = vec2(1.0, mask.water);
mask.materialIDs = EncodeMaterialIDs(1.0, mask.bits);

texure4 = vec2(Encode4x8F(vec4(mask.materialIDs, decode0.r, 0.0, decode0.g)), texure0.g);
texure4.rg = vec2(Encode4x8F(vec4(mask.materialIDs, decode0.r, 0.0, decode0.g)), texure0.g);
} else texure4.g = ReEncodeNormal(texure4.g, 11.0);

gl_FragData[1] = vec4(texure4.rg, 0.0, 1.0);
gl_FragData[1] = vec4(texure4.rgb, 1.0);

if (depth1 - mask.hand >= 1.0) return;

Expand All @@ -162,7 +164,7 @@ void main() {
backPos[1] = mat3(gbufferModelViewInverse) * backPos[0];


vec3 composite = CalculateShadedFragment(mask, torchLightmap, skyLightmap, GI, normal, vertNormal, smoothness, backPos);
vec3 composite = CalculateShadedFragment(mask, mat, torchLightmap, skyLightmap, GI, normal, vertNormal, backPos);
composite *= pow(diffuse, vec3(2.8));

if (mask.water > 0.5 || isEyeInWater == 1)
Expand Down
51 changes: 23 additions & 28 deletions shaders/gbuffers_main.fsh
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,8 @@ vec4 GetDiffuse(vec2 coord) {
return vec4(color.rgb, 1.0) * GetTexture(texture, coord);
}

vec3 GetNormal(vec2 coord) {
#ifdef NORMAL_MAPS
vec3 normal = GetTexture(normals, coord).xyz;
#else
vec3 normal = vec3(0.5, 0.5, 1.0);
#endif
vec3 GetNormal(vec3 normal) {
normal = vec3(0.5, 0.5, 1.0);

normal.xyz = tbnMatrix * normalize(normal.xyz * 2.0 - 1.0);

Expand Down Expand Up @@ -129,48 +125,47 @@ void main() {

vec2 coord = ComputeParallaxCoordinate(texcoord, position[1]);

vec4 diffuse = GetDiffuse(coord);
if (diffuse.a < 0.1000003) discard;

vec3 normal = GetNormal(coord);

float specularity = GetSpecularity(coord);

#if defined WEATHER && defined NORMAL_MAPS
specularity = min(specularity + wetness, 0.99);
#endif
Material mat = CalculateMaterial(coord, vec4(color, 1.0), texture, normals, specular);

if (mat.albedo.a < 0.1000003) discard;

mat.normal = GetNormal(mat.normal);

float waterMask = 0.0;

#if !defined gbuffers_water
float encodedMaterialIDs = EncodeMaterialIDs(materialIDs, vec4(0.0, 0.0, nightVision, 0.0));

gl_FragData[0] = vec4(0.0, 0.0, 0.0, 1.0);
gl_FragData[1] = vec4(diffuse.rgb, 1.0);
gl_FragData[1] = vec4(mat.albedo.rgb, 1.0);
gl_FragData[2] = vec4(0.0);
gl_FragData[3] = vec4(0.0);
gl_FragData[4] = vec4(Encode4x8F(vec4(encodedMaterialIDs, specularity, vertLightmap.rg)), EncodeNormalU(normal, tbnMatrix[2]), 0.0, 1.0);
gl_FragData[4] = vec4(Encode4x8F(vec4(encodedMaterialIDs, waterMask, vertLightmap.rg)), EncodeNormalU(mat.normal, tbnMatrix[2]), Encode4x8F(vec4(mat.f0, mat.roughness, mat.emmisiveTranslucence, mat.AO)), 1.0);
#else
specularity = clamp(specularity, 0.0, 1.0 - 1.0 / 255.0);

Mask mask = EmptyMask;

if (abs(mcID - 8.5) < 0.6) {
if (!gl_FrontFacing) discard;

diffuse = vec4(0.215, 0.356, 0.533, 0.75);
mat.albedo = vec4(0.215, 0.356, 0.533, 0.75);

normal = tbnMatrix * GetWaveNormals(position[1] - worldDisplacement, tbnMatrix[2]);
mat.normal = tbnMatrix * GetWaveNormals(position[1] - worldDisplacement, tbnMatrix[2]);

specularity = 1.0;
mat.f0 = 0.05;
mat.roughness = 0.05;
mat.emmisiveTranslucence = 0.0;
mat.AO = 1.0;

waterMask = 1.0;
}

vec3 composite = CalculateShadedFragment(mask, vertLightmap.r, vertLightmap.g, vec3(0.0), normal.xyz * mat3(gbufferModelViewInverse), tbnMatrix[2], specularity, position);
composite *= pow(diffuse.rgb, vec3(2.2));
vec3 composite = CalculateShadedFragment(mask, mat, vertLightmap.r, vertLightmap.g, vec3(0.0), mat.normal.xyz * mat3(gbufferModelViewInverse), tbnMatrix[2], position);
composite *= pow(mat.albedo.rgb, vec3(2.2));

gl_FragData[0] = vec4(Encode4x8F(vec4(specularity, vertLightmap.g, 0.0, 0.1)), EncodeNormal(normal.xyz, 11), 0.0, 1.0);
gl_FragData[0] = vec4(Encode4x8F(vec4(waterMask, vertLightmap.g, 0.0, 0.1)), EncodeNormal(mat.normal.xyz, 11), Encode4x8F(vec4(mat.f0, mat.roughness, mat.emmisiveTranslucence, mat.AO)), 1.0);
gl_FragData[1] = vec4(0.0);
gl_FragData[2] = vec4(1.0, 0.0, 0.0, diffuse.a);
gl_FragData[3] = vec4(composite, diffuse.a);
gl_FragData[2] = vec4(1.0, 0.0, 0.0, mat.albedo.a);
gl_FragData[3] = vec4(composite, mat.albedo.a);
gl_FragData[4] = vec4(0.0);
#endif

Expand Down
7 changes: 3 additions & 4 deletions shaders/lib/Fragment/Calculate_Shaded_Fragment.fsh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ float GetHeldLight(vec3 viewSpacePosition, vec3 normal, float handMask) {
return hand.x + hand.y;
}

vec3 CalculateShadedFragment(Mask mask, float torchLightmap, float skyLightmap, vec3 GI, vec3 normal, vec3 vertNormal, float smoothness, mat2x3 position) {
vec3 CalculateShadedFragment(Mask mask, Material mat, float torchLightmap, float skyLightmap, vec3 GI, vec3 normal, vec3 vertNormal, mat2x3 position) {
Shading shading;

shading.sunlight = GetLambertianShading(normal, mask) * skyLightmap;
Expand All @@ -58,17 +58,16 @@ vec3 CalculateShadedFragment(Mask mask, float torchLightmap, float skyLightmap,
shading.ambient = 1.0 + (1.0 - eyeBrightnessSmooth.g / 240.0) * 1.7;
shading.ambient += mask.nightVision * 50.0;


Lightmap lightmap;

lightmap.sunlight = shading.sunlight * sunlightColor;

lightmap.skylight = shading.skylight * pow(skylightColor, vec3(0.5));
lightmap.skylight = shading.skylight * pow(skylightColor, vec3(0.5)) * mat.AO;


lightmap.GI = GI * sunlightColor;

lightmap.ambient = vec3(shading.ambient);
lightmap.ambient = vec3(shading.ambient) * mat.AO;

lightmap.torchlight = shading.torchlight * vec3(0.7, 0.3, 0.1);

Expand Down
40 changes: 40 additions & 0 deletions shaders/lib/Fragment/Masks.fsh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,46 @@ struct Mask {
float nightVision;
};

struct Material {
vec4 albedo;
vec3 normal;
float height;
float f0;
float pourosity;
float roughness;
float AO;
float emmisiveTranslucence;
};

Material CalculateMaterial(vec2 coord, vec4 color, sampler2D texture, sampler2D normal, sampler2D specular) {
Material mat;

mat.albedo = texture2D(texture, coord) * color;
vec4 normalSample = texture2D(normal, coord);
vec4 specularSample = texture2D(specular, coord);

mat.normal = normalize(normalSample.xyz);
mat.height = normalSample.w;
mat.f0 = specularSample.x;
mat.pourosity = specularSample.y;
mat.roughness = pow2(1.0 - specularSample.z);
mat.AO = length(normalSample.xyz);
mat.emmisiveTranslucence = (1.0 - specularSample.w);

return mat;
}

Material GetMaterial(vec4 decodedMat) {
Material mat;

mat.f0 = decodedMat.r;
mat.roughness = decodedMat.g;
mat.emmisiveTranslucence = decodedMat.b;
mat.AO = decodedMat.a;

return mat;
}

#define EmptyMask Mask(0.0, 0.0, vec4(0.0), 0.0, 0.0, 0.0, 0.0, 0.0)

float EncodeMaterialIDs(float materialIDs, vec4 bits) {
Expand Down
2 changes: 1 addition & 1 deletion shaders/lib/Settings.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const int colortex2Format = R8;

** Flat Gbuffers **
const int colortex1Format = R11F_G11F_B10F;
const int colortex4Format = RG32F;
const int colortex4Format = RGB32F;

** composite0 Buffer **
const int colortex5Format = RGB8;
Expand Down
1 change: 1 addition & 0 deletions shaders/lib/Vertex/Materials.vsh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ float GetMaterialIDs(int mc_ID) { // Gather material masks
case 38: // Rose
case 59: // Wheat
case 83: // Sugar Cane
case 141: // Carrots
case 142: // Potatoes
case 175: // Double Tall Grass
case 18: // Generic leaves
Expand Down