Presentation is loading. Please wait.

Presentation is loading. Please wait.

Pixel Shader  Based on nVIDIA’s GF3/4 architecture  Texture shader + register combiner texture unit 0texture program texture unit 1texture program texture.

Similar presentations


Presentation on theme: "Pixel Shader  Based on nVIDIA’s GF3/4 architecture  Texture shader + register combiner texture unit 0texture program texture unit 1texture program texture."— Presentation transcript:

1 Pixel Shader  Based on nVIDIA’s GF3/4 architecture  Texture shader + register combiner texture unit 0texture program texture unit 1texture program texture unit 2texture program texture unit 3texture program fragment color input register combiner fragment color output texture shader

2 Texture Shader “Bridge” (s 0,t 0,r 0,q 0 ) (s 1,t 1,r 1,q 1 ) (s 2,t 2,r 2,q 2 ) (s 3,t 3,r 3,q 3 ) (R 0,G 0,B 0,A 0 ) (R 1,G 1,B 1,A 1 ) (R 2,G 2,B 2,A 2 ) (R 3,G 3,B 3,A 3 ) Interpolated texture coordinate sets 32-bit IEEE floating-point Per-component RGBA colors 8-bit [0,1] or [-1,1) fixed-point Per-component Texture shader and Texture fetch units State

3 Texture Shaders Provides a superset of conventional OpenGL texture addressing Five main categories of shader operations –Conventional textures 1D, 2D, texture rectangle, cube map –Special modes none, pass through, cull fragment –Direct dependent textures dependent AR, dependent GB, offset, offset scaled –Dot product (DP) dependent textures DP 2D, DP texture rectangle, DP cube map, DP reflect cube map, DP diffuse cube map –Depth replace operations

4 Conventional Textures Tex# Texture Coords (S,T,R,Q) Shader Operations Texture Fetch Texture 2D 2D Any Format (, ) Bound Texture Target/Format QiQi SiSi QiQi TiTi (S i,T i,R i,Q i )i Output Color (R,G,B,A)  Texture program: 2D texture mapping

5 Texture Rectangle Tex# Texture Coords (S,T,R,Q) Shader Operations Texture Fetch Texture Rectangle Texture Rectangle Any Format (, ) Bound Texture Target/Format QiQi SiSi QiQi TiTi (S i,T i,R i,Q i )i Output Color (R,G,B,A)  Texture program: No need to have power of 2 texture

6 Texture Cube Map Tex# Texture Coords (S,T,R,Q) Shader Operations Texture Fetch Texture Cube Map U =( S i, T i, R i ) Bound Texture Target/Format (S i,T i,R i )i Cube Map Any Format U Output Color (R,G,B,A)

7 Special Modes  Texture program: pass through Shader Operations Texture Fetch Output Color (S i,T i,R i,Q i ) None Bound Texture Target/Format (R,G,B,A) None R = Clamp0to1(S i ) G = Clamp0to1(T i ) B = Clamp0to1(R i ) A = Clamp0to1(Q i )

8 Special Modes Tex# Texture Coords (S,T,R,Q) Shader Operations Texture Fetch Bound Texture Target/Format IgnorediNone Output Color (R,G,B,A) R = 0 G = 0 B = 0 A = 0  Texture program: none

9  Texture program: Cull Fragment Cull the fragment based upon sign of texture coords –each tex coord (STRQ) has its own settable condition –each of the 4 conditions is set to one of the following: GL_GEQUAL (tex coord ≥ 0) – pass iff positive or zero GL_LESS (tex coord < 0) – pass iff negative –all four tex coords are tested –if any of the four fail, the fragment is rejected Texture output for passing fragments is (0,0,0,0) Special Modes

10 Cull Fragment Applications Per-fragment clip planes –Up to 4 clip planes per texture unit –16 clip planes maximum Non-planar clipping approaches also possible –Vertex programs can compute a distance to a point or line and use that interpolated distance for clipping

11 Cull Fragment Examples Clipping a model to two texture shader clip planes Clipping a 3D grid of cubes based on distance from a point

12 Dependent Texture Shaders Take results of one texture, use them for addressing subsequent texture Simple dependent textures (single stage) –Dependent alpha-red –Dependent green blue –Offset texture 2D –Offset texture 2D scaled

