public unsafe bool UpdateSimpleMaterialBGFX(RendererBGFXInstance *sys, ref SimpleMaterial mat, ref SimpleMaterialBGFX matBGFX, bool srgbColors) { // if constants changed, need to update packed value matBGFX.constAlbedo_Opacity = srgbColors ? new float4(Color.LinearToSRGB(mat.constAlbedo), mat.constOpacity) : new float4(mat.constAlbedo, mat.constOpacity); // if texture entity OR load state changed need to update texture handles // content of texture change should transparently update texture referenced by handle bool stillLoading = false; if (InitTexture(ref matBGFX.texAlbedoOpacity, mat.texAlbedoOpacity, sys->m_whiteTexture)) { stillLoading = true; } // if twoSided or hasalpha changed, need to update state matBGFX.state = (ulong)(bgfx.StateFlags.WriteRgb | bgfx.StateFlags.WriteA | bgfx.StateFlags.DepthTestLess); if (!mat.twoSided && !mat.billboarded) { matBGFX.state |= (ulong)bgfx.StateFlags.CullCw; } if (mat.transparent) { matBGFX.state |= RendererBGFXStatic.MakeBGFXBlend(bgfx.StateFlags.BlendOne, bgfx.StateFlags.BlendInvSrcAlpha); } else { matBGFX.state |= (ulong)bgfx.StateFlags.WriteZ; } matBGFX.mainTextureScaleTranslate = new float4(mat.scale, mat.offset); matBGFX.billboarded = new float4(mat.billboarded ? 1 : 0, 0, 0, 0); return(!stillLoading); }
public bool UpdateSimpleMaterialBGFX(RendererBGFXSystem sys, ref SimpleMaterial mat, ref SimpleMaterialBGFX matBGFX) { // if constants changed, need to update packed value matBGFX.constAlbedo_Opacity = new float4(mat.constAlbedo, mat.constOpacity); // if texture entity OR load state changed need to update texture handles // content of texture change should transparently update texture referenced by handle bool stillLoading = false; if (InitTexture(ref matBGFX.texAlbedo, mat.texAlbedo, sys.WhiteTexture)) { stillLoading = true; } if (InitTexture(ref matBGFX.texOpacity, mat.texOpacity, sys.WhiteTexture)) { stillLoading = true; } // if twoSided or hasalpha changed, need to update state matBGFX.state = (ulong)(bgfx.StateFlags.WriteRgb | bgfx.StateFlags.WriteA | bgfx.StateFlags.DepthTestLess); if (!mat.twoSided) { matBGFX.state |= (ulong)bgfx.StateFlags.CullCw; } if (mat.transparent) { matBGFX.state |= RendererBGFXSystem.MakeBGFXBlend(bgfx.StateFlags.BlendOne, bgfx.StateFlags.BlendInvSrcAlpha); } else { matBGFX.state |= (ulong)bgfx.StateFlags.WriteZ; } matBGFX.mainTextureScaleTranslate = new float4(mat.scale, mat.offset); return(!stillLoading); }