Discussion:
How achieve shift operation in Shader
(too old to reply)
SanS
2008-09-17 15:41:52 UTC
Permalink
Hi all.

My doubt is how achieve shift operation in Shader.

// CPU code.

byte lsbValue;
byte msbValue;
short t = ( msbValue<<8) + lsbValue;


// How to achieve this in shader.

float fmsb;
float flsb;

float fShortValue = ( ( fmsb * MAXVALUE) *MAXVALUE + flsb*MAXVALUE ) /
( MAXVALUE*MAXVALUE )

where maxVALUE IS maximum value of a component ( say 256 )
is it correct.
Jan Bruns
2008-10-02 02:39:15 UTC
Permalink
Post by SanS
My doubt is how achieve shift operation in Shader.
// CPU code.
byte lsbValue;
byte msbValue;
short t = ( msbValue<<8) + lsbValue;
// How to achieve this in shader.
float fmsb;
float flsb;
float fShortValue = ( ( fmsb * MAXVALUE) *MAXVALUE + flsb*MAXVALUE ) /
( MAXVALUE*MAXVALUE )
where maxVALUE IS maximum value of a component ( say 256 )
is it correct.
Depends on how the data was converted to float.

With d3d, it is common to have implicit integer to float conversion like

f = intvalue / (q-1);

where q is a power of 2 (this is documtented in the D3DDECLTYPE
description of the DX SDK, for example).

So a compatible, manual extension to double-precision would
look like

x = ( a*(q-1)*q + b*(q-1) ) / (q*q-1)

not taking signs into account.

Gruss

Jan Bruns

Loading...