13 Dependent Alpha-Red Texturing 0 Tex# Texture Coords (S,T,R,Q) Shader Operations Texture Fetch Output Color App specific Texture specific Any type Unsigned RGBA R0G0B0A0R0G0B0A0 1(A0,R0)(A0,R0) Texture specific 2D RGBA Bound Texture Target/Format R1G1B1A1R1G1B1A1 IgnoredNone

14 Dependent Green-Blue Texturing 0 Tex# Texture Coords (S,T,R,Q) Shader Operations Texture Fetch Output Color App specific Texture specific Any type Unsigned RGB[A] R0G0B0A0R0G0B0A0 1(G 0,B 0 ) Texture specific 2D RGBA Bound Texture Target/Format R1G1B1A1R1G1B1A1 IgnoredNone

15 Offset Texture 2D Use previous lookup (a signed 2D offset) to perturb the texture coordinates of a subsequent (non-projective) 2D texture lookup Signed 2D offset is transformed by user- defined 2x2 matrix (shown in the following diagrams as constants k 0 -k 3 ) This 2x2 constant matrix allows for arbitrary rotation/scaling of offset vector Offset defined in DS/DT texture

16 Offset Texture 2D 0 Tex# Texture Coords (S,T,R,Q) Shader Operations Texture Fetch Output Color (S 0,T 0,R 0,Q 0 ) Texture 2D 2D DSDT 1 (, ) Bound Texture Target/Format (0,0,0,0) Q0Q0 S0S0 Q0Q0 T0T0 (S1,T1)(S1,T1) (S 1 ’, T 1 ’ ) S 1 ’ = S 1 + k 0 *ds + k 2 *dt T 1 ’ = T 1 + k 1 *ds + k 3 *dt (ds,dt) R1G1B1A1R1G1B1A1 2D Any Format k 0, k 1, k 2 and k 3 define a constant 2x2 floating-point matrix set by glTexEnv

17 Offset Texture 2D Scale Same as Offset Texture 2D, except that subsequent (non-projective) 2D texture RGB output is scaled Scaling factor is the MAG component (from previous texture) scaled/biased by user- defined constants (k scale and k bias in the following diagrams) Alpha component is NOT scaled

18 (R * M, G * M, B * M,A) Offset Texture 2D Scale 0 Tex# Texture Coords (S,T,R,Q) Shader Operations Texture Fetch Output Color (S 0,T 0,R 0,Q 0 ) Texture 2D 2D DSDT_Mag 1 (, ) Bound Texture Target/Format (0,0,0,0) Q0Q0 S0S0 Q0Q0 T0T0 (S1,T1)(S1,T1) (S 1 ’, T 1 ’ ) S 1 ’ = S 1 + k 0 *ds + k 2 *dt T 1 ’ = T 1 + k 1 *ds + k 3 *dt (ds,dt,mag) 2D RGBA M = k scale * mag + k bias k 0, k 1, k 2 and k 3 define a constant 2x2 floating-point matrix set by glTexEnv k scale and k bias define constant floating-point scale/bias set by glTexEnv

19 Dot Product Dependent Texture Shaders Take results of one texture, perform 2 or 3 dot products with it and incoming texture coordinates, then use results for addressing subsequent texture(s) Multiple contiguous stages, not including source texture

20 Dot Product Texture 2D 0 Tex# Texture Coords (S,T,R,Q) Shader Operations Texture Fetch Output Color App specific Texture specific Any type Signed RGB[A] R0G0B0R0G0B0 1None(0,0,0,0)None 2(Ux, Uy)(Ux, Uy) Texture specific 2D RGBA U y =[S 2, T 2, R 2 ] [R 0,G 0,B 0 ] U x =[S 1,T 1,R 1 ] [R 0,G 0,B 0 ] Bound Texture Target/Format (S 1, T 1, R 1 ) (S 2, T 2, R 2 )R2G2B2A2R2G2B2A2

21 Dot Product Texture 2D Application High-quality bump-mapping –2D HILO texture stores normals Per-fragment tangent-space normal, N –Vertex programs supplies tangent-space light (L) and half-angle (H) vectors in (s,t,r) texture coordinates –Two dot products compute Diffuse L dot N Specular H dot N –Illumination stored in 2D texture accessed by L dot N and H dot N Excellent specular appearance

22 HILO Normal Map Dot Product Texture 2D Bump Mapping Bump mapping the Holy Grail

