private static void SetSamplerInformation(RMaterial material, MatlAttribute a) { var samplerStruct = (MatlAttribute.MatlSampler)a.DataObject; SamplerObject sampler = new SamplerObject { TextureWrapS = MatlToGl.GetWrapMode(samplerStruct.WrapS), TextureWrapT = MatlToGl.GetWrapMode(samplerStruct.WrapT), TextureWrapR = MatlToGl.GetWrapMode(samplerStruct.WrapR), MagFilter = MatlToGl.GetMagFilter(samplerStruct.MagFilter), MinFilter = MatlToGl.GetMinFilter(samplerStruct.MinFilter) }; GL.SamplerParameter(sampler.Id, SamplerParameterName.TextureLodBias, samplerStruct.LodBias); if (samplerStruct.Unk6 == 2 && RenderSettings.Instance.EnableExperimental) { GL.SamplerParameter(sampler.Id, SamplerParameterName.TextureMaxAnisotropyExt, (float)samplerStruct.MaxAnisotropy); } else { GL.SamplerParameter(sampler.Id, SamplerParameterName.TextureMaxAnisotropyExt, 1.0f); } material.samplerByParamId[a.ParamId] = sampler; }
private static void SetBlendState(RMaterial meshMaterial, MatlAttribute a) { var blendState = (MatlAttribute.MatlBlendState)a.DataObject; // TODO: Does "src factor" toggle something in the shader? meshMaterial.BlendSrc = BlendingFactor.One; if (blendState.Unk1 == 0) { meshMaterial.BlendSrc = BlendingFactor.Zero; } if (blendState.BlendFactor2 == 1) { meshMaterial.BlendDst = BlendingFactor.One; } else if (blendState.BlendFactor2 == 2) { meshMaterial.BlendDst = BlendingFactor.SrcAlpha; } else if (blendState.BlendFactor2 == 6) { meshMaterial.BlendDst = BlendingFactor.OneMinusSrcAlpha; } // TODO: Do both need to be set? meshMaterial.UseAlphaSampleCoverage = blendState.Unk7 == 1 || blendState.Unk8 == 1; }
private static void SetTextureParameter(RMaterial meshMaterial, MatlAttribute a) { // Don't make texture names case sensitive. var textureName = ((MatlAttribute.MatlString)a.DataObject).Text.ToLower(); meshMaterial.textureNameByParamId[a.ParamId] = textureName; }
private void SetBlendState(Material meshMaterial, MatlAttribute a) { // TODO: There's a cleaner way to do this. var blendState = (MatlAttribute.MatlBlendState)a.DataObject; if (blendState.BlendFactor1 == 1) { meshMaterial.BlendSrc = OpenTK.Graphics.OpenGL.BlendingFactor.One; } else if (blendState.BlendFactor1 == 6) { meshMaterial.BlendSrc = OpenTK.Graphics.OpenGL.BlendingFactor.SrcAlpha; } if (blendState.BlendFactor2 == 1) { meshMaterial.BlendDst = OpenTK.Graphics.OpenGL.BlendingFactor.One; } else if (blendState.BlendFactor2 == 6) { meshMaterial.BlendDst = OpenTK.Graphics.OpenGL.BlendingFactor.OneMinusSrcAlpha; } meshMaterial.HasAlphaBlending = blendState.BlendFactor1 != 0 || blendState.BlendFactor2 != 0; // TODO: Do both need to be set? meshMaterial.UseStippleBlend = blendState.Unk7 == 1 && blendState.Unk8 == 1; }
private static void SetRasterizerState(RMaterial meshMaterial, MatlAttribute a) { var rasterizerState = (MatlAttribute.MatlRasterizerState)a.DataObject; meshMaterial.DepthBias = rasterizerState.DepthBias; meshMaterial.CullMode = MatlToGl.GetCullMode(rasterizerState.CullMode); }
private void SetSamplerInformation(Material material, MatlAttribute a) { // TODO: Set the appropriate sampler information based on the attribute and param id. var samplerStruct = (MatlAttribute.MtalSampler)a.DataObject; var wrapS = GetWrapMode(samplerStruct.WrapS); var wrapT = GetWrapMode(samplerStruct.WrapT); switch ((long)a.ParamID) { case (long)ParamId.ColSampler: material.col.TextureWrapS = wrapS; material.col.TextureWrapT = wrapT; break; case (long)ParamId.NorSampler: material.nor.TextureWrapS = wrapS; material.nor.TextureWrapT = wrapT; break; case (long)ParamId.PrmSampler: material.prm.TextureWrapS = wrapS; material.prm.TextureWrapT = wrapT; break; case (long)ParamId.EmiSampler: material.emi.TextureWrapS = wrapS; material.emi.TextureWrapT = wrapT; break; } }
private void SetBlendState(Material meshMaterial, MatlAttribute a) { // TODO: There's a cleaner way to do this. var blendState = (MatlAttribute.MatlBlendState)a.DataObject; // TODO: Does "src factor" toggle something in the shader? meshMaterial.BlendSrc = BlendingFactor.One; if (blendState.Unk1 == 0) { meshMaterial.BlendSrc = BlendingFactor.Zero; } if (blendState.BlendFactor2 == 1) { meshMaterial.BlendDst = BlendingFactor.One; } else if (blendState.BlendFactor2 == 2) { meshMaterial.BlendDst = BlendingFactor.SrcAlpha; } else if (blendState.BlendFactor2 == 6) { meshMaterial.BlendDst = BlendingFactor.OneMinusSrcAlpha; } meshMaterial.IsTransparent = blendState.BlendFactor1 != 0 || blendState.BlendFactor2 != 0; // TODO: Do both need to be set? meshMaterial.UseAlphaSampleCoverage = blendState.Unk7 == 1 || blendState.Unk8 == 1; }
private void SetRasterizerState(Material meshMaterial, MatlAttribute a) { // TODO: There's a cleaner way to do this. var rasterizerState = (MatlAttribute.MatlRasterizerState)a.DataObject; meshMaterial.DepthBias = rasterizerState.DepthBias; meshMaterial.CullMode = MatlToGl.GetCullMode(rasterizerState.CullMode); }
private void SetSamplerInformation(Material material, MatlAttribute a) { // TODO: This could be cleaner. SamplerObject sampler = null; switch ((long)a.ParamId) { case (long)ParamId.ColSampler: sampler = material.colSampler; break; case (long)ParamId.NorSampler: sampler = material.norSampler; break; case (long)ParamId.PrmSampler: sampler = material.prmSampler; break; case (long)ParamId.EmiSampler: sampler = material.emiSampler; break; } if (sampler != null) { var samplerStruct = (MatlAttribute.MatlSampler)a.DataObject; sampler.TextureWrapS = MatlToGl.GetWrapMode(samplerStruct.WrapS); sampler.TextureWrapT = MatlToGl.GetWrapMode(samplerStruct.WrapT); sampler.TextureWrapR = MatlToGl.GetWrapMode(samplerStruct.WrapR); sampler.MagFilter = MatlToGl.GetMagFilter(samplerStruct.MagFilter); sampler.MinFilter = MatlToGl.GetMinFilter(samplerStruct.MinFilter); GL.SamplerParameter(sampler.Id, SamplerParameterName.TextureLodBias, samplerStruct.LodBias); if (samplerStruct.Unk6 == 2 && RenderSettings.Instance.EnableExperimental) { GL.SamplerParameter(sampler.Id, SamplerParameterName.TextureMaxAnisotropyExt, (float)samplerStruct.MaxAnisotropy); } else { GL.SamplerParameter(sampler.Id, SamplerParameterName.TextureMaxAnisotropyExt, 1.0f); } } }
private void SetSamplerInformation(Material material, MatlAttribute a) { // TODO: Set the appropriate sampler information based on the attribute and param id. var samplerStruct = (MatlAttribute.MatlSampler)a.DataObject; var wrapS = GetWrapMode(samplerStruct.WrapS); var wrapT = GetWrapMode(samplerStruct.WrapT); var magFilter = GetMagFilter(samplerStruct.MagFilter); Texture textureToSet = null; switch ((long)a.ParamId) { case (long)ParamId.ColSampler: textureToSet = material.col; break; case (long)ParamId.NorSampler: textureToSet = material.nor; break; case (long)ParamId.PrmSampler: textureToSet = material.prm; break; case (long)ParamId.EmiSampler: textureToSet = material.emi; break; } if (textureToSet != null) { textureToSet.TextureWrapS = wrapS; textureToSet.TextureWrapT = wrapT; textureToSet.MagFilter = magFilter; } }
private void SetTextureParameter(Material meshMaterial, MatlAttribute a) { // Don't make texture names case sensitive. var text = ((MatlAttribute.MtalString)a.DataObject).Text.ToLower(); // Create a temp so we don't make the defaults null. if (sfTextureByName.TryGetValue(text, out Texture texture)) { switch ((long)a.ParamID) { case (long)ParamId.ColMap: meshMaterial.col = texture; break; case (long)ParamId.GaoMap: meshMaterial.gao = texture; break; case (long)ParamId.ColMap2: meshMaterial.col2 = texture; meshMaterial.HasCol2 = true; break; case (long)ParamId.NorMap: meshMaterial.nor = texture; break; case (long)ParamId.ProjMap: meshMaterial.proj = texture; break; case (long)ParamId.DifCubemap: meshMaterial.difCube = texture; break; case (long)ParamId.PrmMap: meshMaterial.prm = texture; break; case (long)ParamId.EmiMap: meshMaterial.emi = texture; break; case (long)ParamId.EmiMap2: meshMaterial.emi2 = texture; meshMaterial.HasEmi2 = true; break; case (long)ParamId.BakeLitMap: meshMaterial.bakeLit = texture; break; case (long)ParamId.InkNorMap: meshMaterial.inkNor = texture; break; case (long)ParamId.DiffuseMap: meshMaterial.dif = texture; meshMaterial.HasDiffuse = true; break; } } // TODO: Cube map reading doesn't work yet, so we need to assign it separately. if ((long)a.ParamID == (long)ParamId.SpecularCubeMap) { meshMaterial.specularIbl = meshMaterial.defaultTextures.specularPbr; } }
private void SetTextureParameter(Material meshMaterial, MatlAttribute a) { // Don't make texture names case sensitive. var text = ((MatlAttribute.MatlString)a.DataObject).Text.ToLower(); if (sfTextureByName.TryGetValue(text, out Texture texture)) { switch ((long)a.ParamId) { case (long)ParamId.ColMap: meshMaterial.HasCol = true; meshMaterial.col = texture; break; case (long)ParamId.SpecularCubeMap: meshMaterial.specularCubeMap = texture; break; case (long)ParamId.GaoMap: meshMaterial.gao = texture; break; case (long)ParamId.ColMap2: meshMaterial.col2 = texture; meshMaterial.HasCol2 = true; break; case (long)ParamId.NorMap: meshMaterial.nor = texture; break; case (long)ParamId.ProjMap: meshMaterial.proj = texture; break; case (long)ParamId.DifCubeMap: meshMaterial.difCube = texture; meshMaterial.HasDifCube = true; break; case (long)ParamId.PrmMap: meshMaterial.prm = texture; break; case (long)ParamId.EmiMap: meshMaterial.emi = texture; meshMaterial.HasEmi = true; break; case (long)ParamId.EmiMap2: meshMaterial.emi2 = texture; meshMaterial.HasEmi2 = true; break; case (long)ParamId.BakeLitMap: meshMaterial.bakeLit = texture; break; case (long)ParamId.InkNorMap: meshMaterial.HasInkNorMap = true; meshMaterial.inkNor = texture; break; case (long)ParamId.DiffuseMap: meshMaterial.dif = texture; meshMaterial.HasDiffuse = true; break; case (long)ParamId.DiffuseMap2: meshMaterial.dif2 = texture; meshMaterial.HasDiffuse2 = true; break; case (long)ParamId.DiffuseMap3: meshMaterial.dif3 = texture; meshMaterial.HasDiffuse3 = true; break; } } // TODO: Find a better way to handle this case. if (((long)a.ParamId == (long)ParamId.SpecularCubeMap) && text == "#replace_cubemap") { meshMaterial.specularCubeMap = meshMaterial.defaultTextures.specularPbr; } }