72 |
whitePaperMakers.append( (white, "White background") ) |
whitePaperMakers.append( (white, "White background") ) |
73 |
|
|
74 |
# The programs here are best-first |
# The programs here are best-first |
75 |
|
# The following program gives a 30% improvement |
76 |
|
# to rendering speeds on a GF FX 5600 |
77 |
|
# by using a biased texture unit instead of |
78 |
|
# calculating the bias explicitly in the program. |
79 |
|
|
80 |
|
# Replacing some of the MULH:s with MULX makes |
81 |
|
# it faster but it stops working - the results are |
82 |
|
# not accurate enough. |
83 |
|
# On the 5900, 5700 this should be a lot faster... |
84 |
|
# It's sad that we can't take advantage of the fixed-point |
85 |
|
# units at all except at the very end. |
86 |
|
|
87 |
|
nvBlurProgram = None |
88 |
|
if GL.hasExtension("GL_NV_fragment_program"): |
89 |
|
nvBlurProgram = GL.createProgram("""!!FP1.0 |
90 |
|
# Get the blurred value of the text texture |
91 |
|
# Texture unit 2 is blurred |
92 |
|
TEX H2, f[TEX1], TEX2, 2D; |
93 |
|
|
94 |
|
# Map blurred 'text' texture intensity to background blur |
95 |
|
# as follows: |
96 |
|
# 1 -> no bias |
97 |
|
# 0 -> large bias |
98 |
|
DP4H H2, {-10,-10,-10,31}, H2; |
99 |
|
|
100 |
|
# The derivatives of the paper texture |
101 |
|
DDXH H0, f[TEX0]; |
102 |
|
DDYH H1, f[TEX0]; |
103 |
|
|
104 |
|
# Scale with the DP |
105 |
|
MULH H0, H2, H0; |
106 |
|
MULH H1, H2, H1; |
107 |
|
|
108 |
|
# Get the blurred value of the background texture |
109 |
|
TXD H0, f[TEX0], H0, H1, TEX0, 2D; |
110 |
|
|
111 |
|
# Get the sharp value of the text texture |
112 |
|
TEX H1, f[TEX1], TEX1, 2D; |
113 |
|
|
114 |
|
# Compute the final color |
115 |
|
|
116 |
|
MULX o[COLR], H0, H1; |
117 |
|
END |
118 |
|
""") |
119 |
|
|
120 |
|
def nvFancyBlur(paperMill = None, paperOffset = 0): |
121 |
|
paperMill = getPaperMill(paperMill, paperOffset) |
122 |
|
if not nvBlurProgram: |
123 |
|
print "Nvidia-optimized Fancy blurring is not possible without GL_NV_fragment_program." |
124 |
|
print "Punting to ARB Fancy blur" |
125 |
|
return fancyBlur(paperMill) |
126 |
|
|
127 |
|
if paperMill == None: |
128 |
|
paperMill = PaperMill.getInstance() |
129 |
|
|
130 |
|
return PlainPaperMaker(2, """ |
131 |
|
BindProgram FRAGMENT_PROGRAM_NV %s |
132 |
|
ActiveTexture TEXTURE2 |
133 |
|
TexEnv TEXTURE_FILTER_CONTROL TEXTURE_LOD_BIAS 3.8 |
134 |
|
ActiveTexture TEXTURE0 |
135 |
|
Enable FRAGMENT_PROGRAM_NV |
136 |
|
Disable REGISTER_COMBINERS_NV |
137 |
|
Disable BLEND |
138 |
|
""" % nvBlurProgram.getProgId(), |
139 |
|
""" |
140 |
|
ActiveTexture TEXTURE2 |
141 |
|
TexEnv TEXTURE_FILTER_CONTROL TEXTURE_LOD_BIAS 0 |
142 |
|
ActiveTexture TEXTURE0 |
143 |
|
""", [nvBlurProgram], paperMill) |
144 |
|
|
145 |
|
if nvBlurProgram: |
146 |
|
b = nvFancyBlur |
147 |
|
else: |
148 |
|
b = None |
149 |
|
|
150 |
|
fancyPaperMakers.append( (b, "(NVIDIA-optimized) Blurring background under text") ) |
151 |
|
|
152 |
|
|
153 |
blurProgram = None |
blurProgram = None |
154 |
|
|
173 |
# as follows: |
# as follows: |
174 |
# 1 -> no bias |
# 1 -> no bias |
175 |
# 0 -> large bias |
# 0 -> large bias |
176 |
DP4 coord0.w, {-6,-6,-6,18}, tex1b; |
DP4 coord0.w, {-7,-7,-7,21}, tex1b; |
177 |
|
|
178 |
# Filter background texture with the proper LOD bias |
# Filter background texture with the proper LOD bias |
179 |
TEMP tex0; |
TEMP tex0; |
302 |
fancyPaperMakers.append( (fancyBlend, "No enhancement, Just rendering text on top of Bg (Not recommended)") ) |
fancyPaperMakers.append( (fancyBlend, "No enhancement, Just rendering text on top of Bg (Not recommended)") ) |
303 |
|
|
304 |
|
|
305 |
|
allPaperMakers = whitePaperMakers + fancyPaperMakers |
306 |
|
|