private static void SetUniformData(GFBMaterial mat, ShaderProgram shader, string propertyName) { if (mat.MaterialData.SwitchParams.ContainsKey(propertyName)) { bool Value = (bool)mat.MaterialData.SwitchParams[propertyName].Value; shader.SetBoolToInt(propertyName, Value); } if (mat.MaterialData.ValueParams.ContainsKey(propertyName)) { var Value = mat.MaterialData.ValueParams[propertyName].Value; if (Value is float) { shader.SetFloat(propertyName, (float)Value); } if (Value is uint) { shader.SetFloat(propertyName, (uint)Value); } if (Value is int) { shader.SetFloat(propertyName, (int)Value); } } if (mat.MaterialData.ColorParams.ContainsKey(propertyName)) { Vector3 Value = (Vector3)mat.MaterialData.ColorParams[propertyName].Value; shader.SetVector3(propertyName, Value); } }
private static void SetUniforms(GFBMaterial mat, ShaderProgram shader, GFBMesh m, int id) { // Texture Maps /* shader.SetBoolToInt("useColorTex", false); * shader.SetBoolToInt("EmissionMaskUse", false); * shader.SetBoolToInt("SwitchPriority", false); * shader.SetBoolToInt("Layer1Enable", false); * shader.SetBoolToInt("AmbientMapEnable", false); * shader.SetBoolToInt("NormalMapEnable", false); * shader.SetBoolToInt("LightTableEnable", false); * shader.SetBoolToInt("BaseColorAddEnable", false); * shader.SetBoolToInt("SphereMapEnable", false); * shader.SetBoolToInt("EffectVal", false);*/ //Switch UVs shader.SetBoolToInt("SwitchEmissionMaskTexUV", false); shader.SetBoolToInt("SwitchAmbientTexUV", false); shader.SetBoolToInt("SwitchNormalMapUV", false); //UV Scale shader.SetFloat("ColorUVScaleU", 1); shader.SetFloat("ColorUVScaleV", 1); //UV Translate shader.SetFloat("ColorUVTranslateU", 0); shader.SetFloat("ColorUVTranslateV", 0); SetUniformData(mat, shader, "ColorUVScaleU"); SetUniformData(mat, shader, "ColorUVScaleV"); SetUniformData(mat, shader, "ColorUVTranslateU"); SetUniformData(mat, shader, "ColorUVTranslateV"); }
private static void TextureUniform(ShaderProgram shader, GFBMaterial mat, bool hasTex, string name, STGenericMatTexture mattex) { if (mattex.textureState == STGenericMatTexture.TextureState.Binded) { return; } // Bind the texture and create the uniform if the material has the right textures. if (hasTex) { GL.Uniform1(shader[name], BindTexture(mattex, shader)); } }
private void SetUniformBlocks(GFBMaterial mat, ShaderProgram shader, GFBMesh m, int id) { /* shader.UniformBlockBinding("TexCoord1", 3); * GL.GetActiveUniformBlock(shader.program, * shader.GetUniformBlockIndex("TexCoord1"), * ActiveUniformBlockParameter.UniformBlockBinding, out int binding);*/ /* GL.BindBuffer(BufferTarget.UniformBuffer, TexCoord1Buffer); * GL.BufferData(BufferTarget.UniformBuffer, * (IntPtr)MTOBWrapper.TexCoord1.Size, * ref mat.TexCoord1Buffer, * BufferUsageHint.StaticDraw); * GL.BindBuffer(BufferTarget.UniformBuffer, 0); * GL.BindBufferRange(BufferRangeTarget.UniformBuffer, 0, TexCoord1Buffer, (IntPtr)0, * MTOBWrapper.TexCoord1.Size); * GL.BindBuffer(BufferTarget.UniformBuffer, TexCoord1Buffer); * GL.BINDBUFFER*/ }
private static void SetTextureUniforms(GFBMaterial mat, GFBMesh m, ShaderProgram shader) { SetDefaultTextureAttributes(mat, shader); GL.ActiveTexture(TextureUnit.Texture0 + 1); GL.BindTexture(TextureTarget.Texture2D, RenderTools.defaultTex.RenderableTex.TexID); GL.Uniform1(shader["debugOption"], 2); GL.ActiveTexture(TextureUnit.Texture11); GL.Uniform1(shader["weightRamp1"], 11); GL.BindTexture(TextureTarget.Texture2D, RenderTools.BoneWeightGradient.Id); GL.ActiveTexture(TextureUnit.Texture12); GL.Uniform1(shader["weightRamp2"], 12); GL.BindTexture(TextureTarget.Texture2D, RenderTools.BoneWeightGradient2.Id); GL.ActiveTexture(TextureUnit.Texture10); GL.Uniform1(shader["UVTestPattern"], 10); GL.BindTexture(TextureTarget.Texture2D, RenderTools.uvTestPattern.RenderableTex.TexID); shader.SetInt("RedChannel", 0); shader.SetInt("GreenChannel", 1); shader.SetInt("BlueChannel", 2); shader.SetInt("AlphaChannel", 3); LoadPBRMaps(shader); foreach (STGenericMatTexture matex in mat.TextureMaps) { if (matex.Type == STGenericMatTexture.TextureType.Diffuse) { shader.SetBoolToInt("HasDiffuse", true); TextureUniform(shader, mat, true, "DiffuseMap", matex); } } }
private static void SetDefaultTextureAttributes(GFBMaterial mat, ShaderProgram shader) { }