internal static MyMaterialProxy Create(MyMaterialDescription?desc, string materialTag) { int key = desc.HasValue ? desc.Value.CalculateKey() : 0; key = MyHashHelper.Combine(key, materialTag.GetHashCode()); var proxy = m_proxies.SetDefault(key, null); if (proxy != null) { return(proxy); } proxy = MyShaderMaterialReflection.CreateBindings(materialTag); if (desc == null) { // TODO: change later desc = MyAssetMesh.GetDebugMaterialDescriptor(); } LoadTextures(proxy, desc.Value); proxy.RecalcConstantsHash(); m_proxies[key] = proxy; m_descriptors[key] = desc.Value; m_reverseMapping[proxy] = desc.Value; return(proxy); }
internal static MyMaterialProxy GetBindings(int i0, int i1, int i2) { var key = Tuple.Create(i0, i1, i2); MyMaterialProxy bindings; if (m_cachedBindings.TryGetValue(key, out bindings)) { return(bindings); } bool isSingleMaterial = i1 == -1 && i2 == -1; var material0 = m_materials[i0]; if (isSingleMaterial) { bindings = MyShaderMaterialReflection.CreateBindings(MyVoxelMesh.SINGLE_MATERIAL_TAG); bindings.SetFloat("highfreq_scale", material0.HighFreqScale); bindings.SetFloat("lowfreq_scale", material0.LowFreqScale); bindings.SetFloat("transition_range", material0.TransitionRange); bindings.SetFloat("mask", material0.HasFoliage ? 1 : 0); bindings.SetTexture("ColorMetal_XZnY_pY", material0.ColorMetalArray.ShaderView); bindings.SetTexture("NormalGloss_XZnY_pY", material0.NormalGlossArray.ShaderView); bindings.SetTexture("Ext_XZnY_pY", material0.ExtArray.ShaderView); } else { bindings = MyShaderMaterialReflection.CreateBindings(MyVoxelMesh.MULTI_MATERIAL_TAG); bindings.SetFloat4("material_factors[0]", new Vector4(material0.HighFreqScale, material0.LowFreqScale, material0.TransitionRange, material0.HasFoliage ? 1 : 0)); bindings.SetTexture("ColorMetal_XZnY_pY[0]", material0.ColorMetalArray.ShaderView); bindings.SetTexture("NormalGloss_XZnY_pY[0]", material0.NormalGlossArray.ShaderView); bindings.SetTexture("Ext_XZnY_pY[0]", material0.ExtArray.ShaderView); var material1 = m_materials[i1]; bindings.SetFloat4("material_factors[1]", new Vector4(material1.HighFreqScale, material1.LowFreqScale, material1.TransitionRange, material1.HasFoliage ? 1 : 0)); bindings.SetTexture("ColorMetal_XZnY_pY[1]", material1.ColorMetalArray.ShaderView); bindings.SetTexture("NormalGloss_XZnY_pY[1]", material1.NormalGlossArray.ShaderView); bindings.SetTexture("Ext_XZnY_pY[1]", material1.ExtArray.ShaderView); if (i2 != -1) { var material2 = m_materials[i2]; bindings.SetFloat4("material_factors[2]", new Vector4(material2.HighFreqScale, material2.LowFreqScale, material2.TransitionRange, material2.HasFoliage ? 1 : 0)); bindings.SetTexture("ColorMetal_XZnY_pY[2]", material2.ColorMetalArray.ShaderView); bindings.SetTexture("NormalGloss_XZnY_pY[2]", material2.NormalGlossArray.ShaderView); bindings.SetTexture("Ext_XZnY_pY[2]", material2.ExtArray.ShaderView); } } bindings.RecalcConstantsHash(); bindings.RecalcTexturesHash(); m_cachedBindings[key] = bindings; return(bindings); }
internal MyMaterialProxy(MyShaderMaterialReflection materialReflection) { m_reflection = materialReflection; SRVs = new ShaderResourceView[m_reflection.m_textureSlotsNum]; if (m_reflection.m_cbuffer != null) { Constants = Enumerable.Repeat <byte>(0, m_reflection.m_constantsSize).ToArray(); ConstantsBuffer = m_reflection.m_cbuffer.Buffer; } }
internal MyMaterialProxy(MyShaderMaterialReflection materialReflection) { m_reflection = materialReflection; SRVs = new ShaderResourceView[m_reflection.m_textureSlotsNum]; if (m_reflection.m_cbuffer != null) { Constants = Enumerable.Repeat<byte>(0, m_reflection.m_constantsSize).ToArray(); ConstantsBuffer = m_reflection.m_cbuffer.Buffer; } }