Attempt to fix fullbright lighting.
Fix lightmap value calculation.
This commit is contained in:
parent
d5b94aa9c8
commit
2c054fca76
7 changed files with 46 additions and 55 deletions
|
@ -107,8 +107,10 @@ public interface IForgeVertexBuilder
|
||||||
default int applyBakedLighting(int lightmapCoord, ByteBuffer data) {
|
default int applyBakedLighting(int lightmapCoord, ByteBuffer data) {
|
||||||
int bl = LightTexture.func_228450_a_(lightmapCoord);
|
int bl = LightTexture.func_228450_a_(lightmapCoord);
|
||||||
int sl = LightTexture.func_228454_b_(lightmapCoord);
|
int sl = LightTexture.func_228454_b_(lightmapCoord);
|
||||||
bl = Math.max(bl, Short.toUnsignedInt(data.getShort(26)));
|
int blBaked = Short.toUnsignedInt(data.getShort(24)) >> 4;
|
||||||
sl = Math.max(sl, Short.toUnsignedInt(data.getShort(24)));
|
int slBaked = Short.toUnsignedInt(data.getShort(26)) >> 4;
|
||||||
|
bl = Math.max(bl, blBaked);
|
||||||
|
sl = Math.max(sl, slBaked);
|
||||||
return LightTexture.func_228451_a_(bl, sl);
|
return LightTexture.func_228451_a_(bl, sl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,7 @@ import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class OBJModel implements IMultipartModelGeometry<OBJModel>
|
public class OBJModel implements IMultipartModelGeometry<OBJModel>
|
||||||
{
|
{
|
||||||
|
private static Vector4f COLOR_WHITE = new Vector4f(1, 1, 1, 1);
|
||||||
private static Vec2f[] DEFAULT_COORDS = {
|
private static Vec2f[] DEFAULT_COORDS = {
|
||||||
new Vec2f(0, 0),
|
new Vec2f(0, 0),
|
||||||
new Vec2f(0, 1),
|
new Vec2f(0, 1),
|
||||||
|
@ -337,7 +338,7 @@ public class OBJModel implements IMultipartModelGeometry<OBJModel>
|
||||||
return Optional.ofNullable(parts.get(name));
|
return Optional.ofNullable(parts.get(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Pair<BakedQuad,Direction> makeQuad(int[][] indices, int tintIndex, Vector4f colorTint, Vector4f ambientColor, boolean isFullbright, TextureAtlasSprite texture, TransformationMatrix transform)
|
private Pair<BakedQuad,Direction> makeQuad(int[][] indices, int tintIndex, Vector4f colorTint, Vector4f ambientColor, TextureAtlasSprite texture, TransformationMatrix transform)
|
||||||
{
|
{
|
||||||
boolean needsNormalRecalculation = false;
|
boolean needsNormalRecalculation = false;
|
||||||
for (int[] ints : indices)
|
for (int[] ints : indices)
|
||||||
|
@ -364,10 +365,18 @@ public class OBJModel implements IMultipartModelGeometry<OBJModel>
|
||||||
BakedQuadBuilder builder = new BakedQuadBuilder(texture);
|
BakedQuadBuilder builder = new BakedQuadBuilder(texture);
|
||||||
|
|
||||||
builder.setQuadTint(tintIndex);
|
builder.setQuadTint(tintIndex);
|
||||||
builder.setApplyDiffuseLighting(!isFullbright);
|
|
||||||
|
|
||||||
int fakeLight = (int)((ambientColor.getX() + ambientColor.getY() + ambientColor.getZ()) * 15 / 3.0f);
|
boolean diffuse = true;
|
||||||
Vec2f uv2 = new Vec2f(((float) fakeLight * 0x20) / 0xFFFF, ((float) fakeLight * 0x20) / 0xFFFF);
|
|
||||||
|
Vec2f uv2 = new Vec2f(0,0);
|
||||||
|
if (ambientToFullbright)
|
||||||
|
{
|
||||||
|
int fakeLight = (int) ((ambientColor.getX() + ambientColor.getY() + ambientColor.getZ()) * 15 / 3.0f);
|
||||||
|
uv2 = new Vec2f((fakeLight << 4) / 32767.0f, (fakeLight << 4) / 32767.0f);
|
||||||
|
//uv2 = new Vec2f(0, (fakeLight << 4) / 32767.0f);
|
||||||
|
//uv2 = new Vec2f((fakeLight << 4) / 32767.0f, 0);
|
||||||
|
builder.setApplyDiffuseLighting(diffuse = (fakeLight > 0));
|
||||||
|
}
|
||||||
|
|
||||||
boolean hasTransform = !transform.isIdentity();
|
boolean hasTransform = !transform.isIdentity();
|
||||||
// The incoming transform is referenced on the center of the block, but our coords are referenced on the corner
|
// The incoming transform is referenced on the center of the block, but our coords are referenced on the corner
|
||||||
|
@ -377,11 +386,11 @@ public class OBJModel implements IMultipartModelGeometry<OBJModel>
|
||||||
{
|
{
|
||||||
int[] index = indices[Math.min(i,indices.length-1)];
|
int[] index = indices[Math.min(i,indices.length-1)];
|
||||||
Vector3f pos0 = positions.get(index[0]);
|
Vector3f pos0 = positions.get(index[0]);
|
||||||
Vector4f position = new Vector4f(pos0.getX(), pos0.getY(), pos0.getZ(), 1);
|
Vector4f position = new Vector4f(pos0);
|
||||||
Vec2f texCoord = index.length >= 2 && texCoords.size() > 0 ? texCoords.get(index[1]) : DEFAULT_COORDS[i];
|
Vec2f texCoord = index.length >= 2 && texCoords.size() > 0 ? texCoords.get(index[1]) : DEFAULT_COORDS[i];
|
||||||
Vector3f norm0 = !needsNormalRecalculation && index.length >= 3 && normals.size() > 0 ? normals.get(index[2]) : faceNormal;
|
Vector3f norm0 = !needsNormalRecalculation && index.length >= 3 && normals.size() > 0 ? normals.get(index[2]) : faceNormal;
|
||||||
Vector3f normal = norm0;
|
Vector3f normal = norm0;
|
||||||
Vector4f color = index.length >= 4 && colors.size() > 0 ? colors.get(index[3]) : new Vector4f(1, 1, 1, 1);
|
Vector4f color = index.length >= 4 && colors.size() > 0 ? colors.get(index[3]) : COLOR_WHITE;
|
||||||
if (hasTransform)
|
if (hasTransform)
|
||||||
{
|
{
|
||||||
normal = norm0.func_229195_e_();
|
normal = norm0.func_229195_e_();
|
||||||
|
@ -393,6 +402,7 @@ public class OBJModel implements IMultipartModelGeometry<OBJModel>
|
||||||
color.getY() * colorTint.getY(),
|
color.getY() * colorTint.getY(),
|
||||||
color.getZ() * colorTint.getZ(),
|
color.getZ() * colorTint.getZ(),
|
||||||
color.getW() * colorTint.getW());
|
color.getW() * colorTint.getW());
|
||||||
|
if (!diffuse) normal = new Vector3f(0,0,0);
|
||||||
putVertexData(builder, position, texCoord, normal, tintedColor, uv2, texture);
|
putVertexData(builder, position, texCoord, normal, tintedColor, uv2, texture);
|
||||||
pos[i] = position;
|
pos[i] = position;
|
||||||
norm[i] = normal;
|
norm[i] = normal;
|
||||||
|
@ -525,11 +535,10 @@ public class OBJModel implements IMultipartModelGeometry<OBJModel>
|
||||||
TextureAtlasSprite texture = spriteGetter.apply(ModelLoaderRegistry.resolveTexture(mat.diffuseColorMap, owner));
|
TextureAtlasSprite texture = spriteGetter.apply(ModelLoaderRegistry.resolveTexture(mat.diffuseColorMap, owner));
|
||||||
int tintIndex = mat.diffuseTintIndex;
|
int tintIndex = mat.diffuseTintIndex;
|
||||||
Vector4f colorTint = mat.diffuseColor;
|
Vector4f colorTint = mat.diffuseColor;
|
||||||
boolean isFullbright = ambientToFullbright && mesh.isFullbright();
|
|
||||||
|
|
||||||
for (int[][] face : mesh.faces)
|
for (int[][] face : mesh.faces)
|
||||||
{
|
{
|
||||||
Pair<BakedQuad, Direction> quad = makeQuad(face, tintIndex, colorTint, mat.ambientColor, isFullbright, texture, modelTransform.func_225615_b_());
|
Pair<BakedQuad, Direction> quad = makeQuad(face, tintIndex, colorTint, mat.ambientColor, texture, modelTransform.func_225615_b_());
|
||||||
if (quad.getRight() == null)
|
if (quad.getRight() == null)
|
||||||
modelBuilder.addGeneralQuad(quad.getLeft());
|
modelBuilder.addGeneralQuad(quad.getLeft());
|
||||||
else
|
else
|
||||||
|
@ -543,11 +552,6 @@ public class OBJModel implements IMultipartModelGeometry<OBJModel>
|
||||||
{
|
{
|
||||||
return meshes.stream().map(mesh -> ModelLoaderRegistry.resolveTexture(mesh.mat.diffuseColorMap, owner)).collect(Collectors.toSet());
|
return meshes.stream().map(mesh -> ModelLoaderRegistry.resolveTexture(mesh.mat.diffuseColorMap, owner)).collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasAnyFullBright()
|
|
||||||
{
|
|
||||||
return meshes.stream().anyMatch(ModelMesh::isFullbright);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ModelGroup extends ModelObject
|
public class ModelGroup extends ModelObject
|
||||||
|
@ -582,12 +586,6 @@ public class OBJModel implements IMultipartModelGeometry<OBJModel>
|
||||||
combined.addAll(part.getTextures(owner, modelGetter, missingTextureErrors));
|
combined.addAll(part.getTextures(owner, modelGetter, missingTextureErrors));
|
||||||
return combined;
|
return combined;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasAnyFullBright()
|
|
||||||
{
|
|
||||||
return super.hasAnyFullBright() || parts.values().stream().anyMatch(ModelObject::hasAnyFullBright);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ModelMesh
|
private class ModelMesh
|
||||||
|
@ -603,11 +601,6 @@ public class OBJModel implements IMultipartModelGeometry<OBJModel>
|
||||||
this.mat = currentMat;
|
this.mat = currentMat;
|
||||||
this.smoothingGroup = currentSmoothingGroup;
|
this.smoothingGroup = currentSmoothingGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isFullbright()
|
|
||||||
{
|
|
||||||
return mat != null && TransformationHelper.epsilonEquals(mat.ambientColor, new Vector4f(1,1,1,1), 1/256f);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ModelSettings
|
public static class ModelSettings
|
||||||
|
|
|
@ -24,6 +24,8 @@ import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.FourWayBlock;
|
import net.minecraft.block.FourWayBlock;
|
||||||
import net.minecraft.block.material.Material;
|
import net.minecraft.block.material.Material;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.renderer.RenderType;
|
||||||
|
import net.minecraft.client.renderer.RenderTypeLookup;
|
||||||
import net.minecraft.client.renderer.model.ItemCameraTransforms;
|
import net.minecraft.client.renderer.model.ItemCameraTransforms;
|
||||||
import net.minecraft.client.renderer.texture.AtlasTexture;
|
import net.minecraft.client.renderer.texture.AtlasTexture;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
|
@ -32,6 +34,10 @@ import net.minecraft.item.*;
|
||||||
import net.minecraft.state.StateContainer;
|
import net.minecraft.state.StateContainer;
|
||||||
import net.minecraft.state.properties.BlockStateProperties;
|
import net.minecraft.state.properties.BlockStateProperties;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.shapes.ISelectionContext;
|
||||||
|
import net.minecraft.util.math.shapes.VoxelShape;
|
||||||
|
import net.minecraft.world.IBlockReader;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
||||||
import net.minecraftforge.client.model.ModelLoader;
|
import net.minecraftforge.client.model.ModelLoader;
|
||||||
|
@ -42,6 +48,7 @@ import net.minecraftforge.common.util.NonNullLazy;
|
||||||
import net.minecraftforge.eventbus.api.IEventBus;
|
import net.minecraftforge.eventbus.api.IEventBus;
|
||||||
import net.minecraftforge.fml.RegistryObject;
|
import net.minecraftforge.fml.RegistryObject;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||||
import net.minecraftforge.registries.DeferredRegister;
|
import net.minecraftforge.registries.DeferredRegister;
|
||||||
import net.minecraftforge.registries.ForgeRegistries;
|
import net.minecraftforge.registries.ForgeRegistries;
|
||||||
|
@ -71,6 +78,12 @@ public class NewModelLoaderTest
|
||||||
BlockStateProperties.HORIZONTAL_FACING, context.getPlacementHorizontalFacing()
|
BlockStateProperties.HORIZONTAL_FACING, context.getPlacementHorizontalFacing()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context)
|
||||||
|
{
|
||||||
|
return Block.makeCuboidShape(2,2,2,14,14,14);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,10 @@
|
||||||
{
|
{
|
||||||
"parent": "forge:item/default",
|
"parent": "forge:item/default",
|
||||||
"loader": "forge:composite",
|
"loader": "forge:obj",
|
||||||
"parts": {
|
"model": "new_model_loader_test:models/item/sugar_glider.obj",
|
||||||
"part1": {
|
"ambientToFullbright": true,
|
||||||
"loader": "forge:obj",
|
|
||||||
"model": "new_model_loader_test:models/item/sugar_glider.obj",
|
|
||||||
"ambientToFullbright": true,
|
|
||||||
"textures": {
|
|
||||||
"qr": "minecraft:block/oak_planks"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"textures": {
|
"textures": {
|
||||||
|
"qr": "minecraft:block/oak_planks",
|
||||||
"particle": "block/oak_planks"
|
"particle": "block/oak_planks"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
newmtl None
|
newmtl None
|
||||||
Ns 0
|
Ns 0
|
||||||
Ka 1.0000 1.0000 1.0000
|
Ka 0 0 0
|
||||||
Kd 0.8 0.8 0.8
|
Kd 0.8 0.8 0.8
|
||||||
Ks 0.8 0.8 0.8
|
Ks 0.8 0.8 0.8
|
||||||
d 1
|
d 1
|
||||||
illum 2
|
illum 2
|
||||||
|
map_Kd minecraft:block/coal_ore
|
|
@ -1,16 +1,5 @@
|
||||||
{
|
{
|
||||||
"parent": "forge:item/default",
|
"parent": "new_model_loader_test:block/obj_block",
|
||||||
"loader": "forge:composite",
|
|
||||||
"parts": {
|
|
||||||
"part1": {
|
|
||||||
"loader": "forge:obj",
|
|
||||||
"model": "new_model_loader_test:models/item/sugar_glider.obj",
|
|
||||||
"ambientToFullbright": true,
|
|
||||||
"textures": {
|
|
||||||
"qr": "new_model_loader_test:item/qr"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"textures": {
|
"textures": {
|
||||||
"particle": "block/oak_planks"
|
"particle": "block/oak_planks"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# Rhino
|
# Rhino
|
||||||
newmtl New material 001 (1)
|
newmtl New material 001 (1)
|
||||||
Ka 0.0000 0.0000 0.0000
|
Ka 0.5 0.5 0.5
|
||||||
Kd 0.4588 0.3333 0.1882
|
Kd 0.4588 0.3333 0.1882
|
||||||
Ks 1.0000 1.0000 1.0000
|
Ks 1.0000 1.0000 1.0000
|
||||||
Tf 0.0000 0.0000 0.0000
|
Tf 0.0000 0.0000 0.0000
|
||||||
|
@ -9,7 +9,7 @@ Ns 0
|
||||||
map_Kd #qr
|
map_Kd #qr
|
||||||
|
|
||||||
newmtl New material 001
|
newmtl New material 001
|
||||||
Ka 0.0000 0.0000 0.0000
|
Ka 0.5 0.5 0.5
|
||||||
Kd 0.6745 0.5216 0.3412
|
Kd 0.6745 0.5216 0.3412
|
||||||
Ks 1.0000 1.0000 1.0000
|
Ks 1.0000 1.0000 1.0000
|
||||||
Tf 0.0000 0.0000 0.0000
|
Tf 0.0000 0.0000 0.0000
|
||||||
|
@ -18,7 +18,7 @@ Ns 0
|
||||||
map_Kd #qr
|
map_Kd #qr
|
||||||
|
|
||||||
newmtl Default
|
newmtl Default
|
||||||
Ka 0.0000 0.0000 0.0000
|
Ka 0.5 0.5 0.5
|
||||||
Kd 1.0000 1.0000 1.0000
|
Kd 1.0000 1.0000 1.0000
|
||||||
Ks 1.0000 1.0000 1.0000
|
Ks 1.0000 1.0000 1.0000
|
||||||
Tf 0.0000 0.0000 0.0000
|
Tf 0.0000 0.0000 0.0000
|
||||||
|
@ -27,7 +27,7 @@ Ns 0
|
||||||
map_Kd #qr
|
map_Kd #qr
|
||||||
|
|
||||||
newmtl New material 002
|
newmtl New material 002
|
||||||
Ka 0.0000 0.0000 0.0000
|
Ka 0.5 0.5 0.5
|
||||||
Kd 0.4118 0.4118 0.4118
|
Kd 0.4118 0.4118 0.4118
|
||||||
Ks 1.0000 1.0000 1.0000
|
Ks 1.0000 1.0000 1.0000
|
||||||
Tf 0.0000 0.0000 0.0000
|
Tf 0.0000 0.0000 0.0000
|
||||||
|
@ -36,7 +36,7 @@ Ns 0
|
||||||
map_Kd #qr
|
map_Kd #qr
|
||||||
|
|
||||||
newmtl New material 003
|
newmtl New material 003
|
||||||
Ka 0.0000 0.0000 0.0000
|
Ka 0.5 0.5 0.5
|
||||||
Kd 0.1490 0.1490 0.1490
|
Kd 0.1490 0.1490 0.1490
|
||||||
Ks 1.0000 1.0000 1.0000
|
Ks 1.0000 1.0000 1.0000
|
||||||
Tf 0.0000 0.0000 0.0000
|
Tf 0.0000 0.0000 0.0000
|
||||||
|
|
Loading…
Reference in a new issue