- Home /
Sizeof float in cg shader
I'm trying to write a shader for unity using cg, and I'd like to know what accuracy my floats have, but I can't figure out how to use the sizeof command. When I attempt to use it, I get the error:
Shader error in 'Relativity/ColorShift': GLSL vertex shader: ERROR: 0:433: 'sizeof' : Reserved word. at line 218
218 is the line that says "CGPROGRAM".
Can anyone tell me if there's either a standard size using the arbvp1/arbfp1 profile for a float or how to use the sizeof command?
Answer by ScroodgeM · Jul 14, 2012 at 12:29 PM
float: high precision floating point. Generally 32 bits, just like float type in regular programming languages.
Type float
Approximate range -3.4 × 10^38 to +3.4 × 10^38
Precision 7 digits
I need to know exactly what precision it is using, and also why I can't use so many standard cg functions. ( defining things as double has the same error as using float).
in float structure 1 bit used for sign, 8 bits for exponent and 23 bits for significand, so it's guaranteed 7 decimal digits are stored.
which cg function can't u use? unity3d supports S$$anonymous$$3.0 and almost all functions are works ok.
would you like describe which error do you got? may be somebody here have a solution or another way to arrive you target 8)
you got this error in working model or while debugging?
i mean do you need 'sizeof' in running release version of shader?
It's more that there's a ton of functions that are supposed to be supported and unity has specific errors for, but there seems to be no way to use them. Ideally I would be able to use sizeof in the shader.
I would like to be able to use the double data type as well which is supposed to be possible, but this also has a similar error ( simply 'double' ins$$anonymous$$d of 'sizeof')
Your answer
Follow this Question
Related Questions
How can I make my own shader include file (.cginc or .glslinc)? 2 Answers
How can I get GLSL shaders to work in Unity? 0 Answers
Can a CG shader fail to work on hardware? 1 Answer
shader inverse(float4x4) function 2 Answers
Can sampler2DArray be used? 2 Answers