Stencil buffer - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

Stencil buffer

Description:

D3DSTENCILOP_INCRSAT Increment the stencil-buffer entry, clamping to the maximum value. D3DSTENCILOP_DECRSAT Decrement the stencil-buffer entry, clamping to zero ... – PowerPoint PPT presentation

Number of Views:64
Avg rating:3.0/5.0
Slides: 10
Provided by: Jac86
Category:

less

Transcript and Presenter's Notes

Title: Stencil buffer


1
Stencil buffer
2
Introducción
  • Es un buffer offscreen de la misma resolución que
    el backbuffer y el z-buffer
  • Sirve para bloquear la llegada de pixels al
    backbuffer
  • Funcionamiento similar al sistema de blending
    (posibilidad de muchas combinaciones)
  • Aplicaciones
  • Espejos
  • Stencil shadows
  • Efectos especiales

3
Inicialización
  • Al inicializar Direct3D hay que inicializar el
    Stencil buffer (en el momento en el que se
    inicializan otros buffers, como el Z-buffer)
  • De hecho, el Stencil y el Z-buffer comparten la
    misma superficie en memoria unos bits se dedican
    al primero, y otros al segundo
  • Se inicializa en el evento de DXUT
    ModifyDeviceSettings
  • pDeviceSettings-gtd3d9.pp.AutoDepthStencilFormat
    D3DFMT_D24S8
  • Durante el renderizado, se podrá habilitar,
    deshabilitar y borrar (poner a un cierto valor)
  • SetRenderState( D3DRS_STENCILENABLE, true/false )
  • Clear( 0, 0, D3DCLEAR_TARGET D3DCLEAR_ZBUFFER
    D3DCLEAR_STENCIL, 0xffffffff, 1.0f, 0 )

4
Formatos
  • Existen varias combinaciones posibles. Algunas
    son
  • D3DFMT_D32 32-bit z-buffer bit depth
  • D3DFMT_D15S1 16-bit z-buffer bit depth where 15
    bits are reserved for the depth channel and 1 bit
    is reserved for the stencil channel
  • D3DFMT_D24S8 32-bit z-buffer bit depth using 24
    bits for the depth channel and 8 bits for the
    stencil channel.
  • D3DFMT_D24X8 32-bit z-buffer bit depth using 24
    bits for the depth channel.
  • D3DFMT_D24X4S4 32-bit z-buffer bit depth using 24
    bits for the depth channel and 4 bits for the
    stencil channel.

5
Stencil test
  • IF ref mask OP value mask trueTHEN
    aceptar pixel ELSE descartar pixel
  • Ref valor de referencia. Por defecto es 0, pero
    se puede cambiar
  • SetRenderState( D3DRS_STENCILREF, 0x1 )
  • Mask máscara que se aplica con AND para
    bloquear ciertos bits. Por defecto no bloquea
    nada (0xffffffff) pero se puede modificar
  • SetRenderStat( D3DRS_STENCILMASK, 0x000000ff )
  • Value valor del pixel (i,j) en el stencil buffer

6
  • OP operador de comparación
  • D3DCMP_NEVER Always fail the test
  • D3DCMP_LESS Accept the new pixel if its value is
    less than the value of the current pixel
  • D3DCMP_EQUAL Accept the new pixel if its value
    equals the value of the current pixel
  • D3DCMP_LESSEQUAL Accept the new pixel if its
    value is less than or equal to the value of the
    current pixel
  • D3DCMP_GREATER Accept the new pixel if its value
    is greater than the value of the current pixel
  • D3DCMP_NOTEQUAL Accept the new pixel if its value
    does not equal the value of the current pixel
  • D3DCMP_GREATEREQUAL Accept the new pixel if its
    value is greater than or equal to the value of
    the current pixel
  • D3DCMP_ALWAYS Always pass the test.

7
Como actualizar el stencil buffer
  • Si falla el stencil test, se puede actualizar
    con
  • SetRenderState( D3DRS_STENCILFAIL, operation )
  • Si falla el z-test
  • SetRenderState( D3DRS_STENCILZFAIL, operation )
  • Si pasa ambos test
  • SetRenderState( D3DRS_STENCILPASS, operation )
  • Operation puede ser

8
Operaciones
  • Operation
  • D3DSTENCILOP_KEEP Do not update the entry in the
    stencil buffer. This is the default value
  • D3DSTENCILOP_ZERO Set the stencil-buffer entry to
    0
  • D3DSTENCILOP_REPLACE Replace the stencil-buffer
    entry with a reference value
  • D3DSTENCILOP_INCRSAT Increment the stencil-buffer
    entry, clamping to the maximum value
  • D3DSTENCILOP_DECRSAT Decrement the stencil-buffer
    entry, clamping to zero
  • D3DSTENCILOP_INVERT Invert the bits in the
    stencil-buffer entry
  • D3DSTENCILOP_INCR Increment the stencil-buffer
    entry, wrapping to zero if the new value exceeds
    the maximum value
  • D3DSTENCILOP_DECR Decrement the stencil-buffer
    entry, wrapping to the maximum value if the new
    value is less than zero
  • Tambien existe una máscara que controla la
    escritura
  • SetRenderState( D3DRS_STENCILWRITEMASK,
    0x000000ff )

9
Ejemplo
  • Se dibuja una primitiva con los siguientes
    valores
  • SetRenderState( D3DRS_STENCILENABLE, true )
  • SetRenderState( D3DRS_STENCILFUNC, D3DCMP_ALWAYS
    )
  • SetRenderState( D3DRS_STENCILREF, 0x1 )
  • SetRenderState( D3DRS_STENCILMASK, 0xffffffff )
  • SetRenderState( D3DRS_STENCILZFAIL,
    D3DSTENCILOP_KEEP )
  • SetRenderState( D3DRS_STENCILFAIL,
    D3DSTENCILOP_KEEP )
  • SetRenderState( D3DRS_STENCILPASS,
    D3DSTENCILOP_REPLACE )
  • Renderizar geometría para escribir en el stencil
    buffer
  • Lo que se dibuje después se puede forzar a que no
    se salga de la superficie que se renderizó en la
    pasada anterior
  • SetRenderState( D3DRS_STENCILENABLE, true )
  • SetRenderState( D3DRS_STENCILFUNC, D3DCMP_EQUAL
    )
  • SetRenderState( D3DRS_STENCILPASS,
    D3DSTENCILOP_KEEP )
  • Renderizar la nueva geometría
Write a Comment
User Comments (0)
About PowerShow.com