You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(putting it here so that there is a single place I can refer to).
This is what the final location card looks like.
The way I render cards is to load them up in Unity, then take a screenshot:
public IEnumerator CaptureScreenshot(
GameObject targetObject, string destPath, int width = 500, int height = 650, int targetWidth = 512, int startX = 617, int startY = 310)
{
yield return new WaitForEndOfFrame();
captureCamera.cullingMask = 1 << targetObject.layer; // Only render the layer the target object is on
RenderTexture renderTexture = new RenderTexture(Screen.width, Screen.height, 24);
captureCamera.targetTexture = renderTexture;
captureCamera.Render();
RenderTexture.active = renderTexture;
Texture2D tex = new Texture2D(width, height, TextureFormat.ARGB32, false);
Rect rex = new Rect(startX, startY, Math.Min(Screen.width - startX, width), Math.Min(Screen.height - startY, height));
tex.ReadPixels(rex, 0, 0);
tex.Apply();
// Calculate new height to maintain aspect ratio
float aspectRatio = (float)height / width;
int targetHeight = Mathf.RoundToInt(targetWidth * aspectRatio);
// Scale the captured texture
Texture2D scaledTex = ScaleTexture(tex, targetWidth, targetHeight);
var bytes = scaledTex.EncodeToPNG();
File.WriteAllBytes(destPath, bytes);
// Clean up
captureCamera.targetTexture = null;
RenderTexture.active = null;
Destroy(renderTexture);
Destroy(scaledTex);
Destroy(tex);
}
When the object is displayed in-game, it looks correct, with all its parts properly rendered, but the issue comes when rendering it to a texture with transparency.
If, instead of TextureFormat.ARGB32 I use a format without transparency, like TextureFormat.RGB24, it renders correctly (though obviously without a transparent background, which is an issue).
Moreover, looking at the texture files, this is what it looks like with the alpha channel off:
When turning the alpha channel on:
The missing part clearly corresponds to the part in the texture where the alpha channel is set.
So what I'm looking for now is:
can I turn off transparency altogether in my game objects?
since this happens only when rendering to a texture, and not with the in-game camera, maybe there is a way to tune the camera to ignore this transparency setting (but while keeping the transparent background).
The text was updated successfully, but these errors were encountered:
(putting it here so that there is a single place I can refer to).
This is what the final location card looks like.
The way I render cards is to load them up in Unity, then take a screenshot:
When the object is displayed in-game, it looks correct, with all its parts properly rendered, but the issue comes when rendering it to a texture with transparency.
If, instead of
TextureFormat.ARGB32
I use a format without transparency, likeTextureFormat.RGB24
, it renders correctly (though obviously without a transparent background, which is an issue).Moreover, looking at the texture files, this is what it looks like with the alpha channel off:
When turning the alpha channel on:
The missing part clearly corresponds to the part in the texture where the alpha channel is set.
So what I'm looking for now is:
The text was updated successfully, but these errors were encountered: