glsl highp mediump varying inconsistency ?

491 views
Skip to first unread message

Evgeny Demidov

unread,
May 25, 2017, 2:47:12 AM5/25/17
to webgl-d...@googlegroups.com
at
https://webglfundamentals.org/webgl/lessons/webgl-shaders-and-glsl.html#varyings
(and in all my shaders :)
In the vertex shader varyings have default highp precision (e.g. varying
vec4 v_positionWithOffset) but in the fragment shader they are mediump
floats
precision mediump float;
varying vec4 v_positionWithOffset;
How does it works? Shall (can) I declare in the vertex shader
varying mediump vec4 v_positionWithOffset;
and (just curious) can I sum in the vertex shader
v_positionWithOffset = a_position + u_offset;
as mediump floats?

Evgeny Demidov

Cătălin George Feștilă

unread,
May 25, 2017, 12:08:06 PM5/25/17
to webgl-d...@googlegroups.com
I don't know this website , but is very good to start it.
About precision mediump float declarations and functions used by shaders  I know has some changes ito specs 

You can find some ideas here: 



Evgeny Demidov

--
You received this message because you are subscribed to the Google Groups "WebGL Dev List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webgl-dev-list+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kirill Dmitrenko

unread,
May 26, 2017, 5:36:28 AM5/26/17
to WebGL Dev List
Doesn't seem so according to specs. GLSL 1.0 spec defines link error if varying **types** mismatch (11.4). However, 4.5.2 says "Precision qualifiers, as with other qualifiers, do not effect the basic type of the variable." Thus, a program with varyings with different precision qualifiers, but same types, should link successfully. More over, same precisions qualifiers on different pipeline stages may provide different precision (threre's nothing in the spec preventing implementations from doing that). Also, varying aren't passed from vertex stage directly to fragment stage but rather go through fixed-function hardware that most probably doesn't recognise precision qualifiers at all.

четверг, 25 мая 2017 г., 9:47:12 UTC+3 пользователь Evgeny написал:

Kenneth Russell

unread,
May 31, 2017, 11:01:58 PM5/31/17
to WebGL Dev List
The precisions of varyings can differ between the vertex and fragment shader. See the section "Precision Qualifiers" in the OpenGL ES Shading Language 1.00 specification at https://www.khronos.org/registry/OpenGL/index_es.php .

If your vertex shader is running with good performance using the default highp precision, I would recommend not changing it.

On the other hand, to work on the broadest range of mobile GPUs, it's best to use mediump precision in the fragment shader. highp support is mandated as of OpenGL ES 3.0 (WebGL 2.0), but still, using reduced precision will probably perform better on a broader range of GPUs.

The precisions of uniform variables shared across the vertex and fragment shader must match. This is defined in the ES 2.0 spec.

-Ken



--
Reply all
Reply to author
Forward
0 new messages