23 Dot Product Texture 3D 0 Tex# Texture Coords (S,T,R,Q) Shader Operations Texture Fetch Output Color App specific Texture specific Any type Signed RGB[A] R0G0B0R0G0B0 1None(0,0,0,0)None 2 3R3G3B3A3R3G3B3A3 Texture specific (0,0,0,0)None 3D RGBA T =[S 2,T 2,R 2 ] [R 0,G 0,B 0 ] S =[S 1,T 1,R 1 ] [R 0,G 0,B 0 ] Bound Texture Target/Format (S 3, T 3, R 3 ) (S 2, T 2, R 2 ) (S 1, T 1, R 1 ) R =[S 3,T 3,R 3 ] [R 0,G 0,B 0 ] (S, T, R)

24 Texture Shader Precision Interpolated texture coordinates are IEEE 32- bit floating-point values Texture projections, dot products, texture offset, post-texture offset scaling, reflection vector, and depth replace division computations are performed in IEEE 32-bit floating-point HILO texture components are filtered as 16- bit values DSDT, MAG, intensity, and color components are filtered as 8-bit values

25 Register Combiner  GeForce 2 (only 2 general combiner stages) Spare 0 Fragment Color Texture Fetching General Combiner 0 4 RGB Inputs Texture 0 Texture 1 Fog Color/Factor Register Set 6 RGB Inputs Specular Color 4 Alpha Inputs 3 RGB Outputs 3 Alpha Outputs General Combiner 1 4 RGB Inputs 4 Alpha Inputs 3 RGB Outputs 3 Alpha Outputs Final Combiner 1 Alpha Input Specular Color

26  Register-based programming –All textures and colors available for each and every texture blending stage –8 Stages of blending in hardware, plus specular and fog Note that GeForce3 has 8 combiners, and 4 textures. –Signed color arithmetic Register Combiner (cont’d)

27 Diagram of a General Combiner Input RGB, Alpha Registers Input Alpha, Blue Registers Input Mappings Input Mappings A B C D A op 1 B C op 2 D AB op 3 CD RGB Function A B C D AB CD AB op 4 CD Alpha Function RGB Scale/Bias Alpha Scale/Bias Next Combiner’s RGB Registers Next Combiner’s Alpha Registers RGB Portion Alpha Portion

28 General Combiner Input Registers Input RGB, Alpha Registers Input Alpha, Blue Registers Input Mappings Input Mappings A B C D A op 1 B C op 2 D AB op 3 CD RGB Function A B C D AB CD AB op 4 CD Alpha Function RGB Scale/Bias Alpha Scale/Bias Next Combiner’s RGB Registers Next Combiner’s Alpha Registers RGB Portion Alpha Portion

29 The Register Set Primary (diffuse) color initialized to RGBA of fragment’s primary color Secondary (specular) color initialized to RGB of fragment’s secondary/specular color alpha not initialized Texture 0 and Texture 1 colors initialized to fragment’s filtered RGBA texel from numbered texture unit not initialized if numbered texture unit is disabled or non-existent Spare 0 and Spare 1 Alpha of Spare 0 is initialized to alpha of Texture 0 color (if enabled) RGB of Spare 0 and all of Spare 1 is not initialized Fog RGB is current fog color alpha is fragment’s fog factor (only available in final combiner) read-only Constant color 0 and Constant color 1 initialized to user-defined RGBA value read-only Zero constant, read-only value of zero

30 General Combiner Input Mappings Input RGB, Alpha Registers Input Alpha, Blue Registers Input Mappings Input Mappings A B C D A op 1 B C op 2 D AB op 3 CD RGB Function A B C D AB CD AB op 4 CD Alpha Function RGB Scale/Bias Alpha Scale/Bias Next Combiner’s RGB Registers Next Combiner’s Alpha Registers RGB Portion Alpha Portion

31 General Combiner Input Mappings Signed Identity f(x) = x [-1, 1]  [-1, 1] Unsigned Identity f(x) = max(0, x) [0, 1]  [0, 1] Expand Normal f(x) = 2 * max(0, x) - 1 [0, 1]  [-1, 1] Half Bias Normal f(x) = max(0, x) – ½ [0, 1]  [-½, ½] Signed Negate f(x) = -x [-1, 1]  [1, -1] Unsigned Invert f(x) = 1-min(max(0,x),1) [0, 1]  [1, 0] Expand Negate f(x) = -2 * max(0, x) + 1 [0, 1]  [1, -1] Half Bias Negate f(x) = -max(0, x) + ½ [0, 1]  [½, -½]

