arb fragment program
DESCRIPTION
ARB Fragment Program. Fragment level programmability in OpenGL Evan Hart [email protected]. Plan of Action. What is it How does it work What is it good for. Introduction to ARB FP. New standardized programming model What it replaces What it does not replace. - PowerPoint PPT PresentationTRANSCRIPT
![Page 2: ARB Fragment Program](https://reader036.vdocument.in/reader036/viewer/2022062315/56815870550346895dc5d10e/html5/thumbnails/2.jpg)
Plan of Action• What is it• How does it work• What is it good for
![Page 3: ARB Fragment Program](https://reader036.vdocument.in/reader036/viewer/2022062315/56815870550346895dc5d10e/html5/thumbnails/3.jpg)
Introduction to ARB FP• New standardized programming
model• What it replaces• What it does not replace
![Page 4: ARB Fragment Program](https://reader036.vdocument.in/reader036/viewer/2022062315/56815870550346895dc5d10e/html5/thumbnails/4.jpg)
Standardized Fragment Programmability• ARB standard for fragment-level
programmability• Derived from
ARB_vertex_program
![Page 5: ARB Fragment Program](https://reader036.vdocument.in/reader036/viewer/2022062315/56815870550346895dc5d10e/html5/thumbnails/5.jpg)
Replaces Multitexture Pipe• Replaces
– Texture blending– Color Sum– Fog
• Subsumes– texture enables– texture target priorities
![Page 6: ARB Fragment Program](https://reader036.vdocument.in/reader036/viewer/2022062315/56815870550346895dc5d10e/html5/thumbnails/6.jpg)
Fragment Processing Pipe
User-definedFragment
Processing
User-definedFragment
Processing
frame-bufferops
frame-bufferops
Color SumColor Sum
setupsetup
Texture Fetch andApplication
Texture Fetch andApplication
rasterizerrasterizer
FogFog
![Page 7: ARB Fragment Program](https://reader036.vdocument.in/reader036/viewer/2022062315/56815870550346895dc5d10e/html5/thumbnails/7.jpg)
Preserves Backend Operations• Coverage application• Alpha Test• Stencil and depth test• Blending
![Page 8: ARB Fragment Program](https://reader036.vdocument.in/reader036/viewer/2022062315/56815870550346895dc5d10e/html5/thumbnails/8.jpg)
Programming Model• ASM based similar to
ARB_vertex_program• Rich SIMD instruction set• Requires resource management
– Texture accesses– Interpolators– Temporaries– Constants
![Page 9: ARB Fragment Program](https://reader036.vdocument.in/reader036/viewer/2022062315/56815870550346895dc5d10e/html5/thumbnails/9.jpg)
Similar to ARB_vertex_program• Assembly syntax• Same basic grammar rules
– Ops are upper case– Statements terminated by
semicolons– Comments begin with #
![Page 10: ARB Fragment Program](https://reader036.vdocument.in/reader036/viewer/2022062315/56815870550346895dc5d10e/html5/thumbnails/10.jpg)
Fragment Program Machine
Attributes
Fragment Program
Result Registers
Temporary Variables
Program Local Parameters
Program Environment Parameters
Address Variables
![Page 11: ARB Fragment Program](https://reader036.vdocument.in/reader036/viewer/2022062315/56815870550346895dc5d10e/html5/thumbnails/11.jpg)
Large Instruction Set• Three basic categories
– Scalar (single value) operations– Vector operations– Texture operations
• Component swizzling• Component masking
![Page 12: ARB Fragment Program](https://reader036.vdocument.in/reader036/viewer/2022062315/56815870550346895dc5d10e/html5/thumbnails/12.jpg)
Scalar Instructions• COS – cosine• EX2 – base 2 exponential• LG2 – base 2 logarithm• RCP – reciprocal • RSQ – reciprocal square root• SIN – sine • SCS – sine and cosine• POW – power
![Page 13: ARB Fragment Program](https://reader036.vdocument.in/reader036/viewer/2022062315/56815870550346895dc5d10e/html5/thumbnails/13.jpg)
New Scalar Instructions• COS – cosine • SIN – sine • SCS – sine and cosine
![Page 14: ARB Fragment Program](https://reader036.vdocument.in/reader036/viewer/2022062315/56815870550346895dc5d10e/html5/thumbnails/14.jpg)
Removed Scalar Instructions• EXP – Partial Precision EX2• LOG – Partial Precision LG2
![Page 15: ARB Fragment Program](https://reader036.vdocument.in/reader036/viewer/2022062315/56815870550346895dc5d10e/html5/thumbnails/15.jpg)
Vector Instructions• Standard Arithmetic• Special purpose vector
![Page 16: ARB Fragment Program](https://reader036.vdocument.in/reader036/viewer/2022062315/56815870550346895dc5d10e/html5/thumbnails/16.jpg)
Standard Arithmetic Ops• ABS – absolute value• FLR – floor • FRC – fraction component • SUB – subtract • XPD – cross product• CMP – compare • LRP – linearly interpolate• MAD – multiply accumulate• MOV – move • ADD – add • DP3 – three component dot product• DP4 – four component dot product
![Page 17: ARB Fragment Program](https://reader036.vdocument.in/reader036/viewer/2022062315/56815870550346895dc5d10e/html5/thumbnails/17.jpg)
Special Vector Ops• LIT – compute lighting• DPH – homogeneous dot product• DST – compute distance vector
![Page 18: ARB Fragment Program](https://reader036.vdocument.in/reader036/viewer/2022062315/56815870550346895dc5d10e/html5/thumbnails/18.jpg)
New Instructions• LRP – Linearly Interpolate• CMP - Compare
![Page 19: ARB Fragment Program](https://reader036.vdocument.in/reader036/viewer/2022062315/56815870550346895dc5d10e/html5/thumbnails/19.jpg)
Texture Instructions• TEX• TXP• TXB• KIL
![Page 20: ARB Fragment Program](https://reader036.vdocument.in/reader036/viewer/2022062315/56815870550346895dc5d10e/html5/thumbnails/20.jpg)
Standard Texture FetchTEX <dest>, <src>, texture[n], <type>;
• Does not divide by q
![Page 21: ARB Fragment Program](https://reader036.vdocument.in/reader036/viewer/2022062315/56815870550346895dc5d10e/html5/thumbnails/21.jpg)
Extended Texture Fetches• TXP
– Same syntax as TEX– Divides first three components by
the fourth
• TXB– Adds the fourth component to the
computed LOD
![Page 22: ARB Fragment Program](https://reader036.vdocument.in/reader036/viewer/2022062315/56815870550346895dc5d10e/html5/thumbnails/22.jpg)
Killing pixels• KIL instruction
– Terminates shader program if any component is less than 0
![Page 23: ARB Fragment Program](https://reader036.vdocument.in/reader036/viewer/2022062315/56815870550346895dc5d10e/html5/thumbnails/23.jpg)
Resource Categories in ARB FP• Temporaries• Textures• Attributes• Parameters• Instructions
– Texture Instructions– Arithmetic Instructions
![Page 24: ARB Fragment Program](https://reader036.vdocument.in/reader036/viewer/2022062315/56815870550346895dc5d10e/html5/thumbnails/24.jpg)
Identifying Limits• Standard Resource limits
– Number of temps etc
• Texture Indirections
![Page 25: ARB Fragment Program](https://reader036.vdocument.in/reader036/viewer/2022062315/56815870550346895dc5d10e/html5/thumbnails/25.jpg)
Using Fragment Program• API• Simple shaders• Complex shaders
![Page 26: ARB Fragment Program](https://reader036.vdocument.in/reader036/viewer/2022062315/56815870550346895dc5d10e/html5/thumbnails/26.jpg)
Simple API• Loading programs• Setting Parameters• Making active
![Page 27: ARB Fragment Program](https://reader036.vdocument.in/reader036/viewer/2022062315/56815870550346895dc5d10e/html5/thumbnails/27.jpg)
Shared API
glGenProgramsARB( num, id );
glBindProgramARB( GL_FRAGMENT_PROGRAM_ARB, id );
glProgramStringARB( GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, length, string );
![Page 28: ARB Fragment Program](https://reader036.vdocument.in/reader036/viewer/2022062315/56815870550346895dc5d10e/html5/thumbnails/28.jpg)
Simple shaders• Pre-programmable functionality
– Texture * color
![Page 29: ARB Fragment Program](https://reader036.vdocument.in/reader036/viewer/2022062315/56815870550346895dc5d10e/html5/thumbnails/29.jpg)
Simple Shader Example!!ARBfp1.0
TEMP temp; #temporaryATTRIB tex0 = fragment.texcoord[0];ATTRIB col0 = fragment.color;
PARAM pink = { 1.0, 0.4, 0.4, 1.0};
OUTPUT out = result.color;
TEX temp, tex0, texture[0], 2D; #Fetch texture
MOV out, temp; #replace
#MUL out, col0, temp; #modulate#MUL out, temp, pink; #modulate with constant color
![Page 30: ARB Fragment Program](https://reader036.vdocument.in/reader036/viewer/2022062315/56815870550346895dc5d10e/html5/thumbnails/30.jpg)
Complex Shaders• Lighting• Procedural
![Page 31: ARB Fragment Program](https://reader036.vdocument.in/reader036/viewer/2022062315/56815870550346895dc5d10e/html5/thumbnails/31.jpg)
Phong Lighting#compute half angle vectorADD spec.rgb, view, lVec;DP3 spec.a, spec, spec;RSQ spec.a, spec.a;MUL spec.rgb, spec, spec.a;
#compute specular intensistyDP3_SAT spec.a, spec, tmp;LG2 spec.a, spec.a;MUL spec.a, spec.a, const.w;EX2 spec.a, spec.a;
#compute diffuse illumDP3_SAT dif, tmp, lVec;ADD_SAT dif.rgb, dif, const;
![Page 32: ARB Fragment Program](https://reader036.vdocument.in/reader036/viewer/2022062315/56815870550346895dc5d10e/html5/thumbnails/32.jpg)
Procedural Bricks#Apply the staggerMUL r2.w, r0.y, half;FRC r2.w, r2.w;SGE r2.w, half, r2.w;MAD r0.x, r2.w, half, r0.x;
#determine whether it is brick or mortarFRC r0.xy, r0;SGE r2.xy, freq, r0;SUB r3.xy, 1.0, freq;SGE r0.xy, r3, r0;SUB r0.xy, r2, r0;MUL r0.w, r0.x, r0.y;
![Page 33: ARB Fragment Program](https://reader036.vdocument.in/reader036/viewer/2022062315/56815870550346895dc5d10e/html5/thumbnails/33.jpg)
Caveats • Remember the difference
between– {3.0}– 3.0
• Ensure Continuity at Boundaries– Needed to compute LOD
• Programs under limits may not load
![Page 34: ARB Fragment Program](https://reader036.vdocument.in/reader036/viewer/2022062315/56815870550346895dc5d10e/html5/thumbnails/34.jpg)
Wrap up• Fragment Program is the
Standard for Fragment Programmability
• Assembly Language Shaders• Enhances Pixel Level Effects
![Page 35: ARB Fragment Program](https://reader036.vdocument.in/reader036/viewer/2022062315/56815870550346895dc5d10e/html5/thumbnails/35.jpg)
Questions?• [email protected]