Modern OpenGL tiling region in texture atlas (properly in shader)
I am using modern OpenGL to render a 3D scene with a texture atlas which holds all of my textures.
The texture coordinate calculation is done very simply and gets loaded into a VBO for the shader. Here is some basic calculation in pseudo code:
int posX = slot % texturesInAtlasX, posY = slot / texturesInAtlasX;
float startX = 1f / texturesInAtlasX * posX;
float startY = 1f / texturesInAtlasY * posY;
Normally I use this to calculate the 4 texture coordinates for a rectangle to apply a part of the atlas to it. But to the complexity of my scene forces me to simplify my meshes by calculating some faces with the same texture together into one. Normally this is not a big deal, because in OpenGL you can easily tile your texture by raising your coords above 1. But as I am using a texture atlas this can not easily be done by changing the way how the texture coords gets calculated.
My idea was to load the slot of the atlas which should be used and the size of the face to the shader and somehow tile the part of the atlas across the face. But I have absolutely no idea how to do that. As my objects are individually moving across the scene, loading the objects into one VAO per texture or batching the objects per textures together is not an option, because this absolutely kills the performance.
So my question is: Is there any feature in OpenGL which can help me tiling only parts of a texture?
opengl textures shader texture-mapping texture-atlas
add a comment |
I am using modern OpenGL to render a 3D scene with a texture atlas which holds all of my textures.
The texture coordinate calculation is done very simply and gets loaded into a VBO for the shader. Here is some basic calculation in pseudo code:
int posX = slot % texturesInAtlasX, posY = slot / texturesInAtlasX;
float startX = 1f / texturesInAtlasX * posX;
float startY = 1f / texturesInAtlasY * posY;
Normally I use this to calculate the 4 texture coordinates for a rectangle to apply a part of the atlas to it. But to the complexity of my scene forces me to simplify my meshes by calculating some faces with the same texture together into one. Normally this is not a big deal, because in OpenGL you can easily tile your texture by raising your coords above 1. But as I am using a texture atlas this can not easily be done by changing the way how the texture coords gets calculated.
My idea was to load the slot of the atlas which should be used and the size of the face to the shader and somehow tile the part of the atlas across the face. But I have absolutely no idea how to do that. As my objects are individually moving across the scene, loading the objects into one VAO per texture or batching the objects per textures together is not an option, because this absolutely kills the performance.
So my question is: Is there any feature in OpenGL which can help me tiling only parts of a texture?
opengl textures shader texture-mapping texture-atlas
2
"loading the objects into one VAO per texture or batching the objects per textures together is not an option, because this absolutely kills the performance" But you think changing VAOs and texture frequently will be better for performance?
– Nicol Bolas
Nov 25 '18 at 22:17
add a comment |
I am using modern OpenGL to render a 3D scene with a texture atlas which holds all of my textures.
The texture coordinate calculation is done very simply and gets loaded into a VBO for the shader. Here is some basic calculation in pseudo code:
int posX = slot % texturesInAtlasX, posY = slot / texturesInAtlasX;
float startX = 1f / texturesInAtlasX * posX;
float startY = 1f / texturesInAtlasY * posY;
Normally I use this to calculate the 4 texture coordinates for a rectangle to apply a part of the atlas to it. But to the complexity of my scene forces me to simplify my meshes by calculating some faces with the same texture together into one. Normally this is not a big deal, because in OpenGL you can easily tile your texture by raising your coords above 1. But as I am using a texture atlas this can not easily be done by changing the way how the texture coords gets calculated.
My idea was to load the slot of the atlas which should be used and the size of the face to the shader and somehow tile the part of the atlas across the face. But I have absolutely no idea how to do that. As my objects are individually moving across the scene, loading the objects into one VAO per texture or batching the objects per textures together is not an option, because this absolutely kills the performance.
So my question is: Is there any feature in OpenGL which can help me tiling only parts of a texture?
opengl textures shader texture-mapping texture-atlas
I am using modern OpenGL to render a 3D scene with a texture atlas which holds all of my textures.
The texture coordinate calculation is done very simply and gets loaded into a VBO for the shader. Here is some basic calculation in pseudo code:
int posX = slot % texturesInAtlasX, posY = slot / texturesInAtlasX;
float startX = 1f / texturesInAtlasX * posX;
float startY = 1f / texturesInAtlasY * posY;
Normally I use this to calculate the 4 texture coordinates for a rectangle to apply a part of the atlas to it. But to the complexity of my scene forces me to simplify my meshes by calculating some faces with the same texture together into one. Normally this is not a big deal, because in OpenGL you can easily tile your texture by raising your coords above 1. But as I am using a texture atlas this can not easily be done by changing the way how the texture coords gets calculated.
My idea was to load the slot of the atlas which should be used and the size of the face to the shader and somehow tile the part of the atlas across the face. But I have absolutely no idea how to do that. As my objects are individually moving across the scene, loading the objects into one VAO per texture or batching the objects per textures together is not an option, because this absolutely kills the performance.
So my question is: Is there any feature in OpenGL which can help me tiling only parts of a texture?
opengl textures shader texture-mapping texture-atlas
opengl textures shader texture-mapping texture-atlas
edited Nov 26 '18 at 0:07
genpfault
42.5k954100
42.5k954100
asked Nov 25 '18 at 21:19
nik2038nik2038
1015
1015
2
"loading the objects into one VAO per texture or batching the objects per textures together is not an option, because this absolutely kills the performance" But you think changing VAOs and texture frequently will be better for performance?
– Nicol Bolas
Nov 25 '18 at 22:17
add a comment |
2
"loading the objects into one VAO per texture or batching the objects per textures together is not an option, because this absolutely kills the performance" But you think changing VAOs and texture frequently will be better for performance?
– Nicol Bolas
Nov 25 '18 at 22:17
2
2
"loading the objects into one VAO per texture or batching the objects per textures together is not an option, because this absolutely kills the performance" But you think changing VAOs and texture frequently will be better for performance?
– Nicol Bolas
Nov 25 '18 at 22:17
"loading the objects into one VAO per texture or batching the objects per textures together is not an option, because this absolutely kills the performance" But you think changing VAOs and texture frequently will be better for performance?
– Nicol Bolas
Nov 25 '18 at 22:17
add a comment |
1 Answer
1
active
oldest
votes
Ok, after hours of researching I finally found a solution for my problem.
The feature which I found is called "texture arrays" and is in core since OpenGL 3.3.
So it's safe to use and has no big impact on performance. In my case it also gave me a big performance improvment. It was also really simple to implement.
If anyone got some similar problem here is a link which explaine how texture arrays work: https://www.khronos.org/opengl/wiki/Array_Texture
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53472092%2fmodern-opengl-tiling-region-in-texture-atlas-properly-in-shader%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Ok, after hours of researching I finally found a solution for my problem.
The feature which I found is called "texture arrays" and is in core since OpenGL 3.3.
So it's safe to use and has no big impact on performance. In my case it also gave me a big performance improvment. It was also really simple to implement.
If anyone got some similar problem here is a link which explaine how texture arrays work: https://www.khronos.org/opengl/wiki/Array_Texture
add a comment |
Ok, after hours of researching I finally found a solution for my problem.
The feature which I found is called "texture arrays" and is in core since OpenGL 3.3.
So it's safe to use and has no big impact on performance. In my case it also gave me a big performance improvment. It was also really simple to implement.
If anyone got some similar problem here is a link which explaine how texture arrays work: https://www.khronos.org/opengl/wiki/Array_Texture
add a comment |
Ok, after hours of researching I finally found a solution for my problem.
The feature which I found is called "texture arrays" and is in core since OpenGL 3.3.
So it's safe to use and has no big impact on performance. In my case it also gave me a big performance improvment. It was also really simple to implement.
If anyone got some similar problem here is a link which explaine how texture arrays work: https://www.khronos.org/opengl/wiki/Array_Texture
Ok, after hours of researching I finally found a solution for my problem.
The feature which I found is called "texture arrays" and is in core since OpenGL 3.3.
So it's safe to use and has no big impact on performance. In my case it also gave me a big performance improvment. It was also really simple to implement.
If anyone got some similar problem here is a link which explaine how texture arrays work: https://www.khronos.org/opengl/wiki/Array_Texture
answered Nov 26 '18 at 20:27
nik2038nik2038
1015
1015
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53472092%2fmodern-opengl-tiling-region-in-texture-atlas-properly-in-shader%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
"loading the objects into one VAO per texture or batching the objects per textures together is not an option, because this absolutely kills the performance" But you think changing VAOs and texture frequently will be better for performance?
– Nicol Bolas
Nov 25 '18 at 22:17