This topic is now archived and is closed to further replies.

How to replace _bx2 modifier from ps.1.4 in ps.2.0

This topic is 5311 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to convert my pixel shader for Per pixel diffuse lighting to 2.0 format. The problem is, that the normal map is stored in signed format for the normals. In ps 1.4 i could use the _bx2 modfier for the sampled normal value in dp3 to get the desired result. But this modifier is not present in ps 2.0. I tried to change the format of the normal map from D3DFTM_A8R8G8B8 to D3DFMT_Q8W8U8V8 but then the Normal map computation fails. Here is the code of my 2 pixel shaders the one on top is the 1.4 code and directly beneath it outcomented is the 2.0 version
; Constant registers 
; Used input registers
; t0 - color / bump coordinates
; t1 - light vector in tangent space
; Used input texture stages
; stage0 - ambient texture
; stage1 - normal texture
; Output
; r0 - output color

def c5, 0.5, 1.0, 0.0, 0.0
texld r0, t0 			; color map
texld r1, t0 			; normal map
texcrd,		; Light Vector

dp3 r3, r1_bx2, r2 		; dot(normal, light)
mul r0, r0, r3			; modulate with base

add r0, r0, c0			; modulate ambiente light


;dcl	t0
;dcl	t1
;dcl	v0
;dcl_2d	s0
;dcl_2d	s1

;def c5, 0.5, 1.0, 0.0, 0.0

;texld r0, t0, s0		; color map
;texld r1, t0, s1		; normal map

;dp3 r3, r1, t1 		; dot(normal, light)
;mul r0, r0, r3			; modulate with base

;add r0, r0, c0			; modulate ambiente light
;mov oC0, r0
[edited by - CommanderXXL on May 28, 2003 8:08:17 AM]

Share this post

Link to post
Share on other sites
You need to use a mad instruction.

Put this line above "def c5, 0.5, 1.0, 0.0, 0.0":

def c1, 2.0, 1.0, 0.0, 0.0

Put this line under "texld r1, t0, s1"

mad r1.rgb, r1, c1.x, -c1.y

I guess the reason for not having _bx2 is that ps_2_0 uses floating point rather than fixed point, so _bx2 can''t be optimised using bit shifting, but just needs a full floating point op. Hence no reason to make people think they''re getting a speed up by using _bx2.


Matt Halpin

Share this post

Link to post
Share on other sites