Knowledge (XXG)

Stencil buffer

Source 📝

690:
number of lights but does not address the number of areas on which the shadows fall. There are several solutions to the problem, but we followed the following algorithm: 1. Draw a scene without light 2. Lock the Z-buffer and color buffer, so that the two can not make changes For each light 1. Using in-depth information about the scene (Z-buffer) to fill the stencil buffer only on parts of the scene where volume shadow does not exist or are not visible from the existing buildings. 2. Unlock buffer for color, and adjust the function of the Z-buffer to allow amendments only where the depth value equal to an existing 3. Draw the scene illuminated only by this light, but only for part of the scene passing the stencil test
677:
directly used, it is a far more elegant implementation using the stencil buffer: 1. Enable lights and the lights 2. Draw a scene without any polygon that should be projected shadows 3. Draw all polygons which should be projected shadows, but without lights. In doing so, the stencil buffer, the pixel of each polygon to be assigned to a specific value for the ground to which they belong. The distance between these values should be at least two, because for each plane to be used two values for two states: in the shadows and bright. 4. Disable any
63: 330: 681:(to ensure that the next steps will affect only individual selected light) For each plane: For each light: 1. Edit a stencil buffer and only the pixels that carry a specific value for the selected level. Increase the value of all the pixels that are projected objects between the date of a given level and bright. 2. Allow only selected light for him to draw level at which part of her specific value was not changed. 167: 22: 382: 269: 859:
If say func is GL_ALWAYS, the stencil test will always pass, but depth test may fail. Neither Color/Z-buffer are modified. The stencil buffer is modified as per glStencilOp zfail. If say glStencilOp(GL_KEEP, GL_INCR, GL_KEEP) then GL_INCR takes place and stencilValue = (stencilValue+1) // will
672:
While drawing a plane of shadows, there are two dominant problems: The first concerns the problem of deep struggle in case the flat geometry is not awarded on the part covered with the shadow of shadows and outside. See the section that relates to this. Another problem relates to the extent of the
563:
Due to the lack of precision in the Z-buffer, coplanar polygons that are short-range, or overlapping, can be portrayed as a single plane with a multitude of irregular cross-sections. These sections can vary depending on the camera position and other parameters and are rapidly changing. This is called
502:
The bits allocated to the stencil buffer can be used to represent numerical values in the range , and also as a Boolean matrix (n is the number of allocated bits), each of which may be used to control the particular part of the scene. Any combination of these two ways of using the available memory is
498:
The stencil buffer typically shares the same memory space as the Z-buffer, and typically the ratio is 24 bits for Z-buffer + 8 bits for stencil buffer or, in the past, 15 bits for Z-buffer + 1 bit for stencil buffer. Another variant is 4 + 24, where 28 of the 32 bits are used and 4 ignored. Stencil
866:
If say func is GL_ALWAYS, the stencil test will always pass. If the depth test also passes. Both Color/Z-buffer are modified. The stencil buffer is modified as per glStencilOp zpass. If say, glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP) then Stencil values are not changed, only Color and Z-buffers are
852:
If say func is GL_NEVER, the stencil test will always fail. Neither Color/Z-buffers are modified. The stencil buffer is modified as per glStencilOp fail. If say glStencilOp(GL_REPLACE, GL_KEEP, GL_KEEP) then GL_REPLACE takes place and stencilValue = (ref & stencilMask) // will become
522:
The test itself is carried out over the stencil buffer to some value in it, or altered or used it, and carried out through the so-called stencil function and stencil operations. The stencil function is a function by which the stencil value of a certain pixel is compared to a given reference value.
689:
Stencil buffer implementation of spatial drawing shadows is any shadow of a geometric body that its volume includes part of the scene that is in it. If any part of the scene belongs to this volume, light is not illuminated given, otherwise it is. This problem is compounded by the increase in the
676:
Another problem, which may or may not appear, depending on the technique, the design of more polygons in one part of the shadow, resulting in darker and lighter parts of the same shade. All three problems can be solved geometrically, but because of the possibility that hardware acceleration is
385:
In this image, there are white regions and black regions, representing 1s and 0s in the stencil buffer respectively. Shapes are then drawn on top of the stripes by inverting the value of the stencil buffer. If the buffer at that pixel has a value of 0 (black), color the pixel white (1) and vice
705:
A further example is the so-called soft shadow, in which the transition between the illuminated and shadowed part of the scene is out of focus. Specifically, one way to achieve this effect stencil buffer is to multiply the volume of the shadow, and that as the copies, respectively are scaled
548:
Stencil operations in OpenGL adjust glStencilOp function that expects three values. In Direct3D, again, each state sets a specific method SetRenderState. The three states that can be assigned to surgery are called D3DRS_STENCILFAIL, D3DRENDERSTATE_STENCILZFAIL, and D3DRENDERSTATE_STENCILPASS.
544:
For each of these cases can be set different operations over the examined pixel. In the OpenGL stencil functions, the reference value and mask, respectively, define the function glStencilFunc. In Direct3D each of these components is adjusted individually using methods SetRenderState devices
696:
As for the shadows, this technique can be used to illuminate parts of space that are under strong light. For example, the brightness of the spotlight in a dark room with a large presence of dust in the air could be seen illuminating the appropriate volume of space.
706:
according to a geometric series with a low magnification, e.g.,. 1.04. The Center of scaling can be the center of gravity of the polygon that represents the top volume. This in itself will give a series of composite shadows that give the desired effect.
545:
currently in control. This method expects two parameters, the first of which is a condition that is set and the other its value. In the order that was used above, these conditions are called D3DRS_STENCILFUNC, D3DRS_STENCILREF, and D3DRS_STENCILMASK.
93: 107:, is a useful starting point for translations, but translators must revise errors as necessary and confirm that the translation is accurate, rather than simply copy-pasting machine-translated text into the English Knowledge (XXG). 630:
of a scene is drawn as the scene itself transformed and reflected relative to the "mirror" plane, which requires multiple render passes and using of stencil buffer to restrict areas where the current render pass works:
605:
The stencil buffer implementation of shadow volumes is generally considered among the most practical general-purpose real-time shadowing techniques for use on modern 3D graphics hardware. It has been popularised by the
519:. The stencil test ensures undesired pixels do not reach the depth test. This saves processing time for the scene. Similarly, the alpha test can prevent corresponding pixels to reach the stencil test. 602:
in 1977 as the geometry describing the 3D shape of the region occluded from a light source. A shadow volume divides the virtual world in two: areas that are in shadow and areas that are not.
870:
Typically Stencil buffer is initialized by setting Z-buffer and color buffer masks to false. and then setting appropriate ref value to stencil buffer by failing the stencil test every time.
583:
of the front polygon is drawn into the stencil buffer. After that, the rest of the scene can be rendered only where the silhouette is negative, and so will not clash with the front polygon.
499:
and Z-buffers are part of the frame buffer, coupled to the color buffer. The first chip available to a wider market was 3Dlabs' Permedia II, which supported a one-bit stencil buffer.
576:
All of these approaches to the problem can only reduce the likelihood that the polygons will experience Z-fighting, and do not guarantee a definitive solution in the general case.
567:- Bring the far plane closer to restrict the scene's depth, thus increasing the accuracy of the Z-buffer, or reducing the distance at which objects are visible in the scene. 467:, use the stencil buffer in other ways; for example, it can be used to find the area of the screen obscured by a portal and re-render those pixels correctly. 449:
volumes, Two-Sided Stencil, compositing, decaling, dissolves, fades, swipes, silhouettes, outline drawing, or highlighting of intersections between complex
110:
Do not translate text that appears unreliable or low-quality. If possible, verify the text with references provided in the foreign-language article.
658:
Draw the scene, but only the part of it that lies between the mirror plane and the camera. In other words, a mirror plane is also a clipping plane
118: 75: 438:(stenciling). More advanced usage of the stencil buffer makes use of the strong connection between the Z-buffer and the stencil buffer in the 471: 368: 311: 250: 49: 573:- Move polygons farther apart from one another, which restricts the possibilities for the artist to create an elaborate scene. 293: 184: 35: 627: 579:
A solution that includes the stencil buffer is based on the knowledge of which polygon should be in front of the others. The
442:. For example, stencil values can be automatically increased/decreased for every pixel that fails or passes the depth test. 231: 188: 570:- Increase the number of bits allocated to the Z-buffer, which is possible at the expense of memory for the stencil buffer. 203: 131:
Content in this edit is translated from the existing Serbian Knowledge (XXG) article at ]; see its history for attribution.
435: 339: 284: 710: 210: 1015:
Now use the initialized stencil buffer and stencil test to write only in the locations where the stencil value is 1:
530:
In doing so, the possible reaction caused by the result of comparing three different state-depth and stencil buffer:
511:
Stencil test or stenciling is among the operations on the pixels/fragments (Per-pixel operations), located after the
453:) though they often require several rendering passes and, therefore, can put a heavy load on the graphics hardware. 1187: 445:
The simple combination of depth test and stencil modifiers make a vast number of effects possible (such as stencil
1154: 177: 217: 649:
Depth test is set so that it passes only if the distance of a pixel is less than the current (default behavior)
126: 147: 199: 1192: 661:
Again locks color buffer, depth test is set so that it always passes, reset stencil for the next mirror.
713:(CSG), wherein stencil buffer, together with the Z-buffer, can successfully solve the problems of the 595: 457: 428: 279: 678: 450: 140: 41: 709:
Another implementation includes the field of visualization during the modeling technique solids
1083:// stencil test: only pass stencil test at stencilValue == 1 (Assuming depth test would pass.) 1010:// at stencil shape pixel locations in stencil buffer replace stencil buffer values to ref = 1 714: 641:
Depth test is set up so that each pixel is passed to enter the maximum value and always passes
512: 439: 412: 122: 1001:// first clear stencil buffer by writing default stencil value (0) to all of stencil buffer. 599: 464: 224: 635:
Draw the scene excluding mirror areas – for each mirror lock the Z-buffer and color buffer
346:
Please help update this article to reflect recent events or newly available information.
524: 1086:// and write actual content to depth and color buffer only at stencil shape locations. 652:
The matrix transformation is changed to reflect the scene relative to the mirror plane
1181: 1133: 616: 591: 615:, and a particular variation of the technique used in this game has become known as 846:
Depending on the three possible conditions of the stencil function/depth function.
483: 470:
The stencil buffer and its modifiers can be accessed in computer graphics by using
1127: 487: 424: 407: 398: 166: 540:
Both tests are passed (or stencil test is passed, and the depth is not enabled)
607: 580: 558: 516: 381: 479: 838:// clear stencil buffer, fill with (clearStencilValue & stencilMask) 693:
Each of these passages implies that a clean stencil buffer can be used.
416: 392: 129:
to the source of your translation. A model attribution edit summary is
434:
In the simplest case, the stencil buffer is used to limit the area of
823:// by default GL_KEEP, GL_KEEP, GL_KEEP, do not change stencil buffer 611: 475: 446: 289:
The article does not clearly explain the concept of a stencil buffer.
1080:// can also be achieved by glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); 1065:// no more modifying of stencil buffer on stencil and depth pass. 598:
to add shadows to a rendered scene. They were first proposed by
420: 104: 754:// allow writing to stencil buffer, by default (0xFF) no mask. 323: 262: 160: 56: 15: 1167:
Crow, Franklin C: "Shadow Algorithms for Computer Graphics",
856:
2. Stencil Test Function passes/Depth Test Function fails:
796:// by default GL_ALWAYS, 0, 0xFF, always pass stencil test 564:
Z-fighting. There exist multiple solutions to this issue:
843:
Test: ( ref & mask ) func (stencilValue & mask)
456:
The most typical application is still to add shadows to
1155:"Stencil Buffer Techniques (Direct3D 9) - Win32 apps" 427:
and stencil buffer often share the same area in the
100: 96:
a machine-translated version of the Serbian article.
863:3. Stencil Function passes/Depth Function passes: 191:. Unsourced material may be challenged and removed. 342:may be compromised due to out-of-date information 673:shadows outside the area where the plane there. 125:accompanying your translation by providing an 87:Click for important translation instructions. 74:expand this article with text translated from 1136:(a stencil buffer technique creating shadows) 537:Stencil test is passed but not the depth test 8: 1169:Computer Graphics (SIGGRAPH '77 Proceedings) 50:Learn how and when to remove these messages 527:, the stencil test passes. Otherwise not. 460:. It is also used for planar reflections. 971:// replace stencil buffer values to ref=1 369:Learn how and when to remove this message 312:Learn how and when to remove this message 251:Learn how and when to remove this message 380: 1146: 415:. The buffer is per pixel and works on 769:// clear stencil value, by default = 0 7: 655:Unlock the Z-buffer and color buffer 463:Other rendering techniques, such as 419:values, usually with a depth of one 189:adding citations to reliable sources 14: 849:1. Stencil Test Function fails: 638:Render visible part of the mirror 31:This article has multiple issues. 328: 267: 165: 61: 20: 986:// stencil buffer free to write 176:needs additional citations for 137:{{Translated|sr|¿¿¿¿¿¿¿_¿¿¿¿¿}} 39:or discuss these issues on the 1020:// enable color and Z-buffers. 875:// disable color and Z-buffers 135:You may also add the template 1: 711:Constructive Solid Geometry 287:. The specific problem is: 148:Knowledge (XXG):Translation 1209: 1171:, vol. 11, no. 2, 242-248. 944:// never pass stencil test 717:operations of the SOLiD . 556: 534:Stencil test is not passed 431:of the graphics hardware. 283:to meet Knowledge (XXG)'s 99:Machine translation, like 739:// by default not enabled 76:the corresponding article 1017: 872: 724: 594:is a technique used in 146:For more guidance, see 523:If this comparison is 387: 995:GL_STENCIL_BUFFER_BIT 832:GL_STENCIL_BUFFER_BIT 401:, in addition to the 384: 119:copyright attribution 596:3D computer graphics 294:improve this article 185:improve this article 1113:draw_actual_content 679:global illumination 1004:draw_stencil_shape 701:Other applications 440:rendering pipeline 411:, found on modern 388: 127:interlanguage link 1188:Computer graphics 763:clearStencilValue 646:for each mirror: 617:Carmack's Reverse 515:, and before the 413:graphics hardware 379: 378: 371: 361: 360: 322: 321: 314: 285:quality standards 276:This article may 261: 260: 253: 235: 159: 158: 88: 84: 54: 1200: 1172: 1165: 1159: 1158: 1151: 1117: 1114: 1111: 1108: 1105: 1102: 1099: 1096: 1093: 1090: 1087: 1084: 1081: 1078: 1075: 1072: 1069: 1066: 1063: 1060: 1057: 1054: 1051: 1048: 1045: 1042: 1039: 1036: 1033: 1030: 1027: 1024: 1021: 1011: 1008: 1005: 1002: 999: 996: 993: 990: 987: 984: 981: 978: 975: 972: 969: 966: 963: 960: 957: 954: 951: 948: 945: 942: 939: 936: 933: 930: 927: 924: 921: 918: 915: 912: 909: 906: 903: 900: 897: 894: 891: 888: 885: 882: 879: 876: 839: 836: 833: 830: 827: 824: 821: 818: 815: 812: 809: 806: 803: 800: 797: 794: 791: 788: 785: 782: 779: 776: 773: 770: 767: 764: 761: 758: 755: 752: 749: 746: 743: 740: 737: 734: 731: 728: 465:portal rendering 374: 367: 356: 353: 347: 340:factual accuracy 332: 331: 324: 317: 310: 306: 303: 297: 271: 270: 263: 256: 249: 245: 242: 236: 234: 200:"Stencil buffer" 193: 169: 161: 138: 132: 105:Google Translate 86: 82: 65: 64: 57: 46: 24: 23: 16: 1208: 1207: 1203: 1202: 1201: 1199: 1198: 1197: 1178: 1177: 1176: 1175: 1166: 1162: 1153: 1152: 1148: 1143: 1124: 1119: 1118: 1115: 1112: 1109: 1106: 1103: 1100: 1097: 1094: 1091: 1088: 1085: 1082: 1079: 1076: 1073: 1070: 1067: 1064: 1061: 1058: 1055: 1052: 1049: 1046: 1043: 1040: 1037: 1034: 1031: 1028: 1025: 1022: 1019: 1013: 1012: 1009: 1006: 1003: 1000: 997: 994: 991: 988: 985: 982: 979: 976: 973: 970: 967: 964: 961: 958: 955: 952: 949: 946: 943: 940: 937: 934: 931: 928: 925: 922: 919: 916: 913: 910: 907: 904: 901: 898: 895: 892: 889: 886: 883: 880: 877: 874: 868: 861: 854: 841: 840: 837: 834: 831: 828: 825: 822: 819: 816: 813: 810: 807: 804: 801: 798: 795: 792: 789: 786: 783: 780: 777: 774: 771: 768: 765: 762: 759: 756: 753: 750: 747: 744: 741: 738: 735: 733:GL_STENCIL_TEST 732: 729: 726: 723: 703: 687: 685:Spatial shadows 670: 625: 589: 561: 555: 509: 503:also possible. 496: 458:3D applications 423:per pixel. The 375: 364: 363: 362: 357: 351: 348: 345: 337:This article's 333: 329: 318: 307: 301: 298: 291: 272: 268: 257: 246: 240: 237: 194: 192: 182: 170: 155: 154: 153: 136: 130: 89: 66: 62: 25: 21: 12: 11: 5: 1206: 1204: 1196: 1195: 1190: 1180: 1179: 1174: 1173: 1160: 1145: 1144: 1142: 1139: 1138: 1137: 1131: 1130:(depth buffer) 1123: 1120: 1018: 873: 865: 858: 851: 757:glClearStencil 725: 722: 719: 702: 699: 686: 683: 669: 668:Planar Shadows 666: 665: 664: 663: 662: 659: 656: 653: 650: 644: 643: 642: 639: 624: 621: 588: 585: 557:Main article: 554: 551: 542: 541: 538: 535: 525:logically true 508: 505: 495: 492: 377: 376: 359: 358: 336: 334: 327: 320: 319: 302:September 2013 275: 273: 266: 259: 258: 173: 171: 164: 157: 156: 152: 151: 144: 133: 111: 108: 97: 90: 71: 70: 69: 67: 60: 55: 29: 28: 26: 19: 13: 10: 9: 6: 4: 3: 2: 1205: 1194: 1191: 1189: 1186: 1185: 1183: 1170: 1164: 1161: 1156: 1150: 1147: 1140: 1135: 1134:Shadow volume 1132: 1129: 1126: 1125: 1121: 1089:glStencilFunc 1068:glStencilMask 1016: 974:glStencilMask 920:glStencilFunc 871: 864: 857: 850: 847: 844: 772:glStencilFunc 742:glStencilMask 720: 718: 716: 712: 707: 700: 698: 694: 691: 684: 682: 680: 674: 667: 660: 657: 654: 651: 648: 647: 645: 640: 637: 636: 634: 633: 632: 629: 622: 620: 618: 614: 613: 609: 603: 601: 597: 593: 592:Shadow volume 587:Shadow volume 586: 584: 582: 577: 574: 571: 568: 565: 560: 552: 550: 546: 539: 536: 533: 532: 531: 528: 526: 520: 518: 514: 506: 504: 500: 493: 491: 489: 485: 481: 477: 473: 468: 466: 461: 459: 454: 452: 448: 443: 441: 437: 432: 430: 426: 422: 418: 414: 410: 409: 404: 400: 396: 394: 383: 373: 370: 355: 343: 341: 335: 326: 325: 316: 313: 305: 295: 290: 286: 282: 281: 274: 265: 264: 255: 252: 244: 233: 230: 226: 223: 219: 216: 212: 209: 205: 202: –  201: 197: 196:Find sources: 190: 186: 180: 179: 174:This article 172: 168: 163: 162: 149: 145: 142: 134: 128: 124: 120: 116: 112: 109: 106: 102: 98: 95: 92: 91: 85: 79: 77: 72:You can help 68: 59: 58: 53: 51: 44: 43: 38: 37: 32: 27: 18: 17: 1193:3D rendering 1168: 1163: 1149: 1014: 869: 862: 855: 848: 845: 842: 708: 704: 695: 692: 688: 675: 671: 626: 610: 604: 590: 578: 575: 572: 569: 566: 562: 547: 543: 529: 521: 510: 507:Stencil test 501: 497: 494:Architecture 469: 462: 455: 444: 433: 406: 403:color buffer 402: 397:is an extra 391: 389: 365: 352:January 2016 349: 338: 308: 299: 292:Please help 288: 277: 247: 241:January 2021 238: 228: 221: 214: 207: 195: 183:Please help 178:verification 175: 123:edit summary 114: 83:(April 2014) 81: 73: 47: 40: 34: 33:Please help 30: 1128:Z-buffering 1053:glDepthMask 1023:glColorMask 947:glStencilOp 908:glDepthMask 878:glColorMask 799:glStencilOp 748:stencilMask 623:Reflections 399:data buffer 296:if you can. 1182:Categories 1141:References 953:GL_REPLACE 867:modified. 628:Reflection 608:video game 600:Frank Crow 581:silhouette 559:Z-fighting 553:Z-fighting 517:depth test 513:alpha test 451:primitives 211:newspapers 78:in Serbian 36:improve it 860:become 1 436:rendering 141:talk page 42:talk page 1122:See also 1095:GL_EQUAL 926:GL_NEVER 914:GL_FALSE 902:GL_FALSE 896:GL_FALSE 890:GL_FALSE 884:GL_FALSE 727:glEnable 480:Direct3D 425:Z-buffer 408:Z-buffer 278:require 117:provide 1059:GL_TRUE 1047:GL_TRUE 1041:GL_TRUE 1035:GL_TRUE 1029:GL_TRUE 989:glClear 965:GL_KEEP 959:GL_KEEP 826:glClear 715:Boolean 417:integer 393:stencil 280:cleanup 225:scholar 139:to the 121:in the 80:. 721:OpenGL 612:Doom 3 484:Vulkan 476:OpenGL 447:shadow 395:buffer 386:versa. 227:  220:  213:  206:  198:  817:zpass 811:zfail 488:Metal 474:like 232:JSTOR 218:books 101:DeepL 1107:0xFF 1074:0x00 980:0xFF 938:0xFF 853:ref 805:fail 790:mask 778:func 472:APIs 421:byte 405:and 204:news 115:must 113:You 94:View 1116:(); 1007:(); 784:ref 486:or 429:RAM 187:by 103:or 1184:: 1110:); 1077:); 1062:); 1050:); 998:); 983:); 968:); 941:); 917:); 905:); 835:); 820:); 793:); 766:); 751:); 736:); 619:. 490:. 482:, 478:, 390:A 45:. 1157:. 1104:, 1101:1 1098:, 1092:( 1071:( 1056:( 1044:, 1038:, 1032:, 1026:( 992:( 977:( 962:, 956:, 950:( 935:, 932:1 929:, 923:( 911:( 899:, 893:, 887:, 881:( 829:( 814:, 808:, 802:( 787:, 781:, 775:( 760:( 745:( 730:( 372:) 366:( 354:) 350:( 344:. 315:) 309:( 304:) 300:( 254:) 248:( 243:) 239:( 229:· 222:· 215:· 208:· 181:. 150:. 143:. 52:) 48:(

Index

improve it
talk page
Learn how and when to remove these messages
the corresponding article
View
DeepL
Google Translate
copyright attribution
edit summary
interlanguage link
talk page
Knowledge (XXG):Translation

verification
improve this article
adding citations to reliable sources
"Stencil buffer"
news
newspapers
books
scholar
JSTOR
Learn how and when to remove this message
cleanup
quality standards
improve this article
Learn how and when to remove this message
factual accuracy
Learn how and when to remove this message

Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.