cancel
Showing results for 
Search instead for 
Did you mean: 

Oculus GO / glsl "return" in braces does not quit the current function - instead quits the scope

Anonymous
Not applicable
Hi guys,

glsl 3.1.
Oculus GO (only)

Sounds super weird, but it seems that the very normal "return" from a shader function doesnt actually quit the function - it just quits the current scope. This is the case for both vertex shaders and fragment shaders.

I tested this both on Oculus GO and a Gear VR with a Samsung Galaxy 7  -  return misbehaves on the Oculus GO only and works as intended on the Samsung Galaxy S7.

So a construct like this does nothing.
{ return; }

This code jumps leaves v3 at 1,1,1:
{
v3 = vec3(1,1,1);
return; // just leaves the scope...
v3 = vec3(0,0,0);   // this is not executed but the shader continues after the braces
}
... // continues here, setting
v3 = v3 + vec3(1,1,1); // v3 is 2,2,2 now


This is my header for the shaders:

#version 310 es

#if defined(GL_EXT_texture_cube_map_array)
#extension GL_EXT_texture_cube_map_array : enable
#endif

#if defined( GL_OVR_multiview2 )
#extension GL_OVR_multiview2 : enable
#else
#define gl_ViewID_OVR 0
#endif

precision mediump float;
precision mediump samplerCubeArray;


Can anybody confirm this?

5 REPLIES 5

Anonymous
Not applicable
Sure - use your very own VRCubeWorld - example to test it.

Replace the fragment-shader in VRCubeWorld_NativeActivity.c (Line 756) from:
static const char FRAGMENT_SHADER[] =
    "in lowp vec4 fragmentColor;\n"
    "out lowp vec4 outColor;\n"
    "void main()\n"
    "{\n"
    "    outColor = fragmentColor;\n"
    "}\n";

... tothis here:
static const char FRAGMENT_SHADER[] =
"in lowp vec4 fragmentColor;\n"
"out lowp vec4 outColor;\n"
"void main()\n"
"{\n"
" outColor = vec4(1.0,1.0,1.0,1.0);\n"
" { return; } \n"
" outColor = fragmentColor;\n"
"}\n";

This shader should output pure white cubes then, but it doesnt - the cubes are still vertex-colored. The { return; } has no effect.


Anonymous
Not applicable
yay, glad i could help.

Chartres965
Honored Guest
I want to make both rifts display in same view at same time.
I have 2 Oculusrifys device and 2 PCs. I wanna 2 Oculus Rift show the same Unity Project.
but I don't wanna develop networking,because the synchronization is complicated.
Please tell me, How to do that??? Thanks!

Chartres965
Honored Guest
I want to make both rifts display in same view at same time.
I have 2 Oculusrifys device and 2 PCs. I wanna 2 Oculus Rift show the same Unity Project.
but I don't wanna develop networking,because the synchronization is complicated.
Please tell me, How to do that??? Thanks!

Chartres965
Honored Guest
I want to make both rifts display in same view at same time.
I have 2 Oculusrifys device and 2 PCs. I wanna 2 Oculus Rift show the same Unity Project.
but I don't wanna develop networking,because the synchronization is complicated.
Please tell me, How to do that?? Mobdro? Thanks!