32 General Combiner RGB Function Input RGB, Alpha Registers Input Alpha, Blue Registers Input Mappings Input Mappings A B C D A op 1 B C op 2 D AB op 3 CD RGB Function A B C D AB CD AB op 4 CD Alpha Function RGB Scale/Bias Alpha Scale/Bias Next Combiner’s RGB Registers Next Combiner’s Alpha Registers RGB Portion Alpha Portion

33 General Combiner RGB Functions A B C D AB CD AB + CD A B C D AB CD mux(AB, CD) A B C D A B C D Dot / Dot / Discard A B C D A B CD A B C D AB C D Dot / Mult / DiscardMult / Dot / Discard Mult / Mult / SumMult / Mult / Mux mux(AB, CD) = (Spare0[Alpha]  ½) ? AB : CD Dot products on RGB registers: A B = (A[red] * B[red] + A[green] * B[green] + A[blue] * B[blue], A[red] * B[red] + A[green] * B[green] + A[blue] * B[blue], A[red] * B[red] + A[green] * B[green] + A[blue] * B[blue]) Multiplication on RGB registers: AB = (A[red] * B[red], A[green] * B[green], A[blue] * B[blue])

34 General Combiner Alpha Function Input RGB, Alpha Registers Input Alpha, Blue Registers Input Mappings Input Mappings A B C D A op 1 B C op 2 D AB op 3 CD RGB Function A B C D AB CD AB op 4 CD Alpha Function RGB Scale/Bias Alpha Scale/Bias Next Combiner’s RGB Registers Next Combiner’s Alpha Registers RGB Portion Alpha Portion

35 General Combiner Alpha Functions A B C D AB CD AB + CD A B C D AB CD mux(AB, CD) Mult / Mult / SumMult / Mult / Mux mux(AB, CD) = (Spare0[alpha]  ½) ? AB : CD

36 General Combiner Scale and Bias Input RGB, Alpha Registers Input Alpha, Blue Registers Input Mappings Input Mappings A B C D A op 1 B C op 2 D AB op 3 CD RGB Function A B C D AB CD AB op 4 CD Alpha Function RGB Scale/Bias Alpha Scale/Bias Next Combiner’s RGB Registers Next Combiner’s Alpha Registers RGB Portion Alpha Portion

37 General Combiner Scale and Bias Options f(x) = x/2f(x) = xf(x) = 2xf(x) = 4x Not supported f(x) = x – ½f(x) = 2(x – ½) Not supported Bias by –½ No bias Scale by ½No scaleScale by 2Scale by 4 Scale and bias operation is defined as: ClampNegativeOneToOne( Scale * (x + Bias) ) OR max(min(Scale * (x + Bias), 1), -1)

38 General Combiner Output Registers Input RGB, Alpha Registers Input Alpha, Blue Registers Input Mappings Input Mappings A B C D A op 1 B C op 2 D AB op 3 CD RGB Function A B C D AB CD AB op 4 CD Alpha Function RGB Scale/Bias Alpha Scale/Bias Next Combiner’s RGB Registers Next Combiner’s Alpha Registers RGB Portion Alpha Portion

39 Up to six outputs can be specified per general combiner: three RGB outputs (A op 1 B, C op 2 D, AB op 3 CD) written to RGB portion of writable registers three Alpha outputs (AB, CD, AB op 4 CD) written to Alpha portion of writable registers RGB outputs must be written to distinct registers (that is, two outputs cannot be written to one register) Alpha outputs must be written to distinct registers Any output can be discarded Those RGB functions performing dot products must discard the third result (Dot/Dot/Discard, Dot/Mult/Discard, Mult/Dot/Discard) General Combiner Output Registers

40 Diagram of the Final Combiner (OpenGL only) Input RGB, Alpha Registers Input Alpha, Blue Registers Input Mappings Input Mapping A B C D AB + (1-A)C + D RGB Function RGB Portion Alpha Portion RGB Out Available RGB Inputs Alpha Out E F EF Spare0 2 nd -ary Color Sum Clamp to [0, 1] Input Mappings Color Sum Unit Multiplier

