Lighting.java
com.mojang.blaze3d.platform.Lighting
信息
- 全限定名:com.mojang.blaze3d.platform.Lighting
- 类型:public class
- 包:com.mojang.blaze3d.platform
- 源码路径:src/main/java/com/mojang/blaze3d/platform/Lighting.java
- 起始行号:L18
- 实现:AutoCloseable
- 职责:
TODO
字段/常量
-
DIFFUSE_LIGHT_0- 类型:
Vector3f - 修饰符:
private static final - 源码定位:
L19 - 说明:
TODO
- 类型:
-
DIFFUSE_LIGHT_1- 类型:
Vector3f - 修饰符:
private static final - 源码定位:
L20 - 说明:
TODO
- 类型:
-
NETHER_DIFFUSE_LIGHT_0- 类型:
Vector3f - 修饰符:
private static final - 源码定位:
L21 - 说明:
TODO
- 类型:
-
NETHER_DIFFUSE_LIGHT_1- 类型:
Vector3f - 修饰符:
private static final - 源码定位:
L22 - 说明:
TODO
- 类型:
-
INVENTORY_DIFFUSE_LIGHT_0- 类型:
Vector3f - 修饰符:
private static final - 源码定位:
L23 - 说明:
TODO
- 类型:
-
INVENTORY_DIFFUSE_LIGHT_1- 类型:
Vector3f - 修饰符:
private static final - 源码定位:
L24 - 说明:
TODO
- 类型:
-
UBO_SIZE- 类型:
int - 修饰符:
public static final - 源码定位:
L25 - 说明:
TODO
- 类型:
-
buffer- 类型:
GpuBuffer - 修饰符:
private final - 源码定位:
L26 - 说明:
TODO
- 类型:
-
paddedSize- 类型:
long - 修饰符:
private final - 源码定位:
L27 - 说明:
TODO
- 类型:
内部类/嵌套类型
com.mojang.blaze3d.platform.Lighting.Entry- 类型:
enum - 修饰符:
public static - 源码定位:
L84 - 说明:
TODO
- 类型:
构造器
public Lighting() @ L29
- 构造器名:Lighting
- 源码定位:L29
- 修饰符:public
参数:
- 无
说明:
TODO
方法
下面的方法块按源码顺序生成。
public void updateLevel(CardinalLighting.Type type) @ L57
- 方法名:updateLevel
- 源码定位:L57
- 返回类型:void
- 修饰符:public
参数:
- type: CardinalLighting.Type
说明:
TODO
private void updateBuffer(Lighting.Entry entry, Vector3f light0, Vector3f light1) @ L67
- 方法名:updateBuffer
- 源码定位:L67
- 返回类型:void
- 修饰符:private
参数:
- entry: Lighting.Entry
- light0: Vector3f
- light1: Vector3f
说明:
TODO
public void setupFor(Lighting.Entry entry) @ L74
- 方法名:setupFor
- 源码定位:L74
- 返回类型:void
- 修饰符:public
参数:
- entry: Lighting.Entry
说明:
TODO
public void close() @ L78
- 方法名:close
- 源码定位:L78
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class Lighting implements AutoCloseable {
private static final Vector3f DIFFUSE_LIGHT_0 = new Vector3f(0.2F, 1.0F, -0.7F).normalize();
private static final Vector3f DIFFUSE_LIGHT_1 = new Vector3f(-0.2F, 1.0F, 0.7F).normalize();
private static final Vector3f NETHER_DIFFUSE_LIGHT_0 = new Vector3f(0.2F, 1.0F, -0.7F).normalize();
private static final Vector3f NETHER_DIFFUSE_LIGHT_1 = new Vector3f(-0.2F, -1.0F, 0.7F).normalize();
private static final Vector3f INVENTORY_DIFFUSE_LIGHT_0 = new Vector3f(0.2F, -1.0F, 1.0F).normalize();
private static final Vector3f INVENTORY_DIFFUSE_LIGHT_1 = new Vector3f(-0.2F, -1.0F, 0.0F).normalize();
public static final int UBO_SIZE = new Std140SizeCalculator().putVec3().putVec3().get();
private final GpuBuffer buffer;
private final long paddedSize;
public Lighting() {
GpuDevice device = RenderSystem.getDevice();
this.paddedSize = Mth.roundToward(UBO_SIZE, device.getUniformOffsetAlignment());
this.buffer = device.createBuffer(() -> "Lighting UBO", 136, this.paddedSize * Lighting.Entry.values().length);
Matrix4f flatPose = new Matrix4f().rotationY((float) (-Math.PI / 8)).rotateX((float) (Math.PI * 3.0 / 4.0));
this.updateBuffer(
Lighting.Entry.ITEMS_FLAT,
flatPose.transformDirection(DIFFUSE_LIGHT_0, new Vector3f()),
flatPose.transformDirection(DIFFUSE_LIGHT_1, new Vector3f())
);
Matrix4f item3DPose = new Matrix4f()
.scaling(1.0F, -1.0F, 1.0F)
.rotateYXZ(1.0821041F, 3.2375858F, 0.0F)
.rotateYXZ((float) (-Math.PI / 8), (float) (Math.PI * 3.0 / 4.0), 0.0F);
this.updateBuffer(
Lighting.Entry.ITEMS_3D,
item3DPose.transformDirection(DIFFUSE_LIGHT_0, new Vector3f()),
item3DPose.transformDirection(DIFFUSE_LIGHT_1, new Vector3f())
);
this.updateBuffer(Lighting.Entry.ENTITY_IN_UI, INVENTORY_DIFFUSE_LIGHT_0, INVENTORY_DIFFUSE_LIGHT_1);
Matrix4f playerSkinPose = new Matrix4f();
this.updateBuffer(
Lighting.Entry.PLAYER_SKIN,
playerSkinPose.transformDirection(INVENTORY_DIFFUSE_LIGHT_0, new Vector3f()),
playerSkinPose.transformDirection(INVENTORY_DIFFUSE_LIGHT_1, new Vector3f())
);
}
public void updateLevel(CardinalLighting.Type type) {
switch (type) {
case DEFAULT:
this.updateBuffer(Lighting.Entry.LEVEL, DIFFUSE_LIGHT_0, DIFFUSE_LIGHT_1);
break;
case NETHER:
this.updateBuffer(Lighting.Entry.LEVEL, NETHER_DIFFUSE_LIGHT_0, NETHER_DIFFUSE_LIGHT_1);
}
}
private void updateBuffer(Lighting.Entry entry, Vector3f light0, Vector3f light1) {
try (MemoryStack stack = MemoryStack.stackPush()) {
ByteBuffer byteBuffer = Std140Builder.onStack(stack, UBO_SIZE).putVec3(light0).putVec3(light1).get();
RenderSystem.getDevice().createCommandEncoder().writeToBuffer(this.buffer.slice(entry.ordinal() * this.paddedSize, this.paddedSize), byteBuffer);
}
}
public void setupFor(Lighting.Entry entry) {
RenderSystem.setShaderLights(this.buffer.slice(entry.ordinal() * this.paddedSize, UBO_SIZE));
}
@Override
public void close() {
this.buffer.close();
}
@OnlyIn(Dist.CLIENT)
public static enum Entry {
LEVEL,
ITEMS_FLAT,
ITEMS_3D,
ENTITY_IN_UI,
PLAYER_SKIN;
}
}引用的其他类
-
- 引用位置:
字段
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Std140Builder.onStack()
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
Std140SizeCalculator()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
RenderSystem.getDevice(), RenderSystem.setShaderLights()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Mth.roundToward()
- 引用位置:
-
- 引用位置:
参数
- 引用位置: