RenderTexture with SteamVR differs from standard Unity camera












1















I'm currently working on a project, where I'm coloring 3d objects. The code is similar to here. Basically, I use an orthogonal camera that renders to a rendertexture, which is used as UV image in my material. In the beginning, it only "sees" a plane with a base image on it.



On painting, I create a 2d sprite at the correct position, in front of this render cam. This works fine.
Now, as Unity does not run smoothly with a lot of sprites, I try to reduce the load by combining the sprites into the base image with the Texture2D.ReadPixels() command. This new texture is then set as the new base texture. Rinse and repeat.



This approach works flawlessly if I'm using the build-in Unity camera settings. As the project is intended for VR, I ported everything into a SteamVR project.
The runtime rendering is fine as well, only the save-as-png texture function starts to break. I included the links to the different images. The first is the Base Image, second the saved with "Unity only", last the saved with SteamVR textures. I only paint green circles as sprites upon them.



As you can see, the SteamVR has several problems in comparison with the unity only version:




  1. The alpha channel is detected as black, there is no fading

  2. The overall resolution becomes.. unstable? (see the numbers, they are getting blockier)

  3. The colors from block 1, 5 and 6 are wrong


I tried different formats for the renderTexture, UV texture (RGBA, ARGB, RGB). Apart from importing the SteamVR, nothing else has changed. What am I missing?



The rendering code is as follow:



Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, false);
tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
tex.Apply();
plane.GetComponent<MeshRenderer>().material.mainTexture = tex;


Saving with



var bytes = tex.EncodeToPNG();
System.IO.File.WriteAllBytes(fullPath + fileName, bytes);


If necessary, I can upload the complete project.
Thanks for your help



Thomas










share|improve this question























  • Show the complete function where you're calling ReadPixels from

    – Programmer
    Nov 16 '18 at 16:01
















1















I'm currently working on a project, where I'm coloring 3d objects. The code is similar to here. Basically, I use an orthogonal camera that renders to a rendertexture, which is used as UV image in my material. In the beginning, it only "sees" a plane with a base image on it.



On painting, I create a 2d sprite at the correct position, in front of this render cam. This works fine.
Now, as Unity does not run smoothly with a lot of sprites, I try to reduce the load by combining the sprites into the base image with the Texture2D.ReadPixels() command. This new texture is then set as the new base texture. Rinse and repeat.



This approach works flawlessly if I'm using the build-in Unity camera settings. As the project is intended for VR, I ported everything into a SteamVR project.
The runtime rendering is fine as well, only the save-as-png texture function starts to break. I included the links to the different images. The first is the Base Image, second the saved with "Unity only", last the saved with SteamVR textures. I only paint green circles as sprites upon them.



As you can see, the SteamVR has several problems in comparison with the unity only version:




  1. The alpha channel is detected as black, there is no fading

  2. The overall resolution becomes.. unstable? (see the numbers, they are getting blockier)

  3. The colors from block 1, 5 and 6 are wrong


I tried different formats for the renderTexture, UV texture (RGBA, ARGB, RGB). Apart from importing the SteamVR, nothing else has changed. What am I missing?



The rendering code is as follow:



Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, false);
tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
tex.Apply();
plane.GetComponent<MeshRenderer>().material.mainTexture = tex;


Saving with



var bytes = tex.EncodeToPNG();
System.IO.File.WriteAllBytes(fullPath + fileName, bytes);


If necessary, I can upload the complete project.
Thanks for your help



Thomas










share|improve this question























  • Show the complete function where you're calling ReadPixels from

    – Programmer
    Nov 16 '18 at 16:01














1












1








1








I'm currently working on a project, where I'm coloring 3d objects. The code is similar to here. Basically, I use an orthogonal camera that renders to a rendertexture, which is used as UV image in my material. In the beginning, it only "sees" a plane with a base image on it.



On painting, I create a 2d sprite at the correct position, in front of this render cam. This works fine.
Now, as Unity does not run smoothly with a lot of sprites, I try to reduce the load by combining the sprites into the base image with the Texture2D.ReadPixels() command. This new texture is then set as the new base texture. Rinse and repeat.



This approach works flawlessly if I'm using the build-in Unity camera settings. As the project is intended for VR, I ported everything into a SteamVR project.
The runtime rendering is fine as well, only the save-as-png texture function starts to break. I included the links to the different images. The first is the Base Image, second the saved with "Unity only", last the saved with SteamVR textures. I only paint green circles as sprites upon them.



As you can see, the SteamVR has several problems in comparison with the unity only version:




  1. The alpha channel is detected as black, there is no fading

  2. The overall resolution becomes.. unstable? (see the numbers, they are getting blockier)

  3. The colors from block 1, 5 and 6 are wrong


I tried different formats for the renderTexture, UV texture (RGBA, ARGB, RGB). Apart from importing the SteamVR, nothing else has changed. What am I missing?



The rendering code is as follow:



Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, false);
tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
tex.Apply();
plane.GetComponent<MeshRenderer>().material.mainTexture = tex;


Saving with



var bytes = tex.EncodeToPNG();
System.IO.File.WriteAllBytes(fullPath + fileName, bytes);


If necessary, I can upload the complete project.
Thanks for your help



Thomas










share|improve this question














I'm currently working on a project, where I'm coloring 3d objects. The code is similar to here. Basically, I use an orthogonal camera that renders to a rendertexture, which is used as UV image in my material. In the beginning, it only "sees" a plane with a base image on it.



On painting, I create a 2d sprite at the correct position, in front of this render cam. This works fine.
Now, as Unity does not run smoothly with a lot of sprites, I try to reduce the load by combining the sprites into the base image with the Texture2D.ReadPixels() command. This new texture is then set as the new base texture. Rinse and repeat.



This approach works flawlessly if I'm using the build-in Unity camera settings. As the project is intended for VR, I ported everything into a SteamVR project.
The runtime rendering is fine as well, only the save-as-png texture function starts to break. I included the links to the different images. The first is the Base Image, second the saved with "Unity only", last the saved with SteamVR textures. I only paint green circles as sprites upon them.



As you can see, the SteamVR has several problems in comparison with the unity only version:




  1. The alpha channel is detected as black, there is no fading

  2. The overall resolution becomes.. unstable? (see the numbers, they are getting blockier)

  3. The colors from block 1, 5 and 6 are wrong


I tried different formats for the renderTexture, UV texture (RGBA, ARGB, RGB). Apart from importing the SteamVR, nothing else has changed. What am I missing?



The rendering code is as follow:



Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, false);
tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
tex.Apply();
plane.GetComponent<MeshRenderer>().material.mainTexture = tex;


Saving with



var bytes = tex.EncodeToPNG();
System.IO.File.WriteAllBytes(fullPath + fileName, bytes);


If necessary, I can upload the complete project.
Thanks for your help



Thomas







c# unity3d steamvr






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 16 '18 at 10:08









TSchemmerTSchemmer

133




133













  • Show the complete function where you're calling ReadPixels from

    – Programmer
    Nov 16 '18 at 16:01



















  • Show the complete function where you're calling ReadPixels from

    – Programmer
    Nov 16 '18 at 16:01

















Show the complete function where you're calling ReadPixels from

– Programmer
Nov 16 '18 at 16:01





Show the complete function where you're calling ReadPixels from

– Programmer
Nov 16 '18 at 16:01












0






active

oldest

votes












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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53335566%2frendertexture-with-steamvr-differs-from-standard-unity-camera%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53335566%2frendertexture-with-steamvr-differs-from-standard-unity-camera%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python