private void InitializeTextureUnits() { // Bind a dummy texture to all texture units byte[] whiteData = new byte[4]; whiteData[0] = 255; whiteData[1] = 255; whiteData[2] = 255; whiteData[3] = 255; dummyTexture = new TextureGL(1, 1, PixelFormat.Rgba, PixelInternalFormat.Rgba); dummyTexture.Upload(whiteData, 0); nearestSampler = new SamplerGL1(); nearestSampler.MinFilter = TextureMinFilter.Nearest; nearestSampler.MagFilter = TextureMagFilter.Nearest; nearestSampler.Wrap = TextureWrapMode.ClampToEdge; int textureUnits = 4; try { GL.GetInteger(GetPName.MaxTextureUnits, out textureUnits); } catch (Exception) { } for (int i = 0; i < textureUnits; ++i) { try { GL.ActiveTexture(TextureUnit.Texture0 + i); dummyTexture.Apply(); nearestSampler.Apply(i, TextureTarget.Texture2D); } catch (Exception) { } } float[] zeros = { 0.0f, 0.0f, 0.0f, 0.0f }; for (int i = 0; i < 8; ++i) { GL.Light(LightName.Light0 + i, LightParameter.Ambient, zeros); } }
private void InitializeShaderSystem() { //InitializeOpenRL(); //GL.Enable(EnableCap.Normalize); var dualTexture = AttributeMappings.Pool["dualtexture"] = new AttributeMappings(); dualTexture.Add(0, "_position", VertexUsage.Position, 0, 3); dualTexture.Add(1, "_texcoord", VertexUsage.TexCoord, 0, VertexUsage.TexCoord, 0, 2); dualTexture.Add(2, "_texcoord", VertexUsage.TexCoord, 0, VertexUsage.TexCoord, 1, 2); dualTexture.Add(3, "_color", VertexUsage.Color, 0, 4); var idToColor = AttributeMappings.Pool["idToColor"] = new AttributeMappings(); idToColor.Add(0, "_position", VertexUsage.Position, 0, 3); idToColor.Add(1, "_id_vec3", VertexUsage.Id, 0, VertexUsage.Color, 0, 3); CameraUniformBlock.NearFar = "near_far"; CameraUniformBlock.FovXFovYAspect = "fovx_fovy_aspect"; CameraUniformBlock.ViewToClip = "view_to_clip_matrix"; CameraUniformBlock.ClipToView = "view_to_clip_matrix"; CameraUniformBlock.WorldToClip = "world_to_clip_matrix"; CameraUniformBlock.ClipToWorld = "clip_to_world_matrix"; CameraUniformBlock.WorldToView = "world_to_view_matrix"; CameraUniformBlock.ViewToWorld = "view_to_world_matrix"; CameraUniformBlock.Viewport = "viewport"; CameraUniformBlock.ViewPositionInWorld = "view_position_in_world"; CameraUniformBlock.Initialize("camera"); LightsUniforms.spec.Count = "count"; LightsUniforms.spec.Exposure = "exposure"; LightsUniforms.spec.Bias = "bias"; LightsUniforms.spec.AmbientLightColor = "ambient_light_color"; LightsUniforms.spec.WorldToLight = "world_to_light_matrix"; LightsUniforms.spec.WorldToShadow = "world_to_shadow_matrix"; LightsUniforms.spec.Direction = "direction"; LightsUniforms.spec.Color = "color"; LightsUniforms.Initialize("lights", Configuration.maxLightCount); globalUB = new UniformBlockGL("global"); globalUB.AddVec4("add_color"); globalUB.AddFloat("alpha"); globalUB.Seal(); modelsUB = new UniformBlockGL("models"); modelsUB.AddMat4("model_to_world_matrix", Configuration.instanceCount); modelsUB.AddVec4("id_offset_vec3", Configuration.instanceCount); ShaderGL3.Replace("#if USE_INTEGER_POLYGON_ID", "#if 0"); modelsUB.Seal(); models = UniformBufferFactory.Create(modelsUB); global = UniformBufferFactory.Create(globalUB); global.Floats("alpha").Set(1.0f); global.Floats("add_color").Set(0.0f, 0.0f, 0.4f); global.SyncDelegate = ForceProgramUse; models.SyncDelegate = ModelsDirty; models.Use(); global.Use(); LightsUniforms.Exposure.Set(1.0f); LightsUniforms.Bias.Set(-0.002f, 0.0f, 0.002f); LightsUniforms.AmbientLightColor.Set(0.2f, 0.2f, 0.2f); LightsUniforms.UniformBufferGL.Sync(); LightsUniforms.UniformBufferGL.Use(); var nearestClampToEdge = new SamplerGL1(); nearestClampToEdge.MinFilter = TextureMinFilter.Nearest; nearestClampToEdge.MagFilter = TextureMagFilter.Nearest; nearestClampToEdge.Wrap = TextureWrapMode.ClampToEdge; nearestClampToEdge.CompareMode = TextureCompareMode.None; var bilinearClampToEdge = new SamplerGL1(); bilinearClampToEdge.MinFilter = TextureMinFilter.NearestMipmapLinear; bilinearClampToEdge.MagFilter = TextureMagFilter.Linear; bilinearClampToEdge.Wrap = TextureWrapMode.ClampToEdge; bilinearClampToEdge.CompareMode = TextureCompareMode.None; Samplers.Global.AddSampler2D("t_font", nearestClampToEdge); Samplers.Global.AddSampler2D("t_ninepatch", bilinearClampToEdge).TextureUnitIndex = 1; Samplers.Global.AddSampler2D("t_cube", bilinearClampToEdge); Samplers.Global.AddSampler2D("t_left", nearestClampToEdge); Samplers.Global.AddSampler2D("t_right", nearestClampToEdge).TextureUnitIndex = 1; Samplers.Global.AddSampler2D("t_surface_color", bilinearClampToEdge); Samplers.Global.AddSampler2D("t_particle", bilinearClampToEdge); Samplers.Global.AddSampler2DArray("t_shadowmap_vis", bilinearClampToEdge); Samplers.Global.Seal(); materialUB = new UniformBlockGL("material"); materialUB.AddVec4("surface_diffuse_reflectance_color"); materialUB.AddVec4("surface_specular_reflectance_color"); materialUB.AddFloat("surface_specular_reflectance_exponent"); materialUB.AddVec2("surface_rim_parameters"); materialUB.AddVec4("grid_size"); materialUB.AddFloat("surface_roughness"); materialUB.AddFloat("surface_isotropy"); materialUB.AddFloat("contrast").Default = new Floats(1.0f); materialUB.AddFloat("deghost").Default = new Floats(0.0f); materialUB.AddFloat("saturation").Default = new Floats(1.0f); materialUB.AddFloat("t"); materialUB.AddFloat("slider_t"); materialUB.AddVec4("fill_color"); materialUB.AddVec4("point_color"); materialUB.AddFloat("point_z_offset"); materialUB.AddVec4("line_color"); materialUB.AddVec2("line_width").Default = new Floats(1.0f, 0.25f); // \todo check how to compute .y materialUB.AddFloat("bias_units"); materialUB.AddFloat("bias_factor"); materialUB.AddFloat("octaves").Default = new Floats(4.0f); materialUB.AddFloat("offset").Default = new Floats(0.0f); materialUB.AddFloat("frequency").Default = new Floats(2.2f); materialUB.AddFloat("amplitude").Default = new Floats(0.2f); materialUB.AddFloat("lacunarity").Default = new Floats(3.3f); materialUB.AddFloat("persistence").Default = new Floats(0.25f); materialUB.Seal(); materialUB.ChangeDelegate = ForceProgramUse; }