41 Final Combiner Input Registers Input RGB, Alpha Registers Input Alpha, Blue Registers Input Mappings Input Mapping A B C D AB + (1-A)C + D RGB Function RGB Portion Alpha Portion RGB Out Available RGB Inputs Alpha Out E F EF Spare0 2 nd -ary Color Sum Clamp to [0, 1] Input Mappings Color Sum Unit Multiplier

42 Final Combiner Input Mappings Input RGB, Alpha Registers Input Alpha, Blue Registers Input Mappings Input Mapping A B C D AB + (1-A)C + D RGB Function RGB Portion Alpha Portion RGB Out Available RGB Inputs Alpha Out E F EF Spare0 2 nd -ary Color Sum Clamp to [0, 1] Input Mappings Color Sum Unit Multiplier

43 Final Combiner Input Mappings Unsigned Identity f(x) = max(0, x) [0, 1]  [0, 1] Unsigned Invert f(x) = 1-min(max(0,x),1) [0, 1]  [1, 0]

44 Final Combiner EF Multiplier Input RGB, Alpha Registers Input Alpha, Blue Registers Input Mappings Input Mapping A B C D AB + (1-A)C + D RGB Function RGB Portion Alpha Portion RGB Out Available RGB Inputs Alpha Out E F EF Spare0 2 nd -ary Color Sum Clamp to [0, 1] Input Mappings Color Sum Unit Multiplier

45 Final Combiner EF Multiplier E F E F Multiplication on RGB registers: E F = (E[red] * F[red], E[green] * F[green], E[blue] * F[blue])

46 Final Combiner Color Sum and Optional Clamp Input RGB, Alpha Registers Input Alpha, Blue Registers Input Mappings Input Mapping A B C D AB + (1-A)C + D RGB Function RGB Portion Alpha Portion RGB Out Available RGB Inputs Alpha Out E F EF Spare0 2 nd -ary Color Sum Clamp to [0, 1] Input Mappings Color Sum Unit Multiplier

47 Final Combiner Color Sum and Optional Clamp Spare0 SecondaryColor Clamp(Spare0) + Clamp(SecondaryColor) Clamp to [0, 1] Color Sum Unit Inputs to this unit are hardwired to Spare0 and SecondaryColor registers Each input to the color sum unit undergoes an unsigned identity mapping before addition Unsigned identity = max(0, x), clamping negative input values to 0 Addition on RGB registers: Spare0 + SecondaryColor = (Spare0[red] + SecondaryColor[red], Spare0[green] + SecondaryColor[green], Spare0[blue] + SecondaryColor[blue]) Output range for sum is [0, 2] Optional clamping unit clamps the sum to [0, 1]

48 Final Combiner RGB Input Set Input RGB, Alpha Registers Input Alpha, Blue Registers Input Mappings Input Mapping A B C D AB + (1-A)C + D RGB Function RGB Portion Alpha Portion RGB Out Available RGB Inputs Alpha Out E F EF Spare0 2 nd -ary Color Sum Clamp to [0, 1] Input Mappings Color Sum Unit Multiplier

49 Final Combiner RGB Input Set All registers available to all RGB function inputs (A, B, C and D) Result of EF multiplier also available to all RGB function inputs Result of (possibly clamped) color sum available to B, C and D function inputs (but not A) Neither the result of the EF multiplier nor the color sum is available to the Alpha portion

50 Final Combiner RGB Function Input RGB, Alpha Registers Input Alpha, Blue Registers Input Mappings Input Mapping A B C D AB + (1-A)C + D RGB Function RGB Portion Alpha Portion RGB Out Available RGB Inputs Alpha Out E F EF Spare0 2 nd -ary Color Sum Clamp to [0, 1] Input Mappings Color Sum Unit Multiplier

51 Final Combiner RGB Function A B C D AB + (1-A)C + D RGB Out Unlike the general combiner, only one function is supported in the final combiner Addition/multiplication on RGB registers as defined previously Output range for RGB function is [0, 2] RGB output combined with Alpha output to form a single RGBA fragment RGBA fragment continues with subsequent processing (Z-buffering, blending,...)


Download ppt "Pixel Shader  Based on nVIDIA’s GF3/4 architecture  Texture shader + register combiner texture unit 0texture program texture unit 1texture program texture."

Similar presentations


Ads by Google