Point sprite support

182 views
Skip to first unread message

Kenneth Russell

unread,
Apr 6, 2010, 4:47:11 PM4/6/10
to anglep...@googlegroups.com
TransGaming team (in particular),

A couple of questions about being able to support point sprites in
ANGLE. Looking back at the writeup on D3D / OpenGL caveats from the
recent Khronos F2F, there is a statement that because of differences
in interpolation semantics between D3D and OpenGL, either point
sprites need to be implemented as a pair of triangles in ANGLE, or the
point size needs to be limited to 1.

The point sprite documentation in Direct3D 9 (
http://msdn.microsoft.com/en-us/library/bb147281(v=VS.85).aspx )
indicates that if D3DRS_POINTSPRITEENABLE is set to true, then the
values that come in to the fragment shader via TEXCOORD[n] will be
interpolated between (0,0) and (1,1). However, it states that the
vertex color attributes are constant across the sprite.

It seems to me that it should be possible to implement point sprites
with size > 1, support gl_PointSize and gl_PointCoord, and support the
transfer of the user's varying variables between the vertex and
fragment programs (though these will of course be constant across the
surface of the sprite). In the GLSL to HLSL translation, simply
transfer the user's varyings (and, basically, everything except
gl_PointCoord) in the COLOR[n] units. Enable D3DRS_POINTSPRITEENABLE
and synthesize gl_PointCoord from TEXCOORD[0]. A write to gl_PointSize
is translated to a write to PSIZE.

Will this work? I'd like to figure out whether WebGL authors can
reasonably expect point sprites with size > 1 to work without doing
expensive hacks behind the scenes like translating point sprites to
quads ourselves.

Thanks,

-Ken

Daniel Koch

unread,
Apr 7, 2010, 1:05:50 AM4/7/10
to k...@chromium.org, anglep...@googlegroups.com
Hi Ken,

This is mostly correct, however it fails to account for the one fundamental difference between the OpenGL ES and Direct3D point sprites: the origin of the point sprites.  Because of this difference,  the point sprite's t-coordinate increases in opposite directions between D3D and GLES.  Desktop GL (2.0 and higher, but not in ARB_point_sprite) helpfully includes a POINT_SPRITE_COORD_ORIGIN control which can be used toggle the origin between UPPER_LEFT and LOWER_LEFT.  When porting D3D content to OpenGL this value needs to be set to LOWER_LEFT.  Unfortunately, without the control, the OpenGL (and thus GLES) default is UPPER_LEFT.  Direct3D9 doesn't have a control for this either.

To illustrate (in consistent notation, since it is easy to get confused between the D3D diagram and OpenGL spec language):

Open GL 2.0 w/  UPPER_LEFT, ARB_point_sprite, and ES 2.0
              ^
            +y| (0,0)
              |   +-----+
              |   |     |   
              |   |  P  |   
              |   |     |
              |   +-----+
              |       (1,1)
              |              +x
              O--------------->

Open GL 2.0 w/ LOWER_LEFT
(based on §3.4.1 of the GL 3.3 core spec)
              ^
            +y|       (1,1)
| +-----+ | | | | | P | | | | | +-----+ | (0,0) | +x O--------------->

Direct3D 9
+x
              O--------------->
              |
              | (0,0)
| +-----+ | | | | | P | | | | | +-----+ +y| (1,1)
                            \/


Due to this difference, any ES/WebGL application which uses non-vertically-symmetric textures for sprites will have up-side down point sprites, if ANGLE were to use the built-in D3D9 point-sprites.

Can WebGL authors can rely on having point sprites with size > 1?  I would say that they cannot, regardless of what ANGLE implements.  Technically, a maximum point size of 1 is all that is mandated by the ES 2.0 specification (see Section 3.3, and Table 6.17), thus that is all that WebGL can actually rely on being available by any ES implementation (or Desktop GL for that matter).

Our plan for ANGLE is to initially support a maximum point size of 1.0 (and this is already completed already).  At a later point this can be extended to draw quads if larger points are desired. 

Hope this helps,
Daniel

---
      Daniel Koch -+-  dan...@transgaming.com 
Graphics Technology Lead -+- TransGaming Inc.  -+- www.transgaming.com

Kenneth Russell

unread,
Apr 7, 2010, 3:18:35 PM4/7/10
to Daniel Koch, anglep...@googlegroups.com

ANGLE needs to convert the entire GLSL shader to HLSL anyway. During
this process it seems to me that it should be possible to synthesize
the value for gl_PointCoord as float2(texCoord0.x, 1.0 - texCoord0.y).
Wouldn't this solve the problem and allow D3D's built-in point sprites
to be used?

> Can WebGL authors can rely on having point sprites with size > 1?  I would
> say that they cannot, regardless of what ANGLE implements.  Technically, a
> maximum point size of 1 is all that is mandated by the ES 2.0 specification
> (see Section 3.3, and Table 6.17), thus that is all that WebGL can actually
> rely on being available by any ES implementation (or Desktop GL for that
> matter).

Understood, but a high quality implementation will allow the use of
larger point sprites if the hardware supports it. Authors should query
the ALIASED_POINT_SIZE_RANGE.

> Our plan for ANGLE is to initially support a maximum point size of 1.0 (and
> this is already completed already).  At a later point this can be extended
> to draw quads if larger points are desired.

See above regarding question of whether it is necessary to draw quads
in order to emulate larger point sprites. I don't think it is.

-Ken

Daniel Koch

unread,
Apr 8, 2010, 4:43:19 PM4/8/10
to Kenneth Russell, anglep...@googlegroups.com
Hi Ken,

After examining this further, I believe you are correct that this could be handled in the shaders without generating quads.  I thought there was still some aspect which wouldn't be handled correctly, but I was getting side-tracked by some of the properties of fixed function point sprites which aren't necessary for OpenGL ES.  There are a couple of other considerations to factor in for the shader modifications, and we'll have to work with on scheduling details, but this seems like a good approach.

Thanks,
Daniel

Senior Graphics Architect -+- TransGaming Inc.  -+- www.transgaming.com

Kenneth Russell

unread,
Apr 8, 2010, 4:59:50 PM4/8/10
to Daniel Koch, anglep...@googlegroups.com
Thanks for reexamining this. It's great to hear that you think it's
implementable this way. Performance will be good and developers will
be able to make cool particle systems. The scheduling of the work is
of course at your discretion; no rush.

-Ken
--
Subscription settings: http://groups.google.com/group/angleproject/subscribe?hl=en
Reply all
Reply to author
Forward
0 new messages