-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rough in some bits for unified materials
- Loading branch information
Showing
12 changed files
with
211 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
package grondag.canvas.shader; | ||
|
||
// WIP: remove | ||
@Deprecated | ||
public enum ShaderPass { | ||
SOLID, | ||
DECAL, | ||
|
25 changes: 25 additions & 0 deletions
25
src/main/java/grondag/canvas/shader/wip/MaterialBufferKey.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package grondag.canvas.shader.wip; | ||
|
||
import grondag.canvas.buffer.encoding.VertexEncoder; | ||
import grondag.canvas.material.MaterialVertexFormat; | ||
|
||
/** | ||
* Primitives with the same buffer key can share the same buffer. | ||
* They should share the same encoder/vertex format, same and have the same sorting requirements. | ||
* | ||
* Content of the buffer should also share the same matrix state but this is | ||
* not enforced and must be controlled through appropriate usage. | ||
* | ||
*/ | ||
public class MaterialBufferKey { | ||
public final MaterialVertexFormat format; | ||
public final VertexEncoder encoder; | ||
/** true only for translucent */ | ||
public final boolean sorted; | ||
|
||
private MaterialBufferKey(VertexEncoder encoder, MaterialVertexFormat format, boolean sorted) { | ||
this.format = format; | ||
this.encoder = encoder; | ||
this.sorted = sorted; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/grondag/canvas/shader/wip/MaterialDrawState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package grondag.canvas.shader.wip; | ||
|
||
/** | ||
* Primitives with the same DrawState have the same vertex format/buffer, | ||
* and same uniform state and gl state. | ||
* | ||
* Primitives with draw states will be collected in different arrays | ||
* and then packed into shared buffers (if applicable) with the same buffer key. | ||
* | ||
* Order of packing will be a hierarchy of Gl state and uniform state | ||
*/ | ||
public class MaterialDrawState { | ||
public final MaterialBufferKey bufferKey; | ||
public final MaterialGlState drawState; | ||
public final MaterialUniformState uniformState; | ||
|
||
private MaterialDrawState(MaterialBufferKey bufferKey, MaterialGlState drawState, MaterialUniformState uniformState) { | ||
this.bufferKey = bufferKey; | ||
this.drawState = drawState; | ||
this.uniformState = uniformState; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/grondag/canvas/shader/wip/MaterialGlState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package grondag.canvas.shader.wip; | ||
|
||
|
||
public class MaterialGlState { | ||
|
||
public static class Builder { | ||
// WIP: texture binding | ||
// WIP: transparency | ||
// WIP: depth test | ||
// WIP: cull | ||
// WIP: enable lightmap | ||
|
||
private boolean sorted = false; | ||
|
||
public Builder sorted(boolean sorted) { | ||
this.sorted = sorted; | ||
return this; | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/grondag/canvas/shader/wip/MaterialUniformState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package grondag.canvas.shader.wip; | ||
|
||
public class MaterialUniformState { | ||
|
||
} |
115 changes: 115 additions & 0 deletions
115
src/main/java/grondag/canvas/shader/wip/MaterialVertexState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package grondag.canvas.shader.wip; | ||
|
||
import grondag.canvas.apiimpl.MaterialConditionImpl; | ||
import grondag.fermion.bits.BitPacker32; | ||
import grondag.fermion.bits.BitPacker32.BooleanElement; | ||
import grondag.fermion.bits.BitPacker32.IntElement; | ||
|
||
/** | ||
* Encapsulates material state conveyed via vertex attributes | ||
*/ | ||
@SuppressWarnings("rawtypes") | ||
public class MaterialVertexState { | ||
public final boolean emissive; | ||
public final boolean disableDiffuse; | ||
public final boolean disableAo; | ||
public final boolean cutout; | ||
public final boolean unmipped; | ||
public final MaterialConditionImpl condition; | ||
public final int bits; | ||
|
||
// WIP: flat? (equivalent of shadeModel - need to look at how it is used) | ||
// WIP: cutout threshold: 10% or 50% | ||
|
||
private MaterialVertexState(int bits) { | ||
this.bits = bits; | ||
emissive = EMISSIVE.getValue(bits); | ||
disableDiffuse = DISABLE_DIFFUSE.getValue(bits); | ||
disableAo = DISABLE_AO.getValue(bits); | ||
cutout = CUTOUT.getValue(bits); | ||
unmipped = UNMIPPED.getValue(bits); | ||
condition = MaterialConditionImpl.fromIndex(CONDITION.getValue(bits)); | ||
} | ||
|
||
private static final BitPacker32 PACKER = new BitPacker32<>(null, null); | ||
// these 8 correspond to shader flag bits | ||
private static final BooleanElement EMISSIVE = PACKER.createBooleanElement(); | ||
private static final BooleanElement DISABLE_DIFFUSE = PACKER.createBooleanElement(); | ||
private static final BooleanElement DISABLE_AO = PACKER.createBooleanElement(); | ||
private static final BooleanElement CUTOUT = PACKER.createBooleanElement(); | ||
private static final BooleanElement UNMIPPED = PACKER.createBooleanElement(); | ||
@SuppressWarnings("unused") | ||
private static final BooleanElement RESERVED_5 = PACKER.createBooleanElement(); | ||
@SuppressWarnings("unused") | ||
private static final BooleanElement RESERVED_6 = PACKER.createBooleanElement(); | ||
@SuppressWarnings("unused") | ||
private static final BooleanElement RESERVED_7 = PACKER.createBooleanElement(); | ||
|
||
private static final IntElement CONDITION = PACKER.createIntElement(MaterialConditionImpl.MAX_CONDITIONS); | ||
|
||
public static final int STATE_COUNT = 1 << PACKER.bitLength(); | ||
private static final MaterialVertexState[] STATES = new MaterialVertexState[1 << PACKER.bitLength()]; | ||
|
||
static { | ||
assert MaterialConditionImpl.ALWAYS.index == 0; | ||
|
||
for (int i = 0; i < STATE_COUNT; ++i) { | ||
STATES[i] = new MaterialVertexState(i); | ||
} | ||
} | ||
|
||
public static MaterialVertexState fromBits(int bits) { | ||
return STATES[bits]; | ||
} | ||
|
||
public static class Finder { | ||
private int bits = 0; | ||
|
||
public Finder() { | ||
reset(); | ||
} | ||
|
||
public Finder reset() { | ||
bits = 0; | ||
return this; | ||
} | ||
|
||
public Finder emissive(boolean emissive) { | ||
bits = EMISSIVE.setValue(emissive, bits); | ||
return this; | ||
} | ||
|
||
public Finder disableDiffuse(boolean disableDiffuse) { | ||
bits = DISABLE_DIFFUSE.setValue(disableDiffuse, bits); | ||
return this; | ||
} | ||
|
||
public Finder disableAo(boolean disableAo) { | ||
bits = DISABLE_AO.setValue(disableAo, bits); | ||
return this; | ||
} | ||
|
||
public Finder cutout(boolean cutout) { | ||
bits = CUTOUT.setValue(cutout, bits); | ||
return this; | ||
} | ||
|
||
public Finder unmipped(boolean unmipped) { | ||
bits = UNMIPPED.setValue(unmipped, bits); | ||
return this; | ||
} | ||
|
||
public Finder condition(MaterialConditionImpl condition) { | ||
bits = CONDITION.setValue(condition.index, bits); | ||
return this; | ||
} | ||
|
||
public int findBits() { | ||
return bits; | ||
} | ||
|
||
public MaterialVertexState find() { | ||
return STATES[bits]; | ||
} | ||
} | ||
} |