@@ -16,6 +16,7 @@ import gg.generations.rarecandy.renderer.animation.AnimationController
1616import gg.generations.rarecandy.renderer.animation.Transform
1717import gg.generations.rarecandy.renderer.loading.ITexture
1818import gg.generations.rarecandy.renderer.model.material.Material
19+ import gg.generations.rarecandy.renderer.model.material.MaterialValues
1920import gg.generations.rarecandy.renderer.model.material.PipelineRegistry
2021import gg.generations.rarecandy.renderer.pipeline.Pipeline
2122import gg.generations.rarecandy.renderer.pipeline.UniformUploadContext
@@ -39,6 +40,8 @@ object Pipelines {
3940 )
4041 )
4142 private val ONE = Vector3f (1f , 1f , 1f )
43+ private val ZERO = Vector3f (0f , 0f , 0f )
44+
4245
4346 @JvmField
4447 var REGISTER : Event <Consumer <PipelineRegister >> = EventFactory .createConsumerLoop(
@@ -85,7 +88,7 @@ object Pipelines {
8588 val builder = Pipeline .Builder ()
8689 .supplyUniform(
8790 " viewMatrix"
88- ) { ctx: UniformUploadContext -> ctx.uniform().uploadMat4f(ctx.instance().viewMatrix ()) }
91+ ) { ctx -> ctx.uniform().uploadMat4f(RenderSystem .getModelViewMatrix ()) }
8992 .supplyFloatUniform(" FogStart" ) { RenderSystem .getShaderFogStart() }
9093 .supplyFloatUniform(" FogEnd" ) { RenderSystem .getShaderFogEnd() }
9194 .supplyColorArray(" FogColor" ) { RenderSystem .getShaderFogColor() }
@@ -97,7 +100,7 @@ object Pipelines {
97100 .supplyVec2(" uvOffset" ) { it.transform.offset() ? : Transform .DEFAULT_OFFSET }
98101 .supplyVec2(" uvScale" ) { it.transform.scale() ? : Transform .DEFAULT_SCALE }
99102 .supplyTexture(" diffuse" , 0 ) {
100- it.getTextureOrOther(" diffuse" ) { ITextureLoader .instance().nuetralFallback }
103+ it.getTextureOrOther({ it.material.images(). diffuse } ) { ITextureLoader .instance().nuetralFallback }
101104 }
102105 .configure(::addLight)
103106 .supplyVec3(" Light0_Direction" ) {
@@ -106,7 +109,7 @@ object Pipelines {
106109 .supplyVec3(" Light1_Direction" ) {
107110 RenderSystem .shaderLightDirections[1 ]
108111 }
109- .supplyVec3(" cobblemonTint" ) { it.instance.instanceOrNull<CobblemonInstance >()?.tint ? : ONE }
112+ .supplyVec3(" cobblemonTint" ) { it.instance.instanceOrNull<CobblemonInstance >()?.tint?. takeIf { it != ZERO } ? : ONE }
110113 .prePostDraw({ material: Material ->
111114 if (material.cullType() != CullType .None ) {
112115 RenderSystem .enableCull()
@@ -178,10 +181,12 @@ object Pipelines {
178181 .configure(::baseColors)
179182 .configure(::emissionColors)
180183 .supplyTexture(" layer" , 3 ) {
181- ctx -> ctx.getTexture(" layer" ).takeIf { ! ctx.isStatueMaterial } ? : ITextureLoader .instance().darkFallback
184+ it.getTextureOrOther({ it.material.images().layer}) {
185+ ITextureLoader .instance().darkFallback
186+ }
182187 }
183188 .supplyTexture(" mask" , 4 ) {
184- it.getTextureOrOther(" mask" ) {
189+ it.getTextureOrOther({ it.material.images(). mask} ) {
185190 ITextureLoader .instance().darkFallback
186191 }
187192 }
@@ -190,12 +195,10 @@ object Pipelines {
190195 private fun Pipeline.Builder.masked (): Pipeline .Builder {
191196 return this
192197 .supplyTexture(" mask" , 3 ) {
193- it.getTextureOrOther(" mask" ) { ITextureLoader .instance().darkFallback }
198+ it.getTextureOrOther({ it.material.images(). mask } ) { ITextureLoader .instance().darkFallback }
194199 }
195200 .supplyVec3(" color" ) {
196- var color = it.instance.instanceOrNull<TintProvider >()?.getTint() ? : it.getColorValue(" color" )
197-
198-
201+ var color = it.instance.instanceOrNull<TintProvider >()?.getTint() ? : it.material.values().baseColor1
199202 color
200203 }
201204 }
@@ -220,65 +223,32 @@ object Pipelines {
220223 }
221224
222225 private fun emissionColors (builder : Pipeline .Builder ) = builder
223- .supplyVec3(" emiColor1" ) {
224- it.getColorValue(" emiColor1" )
225- }
226- .supplyVec3(" emiColor2" ) {
227- it.getColorValue(" emiColor2" )
228- }
229- .supplyVec3(" emiColor3" ) {
230- it.getColorValue(" emiColor3" )
231- }
232- .supplyVec3(" emiColor4" ) {
233- it.getColorValue(" emiColor4" )
234- }
226+ .supplyVec3(" emiColor1" ) { it.takeIf { ! it.isStatueMaterial }?.material?.values()?.emiColor1 ? : ONE }
227+ .supplyVec3(" emiColor2" ) { it.takeIf { ! it.isStatueMaterial }?.material?.values()?.emiColor2 ? : ONE }
228+ .supplyVec3(" emiColor3" ) { it.takeIf { ! it.isStatueMaterial }?.material?.values()?.emiColor3 ? : ONE }
229+ .supplyVec3(" emiColor4" ) { it.takeIf { ! it.isStatueMaterial }?.material?.values()?.emiColor4 ? : ONE }
235230 .supplyVec3(" emiColor5" ) {
236- it.instance.instanceOrNull<TintProvider >()?.tint ? : it.getColorValue(" emiColor5" )
237- }
238- .supplyFloatUniform(" emiIntensity1" ) {
239- it.getFloatValue(" emiIntensity1" )
240- }
241- .supplyFloatUniform(" emiIntensity2" ) {
242- it.getFloatValue(" emiIntensity2" )
243- }
244- .supplyFloatUniform(" emiIntensity3" ) {
245- it.getFloatValue(" emiIntensity3" )
246- }
247- .supplyFloatUniform(" emiIntensity4" ) {
248- it.getFloatValue(" emiIntensity4" )
249- }
250- .supplyFloatUniform(" emiIntensity5" ) {
251- it.getFloatValue(" emiIntensity5" , 1.0f )
231+ it.instance.instanceOrNull<TintProvider >()?.tint ? : it.material.values().emiColor5
252232 }
233+ .supplyFloatUniform(" emiIntensity1" ) { it.takeIf { ! it.isStatueMaterial }?.material?.values()?.emiIntensity1 ? : 0.0f }
234+ .supplyFloatUniform(" emiIntensity2" ) { it.takeIf { ! it.isStatueMaterial }?.material?.values()?.emiIntensity2 ? : 0.0f }
235+ .supplyFloatUniform(" emiIntensity3" ) { it.takeIf { ! it.isStatueMaterial }?.material?.values()?.emiIntensity3 ? : 0.0f }
236+ .supplyFloatUniform(" emiIntensity4" ) { it.takeIf { ! it.isStatueMaterial }?.material?.values()?.emiIntensity4 ? : 0.0f }
237+ .supplyFloatUniform(" emiIntensity5" ) { it.takeIf { ! it.isStatueMaterial }?.material?.values()?.emiIntensity5 ? : 1.0f }
253238
254239
255- private fun baseColors (builder : Pipeline .Builder ) = builder
256- .supplyVec3(" baseColor1" ) {
257- it.getColorValue(" baseColor1" )
258- }
259- .supplyVec3(" baseColor2" ) {
260- it.getColorValue(" baseColor2" )
261- }
262- .supplyVec3(" baseColor3" ) {
263- it.getColorValue(" baseColor3" )
264- }
265- .supplyVec3(" baseColor4" ) {
266- it.getColorValue(" baseColor4" )
267- }
268- .supplyVec3(" baseColor5" ) {
269- it.getColorValue(" baseColor5" )
270- }
271-
272240
273- private fun UniformUploadContext.getColorValue (id : String ): Vector3f {
274- return (if (! this .isStatueMaterial) this .value<Vector3f >(id) else null ) ? : ONE
275- }
276-
277- private fun UniformUploadContext.getFloatValue (id : String , value : Float = 0.0f): Float {
278- return (if (! this .isStatueMaterial) this .value<Float >(id) else null ) ? : value
279- }
241+ private fun baseColors (builder : Pipeline .Builder ) = builder
242+ .supplyVec3(" baseColor1" , { ctx -> ctx.takeIf { ! it.isStatueMaterial }?.material?.values()?.baseColor1 ? : ONE } )
243+ .supplyVec3(" baseColor2" , { ctx -> ctx.takeIf { ! it.isStatueMaterial }?.material?.values()?.baseColor2 ? : ONE } )
244+ .supplyVec3(" baseColor3" , { ctx -> ctx.takeIf { ! it.isStatueMaterial }?.material?.values()?.baseColor3 ? : ONE } )
245+ .supplyVec3(" baseColor4" , { ctx -> ctx.takeIf { ! it.isStatueMaterial }?.material?.values()?.baseColor4 ? : ONE } )
246+ .supplyVec3(" baseColor5" , { ctx -> ctx.takeIf { ! it.isStatueMaterial }?.material?.values()?.baseColor5 ? : ONE } )
280247
281- private fun UniformUploadContext.getTextureOrOther (name : String , function : () -> ITexture ): ITexture = this .getTexture(name)?.takeUnless { texture -> this .isStatueMaterial || texture == = GenerationsTextureLoader .MissingTextureProxy } ? : function.invoke()
248+ private fun UniformUploadContext.getTextureOrOther (
249+ function : (UniformUploadContext ) -> String? ,
250+ supplier : () -> ITexture
251+ ): ITexture = GenerationsTextureLoader .getTexture(function.invoke(this ))?.takeUnless { texture -> this .isStatueMaterial || texture == = GenerationsTextureLoader .MissingTextureProxy } ? : supplier.invoke()
282252
283253 private fun addLight (builder : Pipeline .Builder ) {
284254 builder
@@ -287,8 +257,8 @@ object Pipelines {
287257 val light = (ctx.instance() as BlockLightValueProvider ).light
288258 ctx.uniform().upload2i(light and 0xFFFF , light shr 16 and 0xFFFF )
289259 }
290- .supplyTexture(" emission" , 2 ) { it.getTextureOrOther(" emission" ) { ITextureLoader .instance().darkFallback } }
291- .supplyBooleanUniform(" useLight" ) { it.value< Boolean >( " useLight " ) ? : true }
260+ .supplyTexture(" emission" , 2 ) { it.getTextureOrOther({ it.material.images(). emission } ) { ITextureLoader .instance().darkFallback } }
261+ .supplyBooleanUniform(" useLight" ) { it.material.values().useLight }
292262 }
293263
294264
@@ -381,10 +351,6 @@ private fun Pipeline.Builder.supplyFloatUniform(name: String, function: (Uniform
381351 return this .supplyUniform(name) { it.uniform.uploadFloat(function.invoke(it))}
382352}
383353
384- private inline fun <reified T > UniformUploadContext.value (name : String ): T ? {
385- return this .getValue(name).instanceOrNull<T >()
386- }
387-
388354private fun Pipeline.Builder.supplyEnumUniform (name : String , value : Enum <* >): Pipeline .Builder = this .supplyInt(name) { value.ordinal }
389355
390356private fun Pipeline.Builder.supplyInt (name : String , function : () -> Int ): Pipeline .Builder = this .also { this .supplyUniform(name) { it.uniform.uploadInt(function.invoke()) } }
0 commit comments