Hey,
I wanted to know if there is a way to use stereoscopic cubemaps in playcanvas for use in VR/XR?
I was thinking about a per Eye layer to use a different mapped sphere on each layer and display the corresponding cubemap. But I don’t know if this can be achieved.
Hmmm, I’ve not come across this myself. There’s no layer on a per eye level on the public API level. You may have to start digging into the engine internals at that point
Thanks, although almost a year later I came back here and implemented a shader chunk as @mvaligursky suggested. I figured this might be helpful for someone trying to do the same:
// Define the texture to use for the left eye
uniform sampler2D _leftTexture;
// Define the texture to use for the right eye
uniform sampler2D _rightTexture;
uniform bool _singleImage;
uniform vec3 _viewDir;
uniform vec3 _viewPos;
void getEmission() {
vec2 uv = $UV;
vec4 textureColor;
if(_singleImage){
uv.y = uv.y * 0.5;
}
// use reference position and calc vector to viewpos
vec3 vectorAB = view_position - _viewPos;
// Calculate the cross product between the direction vector and the vector formed by the two positions
vec3 cross = cross(_viewDir, vectorAB);
if (cross.y > 0.0) {
// position is to the left of the direction
textureColor = texture2D(_leftTexture, uv);
} else {
// position is to the right of the direction
if(_singleImage){
uv.y += 0.5;
textureColor = texture2D(_leftTexture, uv);
} else {
textureColor = texture2D(_rightTexture, uv);
}
}
dEmission = textureColor.rgb;
}