Graphics Reference
In-Depth Information
5.3.5 Sampler Configuration
The above shader works fine when setting the samplers' wrap modes to GL_CLAMP
_TO_EDGE and when using textures that have a fully transparent border. If this
is not the case (or if repeat mode is required), the shader must take care of
discarding the layer contribution if it falls out of the accepted range. The following
is an example on how to discard values outside the [0 . 0 , 1 . 0] range.
contribution =
texture2D ( Textures [ i ], vTextureCoordinates [ i ]);
result = contribution +( 1.0
contribution . a ) ￿ result ;
result ￿ = step (0.0, vTextureCoordinates [ i ]. x );
result ￿ = step ( vTextureCoordinates [ i ]. x ,1.0);
result ￿ = step (0.0, vTextureCoordinates [ i ]. y );
result ￿ = step ( vTextureCoordinates [ i ]. y ,1.0);
5.3.6 Simulating Depth
If depth testing is required, it needs to be handled manually because we are now
rendering screen-space tiles. After binding the depth texture and sampling it in
the fragment shader, it is now possible to compare the depth value to each tile's
depth (passed in as an extra vertex attribute) in order to modulate the inter-
mediate results using a call to step() . Compared to regular blending, the depth
buffer needs to be sampled only once per pixel (per screen-space tile affecting it)
instead of once per primitive.
mediump float depth ;
depth = texture2D ( DepthTexture , tileTextureCoordinates . xy );
// . . .
contribution =
texture2D ( Textures [ i ], vTextureCoordinates [ i ]);
result = contribution +( 1.0
contribution . a ) ￿
result ;
result ￿ = step ( vTextureCoordinates [ i ]. z , depth );
Using gl_FragCoord to compute the coordinates to sample the depth textures
would result in a dependent texture fetch; a better solution consists of passing
the screen-space coordinates as varyings.
From here, we can get soft particles almost for free by using an alpha ramp
instead of the previous step() function.
For all this to work, the device must of course support depth textures ( OES_
depth_texture extension).
Search WWH ::




Custom Search