public static TextureCubeMap CreateGLCubeMap(DDS dds) { TextureCubeMap texture = new TextureCubeMap(); var cubemap = GetArrayFaces(dds, 6); bool Compressed = dds.IsCompressed(); if (Compressed) { texture.LoadImageData((int)dds.header.width, (InternalFormat)PixelInternalFormat.CompressedRgbaS3tcDxt1Ext, cubemap[0].mipmaps, cubemap[1].mipmaps, cubemap[2].mipmaps, cubemap[3].mipmaps, cubemap[4].mipmaps, cubemap[5].mipmaps); } else { texture.LoadImageData((int)dds.header.width, new SFGraphics.GLObjects.Textures.TextureFormats.TextureFormatUncompressed(PixelInternalFormat.Rgba, OpenTK.Graphics.OpenGL.PixelFormat.Rgba, OpenTK.Graphics.OpenGL.PixelType.UnsignedByte), cubemap[0].mipmaps[0], cubemap[1].mipmaps[0], cubemap[2].mipmaps[0], cubemap[3].mipmaps[0], cubemap[4].mipmaps[0], cubemap[5].mipmaps[0]); } return(texture); }
public static TextureCubeMap CreateTextureCubeMap(NutTexture t) { TextureCubeMap texture = new TextureCubeMap(Properties.Resources._10102000); texture.Bind(); // Necessary to access mipmaps past the base level. texture.MinFilter = TextureMinFilter.LinearMipmapLinear; // The number of mip maps needs to be specified first. GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureBaseLevel, 0); GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMaxLevel, t.surfaces[0].mipmaps.Count); GL.GenerateMipmap(GenerateMipmapTarget.TextureCubeMap); for (int i = 0; i < t.surfaces.Count; i++) { GL.CompressedTexImage2D <byte>(TextureTarget.TextureCubeMapPositiveX + i, 0, (InternalFormat)t.pixelInternalFormat, t.Width, t.Height, 0, t.ImageSize, t.surfaces[i].mipmaps[0]); // Initialize the data for each level. for (int j = 1; j < t.surfaces[i].mipmaps.Count; j++) { GL.CompressedTexImage2D <byte>(TextureTarget.TextureCubeMapPositiveX + i, j, (InternalFormat)t.pixelInternalFormat, t.Width / (int)Math.Pow(2, j), t.Height / (int)Math.Pow(2, j), 0, t.ImageSize, t.surfaces[i].mipmaps[j]); } } return(texture); }
public static void RenderSkyBox(Camera camera, TextureCubeMap cubemap, int mipLevel = 0) { if (UnitSkyBox == null) { UnitSkyBox = new SkyBox(); } var shader = ShaderManager.GetShader("CubeMap"); shader.UseProgram(); shader.SetInt("mipLevel", mipLevel); Matrix4 view = camera.ModelViewMatrix; var mat = new Matrix3(view); view = new Matrix4(mat); shader.SetMatrix4x4("view", ref view); var projection = Matrix4.CreatePerspectiveFieldOfView(1.3f, camera.RenderWidth / (float)camera.RenderHeight, 0.1f, 100.0f); shader.SetMatrix4x4("projection", ref projection); shader.SetTexture("skybox", cubemap, 0); cubemap.MagFilter = TextureMagFilter.Nearest; UnitSkyBox.Draw(shader); }
/// <summary> /// Binds the given <see cref="TextureCubeMap"/> to the GraphicsDevice at the given texture unit location. /// </summary> /// <param name="slot">The texture unit slot that the texture will be bound to.</param> /// <param name="textureCubeMap">The <see cref="TextureCubeMap"/> to bind.</param> public void BindTextureCubeMap(int slot, TextureCubeMap textureCubeMap) { if (slot < 0 || slot >= GLInfo.MaxTextureImageUnits) { throw new ArgumentOutOfRangeException(nameof(slot)); } if (textureCubeMap == null) { throw new ArgumentNullException(nameof(textureCubeMap)); } textureCubeMap.EnsureUndisposed(); SetActiveTextureSlot(slot); if (_textureUnits[slot].TextureCubeMapHandle == textureCubeMap.Handle) { return; } ClearOtherTextureTypes(slot, ManaTextureType.TextureCubeMap); GL.BindTexture(TextureTarget.TextureCubeMap, textureCubeMap.Handle); _boundTextureType = ManaTextureType.TextureCubeMap; _textureUnits[slot].TextureCubeMapHandle = textureCubeMap.Handle; _textureUnits[slot].TextureCubeMap = textureCubeMap; _textureUnits[slot].TextureCubeMap.BoundContext = this; }
public TextureCubeMap LoadCubeMap(string front, string back, string bottom, string top, string left, string right) { // TODO Setup Cubemap hotswapping var rv = TextureCubeMap.CreateFromFile(TexturesFolder + front, TexturesFolder + back, TexturesFolder + bottom, TexturesFolder + top, TexturesFolder + left, TexturesFolder + right); CubeMaps.Add(rv.TextureId, rv); return(rv); }
public void BitmapFaces() { // Will fail if exception is thrown. var texture = new TextureCubeMap(); texture.LoadImageData(new Bitmap(8, 8 * 8 * 6), 8); Assert.AreEqual(8, texture.Width); Assert.AreEqual(8, texture.Height); }
public static TextureCubeMap CreateGLCubeMap(DDS dds) { TextureCubeMap texture = new TextureCubeMap(); List <byte[]> cubemap = GetArrayFaces(dds.bdata, 6); texture.LoadImageData((int)dds.header.width, new SFGraphics.GLObjects.Textures.TextureFormats.TextureFormatUncompressed(PixelInternalFormat.Rgba, OpenTK.Graphics.OpenGL.PixelFormat.Rgba, OpenTK.Graphics.OpenGL.PixelType.Float), cubemap[0], cubemap[1], cubemap[2], cubemap[3], cubemap[4], cubemap[5]); return(texture); }
public void NotCompressedInternalFormat() { var textureCubeMap = new TextureCubeMap(); var e = Assert.ThrowsException <ArgumentException>(() => textureCubeMap.LoadImageData(128, InternalFormat.Rgba, mipmaps, mipmaps, mipmaps, mipmaps, mipmaps, mipmaps)); Assert.AreEqual("The InternalFormat is not a compressed image format.", e.Message); }
public void CorrectFormatSameMipmapCount() { // Will fail if exception is thrown. var texture = new TextureCubeMap(); texture.LoadImageData(128, InternalFormat.CompressedRgbaS3tcDxt1Ext, mipmaps, mipmaps, mipmaps, mipmaps, mipmaps, mipmaps); Assert.AreEqual(128, texture.Width); Assert.AreEqual(128, texture.Height); }
public void UncompressedGenerateMipmaps() { var texture = new TextureCubeMap(); var format = new TextureFormatUncompressed(PixelInternalFormat.Rgba32f, PixelFormat.Rgba, PixelType.Float); texture.LoadImageData(128, format, mipmaps[0], mipmaps[0], mipmaps[0], mipmaps[0], mipmaps[0], mipmaps[0]); Assert.AreEqual(128, texture.Width); Assert.AreEqual(128, texture.Height); }
public void MoreThanOneTypePerTextureUnit() { shader.SetTexture("tex2D", new Texture2D(), 0); var cube = new TextureCubeMap(); shader.SetTexture("texCube", cube, 0); Assert.AreEqual(0, invalidUniformSets.Count); Assert.AreEqual(1, invalidTextureSets.Count); Assert.AreEqual("texCube", invalidTextureSets[0].Name); Assert.AreEqual(0, invalidTextureSets[0].TextureUnit); Assert.AreEqual(ActiveUniformType.SamplerCube, invalidTextureSets[0].Type); Assert.AreEqual(cube, invalidTextureSets[0].Value); }
/// <summary> /// Ensures that the given <see cref="TextureCubeMap"/> object is unbound from all slots. /// </summary> public void EnsureTextureCubeMapUnbound(TextureCubeMap textureCubeMap) { if (textureCubeMap == null) { throw new ArgumentNullException(nameof(textureCubeMap)); } for (int i = 0; i < GLInfo.MaxTextureImageUnits; i++) { if (_textureUnits[i].TextureCubeMapHandle == textureCubeMap.Handle) { UnbindTextureCubeMap(i); } } }
public void InvalidMipmapCount() { List <byte[]> mipmapsBig = new List <byte[]> { new byte[16] }; var textureCubeMap = new TextureCubeMap(); var e = Assert.ThrowsException <ArgumentOutOfRangeException>(() => textureCubeMap.LoadImageData(128, InternalFormat.CompressedRgbaS3tcDxt1Ext, mipmaps, mipmaps, mipmaps, mipmapsBig, mipmaps, mipmaps)); Assert.IsTrue(e.Message.Contains("Mipmap count is not equal for all faces.")); Assert.AreEqual("mips", e.ParamName); }
private void LoadSpecularPbr() { specularPbr = new TextureCubeMap(); var surfaceData = new List <List <byte[]> >(); AddCubeMipmaps(surfaceData, "x+"); AddCubeMipmaps(surfaceData, "x-"); AddCubeMipmaps(surfaceData, "y+"); AddCubeMipmaps(surfaceData, "y-"); AddCubeMipmaps(surfaceData, "z+"); AddCubeMipmaps(surfaceData, "z-"); var format = new TextureFormatUncompressed(PixelInternalFormat.Rgba32f, PixelFormat.Rgba, PixelType.Float); specularPbr.LoadImageData(64, format, surfaceData[0], surfaceData[1], surfaceData[2], surfaceData[3], surfaceData[4], surfaceData[5]); }
/// <summary> /// Ensures that the given <see cref="TextureCubeMap"/> object is unbound on the given slot. /// </summary> public void EnsureTextureCubeMapUnbound(int slot, TextureCubeMap textureCubeMap) { if (slot < 0 || slot >= GLInfo.MaxTextureImageUnits) { throw new ArgumentOutOfRangeException(nameof(slot)); } if (textureCubeMap == null) { throw new ArgumentNullException(nameof(textureCubeMap)); } if (_textureUnits[slot].TextureCubeMapHandle == textureCubeMap.Handle) { UnbindTextureCubeMap(slot); } }
private void LoadSpecularPbr() { specularPbr = new TextureCubeMap(); var surfaceData = new List <List <byte[]> >(); for (int surface = 0; surface < 6; surface++) { var mipmaps = new List <byte[]>(); for (int mip = 0; mip < 10; mip++) { var mipData = System.IO.File.ReadAllBytes($"DefaultTextures/specularSdr{surface}{mip}.bin"); mipmaps.Add(mipData); } surfaceData.Add(mipmaps); } specularPbr.LoadImageData(512, InternalFormat.CompressedRgbaS3tcDxt1Ext, surfaceData[0], surfaceData[1], surfaceData[2], surfaceData[3], surfaceData[4], surfaceData[5]); }
public static void LoadTextures() { dummyTextures = CreateNudDummyTextures(); NudMatSphereDrawing.LoadMaterialSphereTextures(); // Helpful textures. uvTestPattern = new Texture2D(); uvTestPattern.LoadImageData(Properties.Resources.UVPattern); uvTestPattern.TextureWrapS = TextureWrapMode.Repeat; uvTestPattern.TextureWrapT = TextureWrapMode.Repeat; // TODO: Simplify this conversion. DDS specularSdr = new DDS(new FileData(Properties.Resources.specularSDR)); specularPbr = NUT.CreateTextureCubeMap(specularSdr.ToNutTexture()); DDS diffuseSdr = new DDS(new FileData(Properties.Resources.diffuseSDR)); diffusePbr = NUT.CreateTextureCubeMap(diffuseSdr.ToNutTexture()); // Don't use mipmaps. diffusePbr.MinFilter = TextureMinFilter.Linear; diffusePbr.MagFilter = TextureMagFilter.Linear; boneWeightGradient = new Texture2D(); boneWeightGradient.LoadImageData(Properties.Resources.boneWeightGradient); boneWeightGradient2 = new Texture2D(); boneWeightGradient2.LoadImageData(Properties.Resources.boneWeightGradient2); defaultTex = new Texture2D(); defaultTex.LoadImageData(Resources.Resources.DefaultTexture); try { floorTexture = new Texture2D(); floorTexture.LoadImageData(new Bitmap(Runtime.floorTexFilePath)); backgroundTexture = new Texture2D(); backgroundTexture.LoadImageData(new Bitmap(Runtime.backgroundTexFilePath)); } catch (Exception) { // File paths are incorrect or never set. } }
private void LoadDiffusePbr() { diffusePbr = new TextureCubeMap(); var surfaceData = new List <List <byte[]> >(); for (int surface = 0; surface < 6; surface++) { var mipData = System.IO.File.ReadAllBytes($"DefaultTextures/diffuseSdr{surface}{0}.bin"); surfaceData.Add(new List <byte[]>() { mipData }); } diffusePbr.LoadImageData(128, InternalFormat.CompressedRgbaS3tcDxt1Ext, surfaceData[0], surfaceData[1], surfaceData[2], surfaceData[3], surfaceData[4], surfaceData[5]); // Don't Use mipmaps. diffusePbr.MagFilter = TextureMagFilter.Linear; diffusePbr.MinFilter = TextureMinFilter.Linear; }
public Material(Resources.DefaultTextures defaultTextures) { // TODO: Don't store another reference. this.defaultTextures = defaultTextures; // Ensure the textures are never null, so we can modify their state later. col = defaultTextures.defaultBlack; col2 = defaultTextures.defaultBlack; proj = defaultTextures.defaultBlack; nor = defaultTextures.defaultNormal; inkNor = defaultTextures.defaultWhite; prm = defaultTextures.defaultPrm; emi = defaultTextures.defaultBlack; emi2 = defaultTextures.defaultBlack; bakeLit = defaultTextures.defaultBlack; gao = defaultTextures.defaultWhite; specularIbl = defaultTextures.blackCube; difCube = defaultTextures.defaultBlack; dif = defaultTextures.defaultBlack; }
public static TextureCubeMap CreateTextureCubeMap(NutTexture t) { if (TextureFormatTools.IsCompressed(t.pixelInternalFormat)) { // Compressed cubemap with mipmaps. TextureCubeMap texture = new TextureCubeMap(); texture.LoadImageData(t.Width, (InternalFormat)t.pixelInternalFormat, t.surfaces[0].mipmaps, t.surfaces[1].mipmaps, t.surfaces[2].mipmaps, t.surfaces[3].mipmaps, t.surfaces[4].mipmaps, t.surfaces[5].mipmaps); return(texture); } else { // Uncompressed cube map with no mipmaps. TextureCubeMap texture = new TextureCubeMap(); texture.LoadImageData(t.Width, new TextureFormatUncompressed(t.pixelInternalFormat, t.pixelFormat, t.pixelType), t.surfaces[0].mipmaps[0], t.surfaces[1].mipmaps[0], t.surfaces[2].mipmaps[0], t.surfaces[3].mipmaps[0], t.surfaces[4].mipmaps[0], t.surfaces[5].mipmaps[0]); return(texture); } }
private void LoadDiffusePbr() { diffusePbr = new TextureCubeMap(); var surfaceData = new List <List <byte[]> >(); AddIrrFace(surfaceData, "x+"); AddIrrFace(surfaceData, "x-"); AddIrrFace(surfaceData, "y+"); AddIrrFace(surfaceData, "y-"); AddIrrFace(surfaceData, "z+"); AddIrrFace(surfaceData, "z-"); var format = new TextureFormatUncompressed(PixelInternalFormat.Rgba32f, PixelFormat.Rgba, PixelType.Float); diffusePbr.LoadImageData(64, format, surfaceData[0], surfaceData[1], surfaceData[2], surfaceData[3], surfaceData[4], surfaceData[5]); // Don't Use mipmaps. diffusePbr.MagFilter = TextureMagFilter.Linear; diffusePbr.MinFilter = TextureMinFilter.Linear; }
public override void Initialize() { base.Initialize(); _projectionMatrix = Matrix4x4.CreatePerspectiveFieldOfView(1.0f, Window.AspectRatio, 0.1f, 10_000.0f); var sw = Stopwatch.StartNew(); _shader = AssetManager.Load <ShaderProgram>("./Shaders/shader.json", true); _mesh = MeshGenerator.CreateMesh(RenderContext, MeshGenerator.GenerateCubeData(Vector3.Zero, 1f, 1f, 1f), Matrix4x4.Identity); _skyboxMesh = MeshGenerator.CreateMesh(RenderContext, MeshGenerator.GenerateSkyboxCube(), Matrix4x4.Identity); Window.Maximize(); _skybox0 = AssetManager.Load <TextureCubeMap>("./Textures/skybox1/skybox1.json"); _skyboxShader = AssetManager.Load <ShaderProgram>("./Shaders/skybox.json"); _nanosuit = AssetManager.Load <Model>("./Models/Nanosuit/nanosuit.obj"); sw.Stop(); _log.Info("Assets loaded in: " + sw.Elapsed.TotalMilliseconds + " ms"); }
public static Dictionary <NudEnums.DummyTexture, Texture> CreateNudDummyTextures() { Dictionary <NudEnums.DummyTexture, Texture> dummyTextures = new Dictionary <NudEnums.DummyTexture, Texture>(); // Dummy textures. TextureCubeMap stageMapHigh = new TextureCubeMap(); stageMapHigh.LoadImageData(Properties.Resources._10102000, 128); dummyTextures.Add(NudEnums.DummyTexture.StageMapHigh, stageMapHigh); TextureCubeMap stageMapLow = new TextureCubeMap(); stageMapLow.LoadImageData(Properties.Resources._10101000, 128); dummyTextures.Add(NudEnums.DummyTexture.StageMapLow, stageMapLow); Texture2D dummyRamp = new Texture2D(); dummyRamp.LoadImageData(Properties.Resources._10080000); dummyTextures.Add(NudEnums.DummyTexture.DummyRamp, dummyRamp); Texture2D pokemonStadiumDummyTex = new Texture2D(); pokemonStadiumDummyTex.LoadImageData(Properties.Resources._10040001); dummyTextures.Add(NudEnums.DummyTexture.PokemonStadium, pokemonStadiumDummyTex); Texture2D punchOutDummyTex = new Texture2D(); punchOutDummyTex.LoadImageData(Properties.Resources._10040000); dummyTextures.Add(NudEnums.DummyTexture.PunchOut, punchOutDummyTex); Texture2D shadowMapDummyTex = new Texture2D(); shadowMapDummyTex.LoadImageData(Properties.Resources._10100000); dummyTextures.Add(NudEnums.DummyTexture.ShadowMap, shadowMapDummyTex); return(dummyTextures); }
void CreateFramebuffers() { deferred_fb = device.CreateFrameBuffer(device.Width, device.Height); lighting_fb = device.CreateFrameBuffer(device.Width, device.Height); shadow_fb = device.CreateFrameBuffer(SHADOW_MAP_SIZE, SHADOW_MAP_SIZE); if (device.Extensions.NV_depth_buffer_float) { has_stencil = true; depth_texture = device.CreateTexture2D(InternalFormat.DepthComponent32F_Stencil8_NV, device.Width, device.Height); shadow_texture = device.CreateTexture2D(InternalFormat.DepthComponent32F_NV, SHADOW_MAP_SIZE, SHADOW_MAP_SIZE); shadow_texture_cube = device.CreateTextureCubeMap(InternalFormat.DepthComponent32F_NV, SHADOW_MAP_SIZE); } else if (device.Extensions.ARB_depth_buffer_float) { // TODO: does not work on ATI //has_stencil = true; //depth_texture = device.CreateTexture2D(InternalFormat.Depth24Stencil8, device.Width, device.Height); has_stencil = false; depth_texture = device.CreateTexture2D(InternalFormat.DepthComponent32F, device.Width, device.Height); shadow_texture = device.CreateTexture2D(InternalFormat.DepthComponent32F, SHADOW_MAP_SIZE, SHADOW_MAP_SIZE); shadow_texture_cube = device.CreateTextureCubeMap(InternalFormat.DepthComponent32F, SHADOW_MAP_SIZE); } else { throw new System.ApplicationException("no hardware floating shadow maps available!"); } depth_texture.SetFilter(TextureMagFilter.Nearest, TextureMinFilter.Nearest); depth_texture.SetWrap(TextureWrap.ClampToEdge, TextureWrap.ClampToEdge); depth_texture.SetCompareMode(TextureCompareMode.None); shadow_texture.SetFilter(TextureMagFilter.Linear, TextureMinFilter.Linear); shadow_texture.SetWrap(TextureWrap.ClampToEdge, TextureWrap.ClampToEdge); shadow_texture.SetCompareMode(TextureCompareMode.CompareRToTexture); shadow_texture.SetCompareFunc(TextureCompareFunc.LEqual); shadow_texture_cube.SetFilter(TextureMagFilter.Linear, TextureMinFilter.Linear); shadow_texture_cube.SetWrap(TextureWrap.ClampToEdge, TextureWrap.ClampToEdge); //shadow_texture_cube.SetCompareMode(TextureCompareMode.CompareRToTexture); //shadow_texture_cube.SetCompareFunc(TextureCompareFunc.LEqual); //color_texture = device.CreateTexture2D(InternalFormat.RGBA8, device.Width, device.Height); // fallback color_texture = device.CreateTexture2D(InternalFormat.RGBA16F, device.Width, device.Height); color_texture.SetFilter(TextureMagFilter.Nearest, TextureMinFilter.Nearest); color_texture.SetWrap(TextureWrap.ClampToEdge, TextureWrap.ClampToEdge); //normal_texture = device.CreateTexture2D(InternalFormat.RGBA8, device.Width, device.Height); // fallback normal_texture = device.CreateTexture2D(InternalFormat.RGBA16F, device.Width, device.Height); normal_texture.SetFilter(TextureMagFilter.Nearest, TextureMinFilter.Nearest); normal_texture.SetWrap(TextureWrap.ClampToEdge, TextureWrap.ClampToEdge); lighting_output = device.CreateTexture2D(InternalFormat.RGBA8, device.Width, device.Height); //lighting_output = device.CreateTexture2D(InternalFormat.RGB16F, device.Width, device.Height); // for HDR lighting_output.SetFilter(TextureMagFilter.Nearest, TextureMinFilter.Nearest); lighting_output.SetWrap(TextureWrap.ClampToEdge, TextureWrap.ClampToEdge); GL.ReadBuffer(ReadBufferMode.None); // TODO GL.DrawBuffer(DrawBufferMode.None); // TODO shadow_fb.SetTexture2D(FramebufferAttachment.DepthAttachment, 0, shadow_texture); System.Diagnostics.Debug.Assert(shadow_fb.Status == FramebufferStatus.Complete); deferred_fb.SetTexture2D(FramebufferAttachment.DepthAttachment, 0, depth_texture); if (has_stencil) { deferred_fb.SetTexture2D(FramebufferAttachment.StencilAttachment, 0, depth_texture); } deferred_fb.SetTexture2D(FramebufferAttachment.Color0, 0, color_texture); deferred_fb.SetTexture2D(FramebufferAttachment.Color1, 0, normal_texture); System.Diagnostics.Debug.Assert(deferred_fb.Status == FramebufferStatus.Complete); lighting_fb.SetTexture2D(FramebufferAttachment.DepthAttachment, 0, depth_texture); if (has_stencil) { lighting_fb.SetTexture2D(FramebufferAttachment.StencilAttachment, 0, depth_texture); } lighting_fb.SetTexture2D(FramebufferAttachment.Color0, 0, lighting_output); System.Diagnostics.Debug.Assert(lighting_fb.Status == FramebufferStatus.Complete); }
/// <summary> /// Load contents /// </summary> public override void LoadContent() { Display.RenderState.ClearColor = Color.Pink; Display.RenderState.FrontFace = FrontFace.CounterClockWise; Display.RenderState.DepthTest = true; #region Textures #region Cube texture Display.TextureUnit = 0; CubeTexture = new TextureCubeMap(); CubeTexture.WrapR = TextureWrapFilter.ClampToEdge; CubeTexture.WrapS = TextureWrapFilter.ClampToEdge; CubeTexture.WrapT = TextureWrapFilter.ClampToEdge; CubeTexture.MagFilter = TextureMagFilter.Linear; CubeTexture.MinFilter = TextureMinFilter.LinearMipmapLinear; // load the 6 faces CubeTexture.LoadImage(TextureCubeFace.NegativeX, "data/textures/neg_x.png"); CubeTexture.LoadImage(TextureCubeFace.NegativeY, "data/textures/neg_y.png"); CubeTexture.LoadImage(TextureCubeFace.NegativeZ, "data/textures/neg_z.png"); CubeTexture.LoadImage(TextureCubeFace.PositiveX, "data/textures/pos_x.png"); CubeTexture.LoadImage(TextureCubeFace.PositiveY, "data/textures/pos_y.png"); CubeTexture.LoadImage(TextureCubeFace.PositiveZ, "data/textures/pos_z.png"); CubeTexture.GenerateMipmap(); #endregion #region Tarnish texture Display.TextureUnit = 1; TarnishTexture = new Texture2D("data/textures/tarnish.png"); TarnishTexture.MagFilter = TextureMagFilter.Linear; TarnishTexture.MinFilter = TextureMinFilter.LinearMipmapLinear; TarnishTexture.HorizontalWrap = TextureWrapFilter.ClampToEdge; TarnishTexture.VerticalWrap = TextureWrapFilter.ClampToEdge; TarnishTexture.GenerateMipmap(); #endregion #endregion #region Meshes // Generate the cube mesh Cube = Mesh.CreateCube(3.0f); // Generate the spehre Sphere = Mesh.CreateSphere(1.0f, 32); #endregion #region Shaders // Reflection shader Reflection = new Shader(); Reflection.LoadSource(ShaderType.VertexShader, "data/shaders/reflection.vert"); Reflection.LoadSource(ShaderType.FragmentShader, "data/shaders/reflection.frag"); Reflection.Compile(); // Skybox shader Skybox = new Shader(); Skybox.LoadSource(ShaderType.VertexShader, "data/shaders/skybox.vert"); Skybox.LoadSource(ShaderType.FragmentShader, "data/shaders/skybox.frag"); Skybox.Compile(); #endregion }
public void SetTextureCubeMap(FramebufferAttachment attachment, TextureTarget face, int miplevel, TextureCubeMap texture) { GL.BindFramebuffer(FramebufferType.Framebuffer, framebuffer); GL.FramebufferTexture2D(FramebufferType.Framebuffer, attachment, face, texture == null ? 0 : texture.Handle, miplevel); SetTextureAttachment(attachment, texture); }
public void Set(TextureCubeMap texture) { if (location != -1) { Debug.Assert(type == UniformType.SamplerCube); GL.ActiveTexture(unit); GL.BindTexture(TextureTarget.TextureCubeMap, texture.Handle); GL.Uniform(location, unit - TextureUnit.Texture0); } }
/// <summary> /// Gets the SFTexture of this surface /// </summary> /// <returns></returns> public Texture GetRenderTexture() { if (renderTexture == null) { if (Arrays.Count == 6) { var cube = new TextureCubeMap() { MinFilter = TextureMinFilter.Linear, MagFilter = TextureMagFilter.Linear }; if (TextureFormatTools.IsCompressed(InternalFormat)) { cube.LoadImageData(Width, InternalFormat, Arrays[0].Mipmaps, Arrays[1].Mipmaps, Arrays[2].Mipmaps, Arrays[3].Mipmaps, Arrays[4].Mipmaps, Arrays[5].Mipmaps); } else { var format = new TextureFormatUncompressed((PixelInternalFormat)PixelFormat, PixelFormat, PixelType); cube.LoadImageData(Width, format, Arrays[0].Mipmaps[0], Arrays[1].Mipmaps[0], Arrays[2].Mipmaps[0], Arrays[3].Mipmaps[0], Arrays[4].Mipmaps[0], Arrays[5].Mipmaps[0]); } renderTexture = cube; } else { var sfTex = new Texture2D() { // Set defaults until all the sampler parameters are added. TextureWrapS = TextureWrapMode.Repeat, TextureWrapT = TextureWrapMode.Repeat, }; if (TextureFormatTools.IsCompressed(InternalFormat)) { // hack // trying to load mipmaps with similar sizes seems to not work var mipTest = new List <byte[]>(); int prevsize = 0; foreach (var v in Arrays[0].Mipmaps) { if (v.Length == prevsize) { continue; } mipTest.Add(v); prevsize = v.Length; } sfTex.LoadImageData(Width, Height, mipTest, InternalFormat); } else { // TODO: Uncompressed mipmaps var format = new TextureFormatUncompressed(PixelInternalFormat.Rgba, PixelFormat, PixelType); sfTex.LoadImageData(Width, Height, Arrays[0].Mipmaps, format); } renderTexture = sfTex; } } return(renderTexture); }