Search Unity

How to use _CameraToWorld builtin value?

Discussion in 'Shaders' started by SpookyCat, Nov 30, 2010.

  1. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,768
    Hi All
    Still struggling with my reconstruction of world space coords and I am wondering if I am doing something very wrong with the built in value _CameraToWorld. It says in the Unity 3.0 release notes that
    Thing is I can't find the param _CameraToWorld in any of the .cginc files, (I can find other builtin values such as UNITY_MATRIX_MV etc) if I try to use the value I get an error unless I add the value myself to my shader ie float4x4 _CameraToWorld and it seems if I have to do that that if it is indeed a builtin value, me adding it to my shader is confusing the issue.

    Can anyone tell me the correct way to make use of this value, do I need to add it myself to my shader? Is there an include Iam missing? Do I need to do a SetMatrix to set the value of this builtin value?
    Thanks
    Chris
     
  2. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Have you tried just using _CameraToWorld after declaring it in your shader? That's usually all you have to do to get Unity's built-in values to work.
     
  3. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,768
    Thanks Daniel, been playing and it is working, just getting confused that you have to add some params for builtin values and for others you dont. Still cant get my world space calc to move away from the corner :(
     
  4. Battle Angel Alita

    Battle Angel Alita

    Joined:
    Mar 29, 2010
    Posts:
    44
    I tried to do this too. Unsucessfull too.
    One thing what i realize it's UNITY_MATRIX_MV is useless, in post-process shaders it's allways identity. So i just get camera.cameraToWorldMatrix in script, and pass it in to shader.
     
    Last edited: Nov 30, 2010
  5. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,768
    Arr that's interesting, did notice something screwy with my ray values always seeming to be 0. Would be nice if someone from Unity could explain the state of the matrices when used from a Post Effect shader. Also I can't find any direction information on what kind of values get passed for the quad used to render the effect, in one of the cginc files it says
    If the ray is already in the texcoord why is it being recalculated inside the shader code below that Iam took from a Unity shader. All seems very vague. And what is the purpose of the * float3(-1, -1 1)?
    It would be nice if some clearer info could be given on this. I realise Iam very far from being a shader expert, expecially in Unity, but a little more info would be handy :) Or have I missed a section in the docs, guess I need to go double check.
     
    Last edited: Nov 30, 2010