surface_shader reading specific values causes wrong color
OnkelDagobert
Join Date: 2013-01-31 Member: 182694Members
in Modding
Hi,
I'm having Problems writing the shader for a material.
but if i try to read some vars it give me a total wrong result:
the material color ALLWAYS becomes purple, no matter what i write into material.emissive
this happens if i try to read following vars:
- viewPoint
- worldToScreenMatrix
- worldToCameraMatrix
and maybe some more
even though it makes the Color purple it reads the right values from this varibales
does anyone know what to do?
or is there a way get the distance from the cam to the displaying object without using viewPoint?
I'm having Problems writing the shader for a material.
<shader> <inputs> </inputs> <params> <param name="osPosition">true</param> <param name="wsPosition">true</param> <param name="wsNormal">true</param> <param name="vsNormal">true</param> <param name="twoSided">true</param> <param name="alphaTest">true</param> </params> <code> <![CDATA[ void MaterialShader(in Material_Input input, inout Material material) { material.emissive = float3(0,0,1); } ]]> </code> </shader>this shader works fine and gives me this (the blue glass):
but if i try to read some vars it give me a total wrong result:
<shader> <inputs> </inputs> <params> <param name="osPosition">true</param> <param name="wsPosition">true</param> <param name="wsNormal">true</param> <param name="vsNormal">true</param> <param name="twoSided">true</param> <param name="alphaTest">true</param> </params> <code> <![CDATA[ void MaterialShader(in Material_Input input, inout Material material) { float3 neverused = viewPoint.xyz ; material.emissive = float3(0,0,1); } ]]> </code> </shader>
the material color ALLWAYS becomes purple, no matter what i write into material.emissive
this happens if i try to read following vars:
- viewPoint
- worldToScreenMatrix
- worldToCameraMatrix
and maybe some more
even though it makes the Color purple it reads the right values from this varibales
does anyone know what to do?
or is there a way get the distance from the cam to the displaying object without using viewPoint?
Comments
I can not see where this variable is defined nor is it an intrinsic HLSL function.
So maybe you are accessing an undefinded variable, causing a shader compile error and as a result get some default or uninitialized material instead ?
Have you had a look at the debug output messages withing the console ?
and as i said the value in viewPoint is correct. I tested it by adding a glow to the material depending on the viewPoint
it seems that the purple color is the right behavior.
the shader used the default values specified in Deferred.shader_template:
so a fixed it
but why does the shader sometimes use these default values and sometimes not?