Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

depth of field D3D

Discussion in 'Shaders' started by arioch82, Oct 13, 2010.

  1. arioch82

    arioch82

    Joined:
    Dec 3, 2009
    Posts:
    253
    hi everyone,

    i was having some problem with DOF and reading http://unity3d.com/support/documentation/Components/SL-PlatformDifferences.html I found out that I should add this piece of code

    Code (csharp):
    1. // On D3D when AA is used, the main texture  scene depth texture
    2. // will come out in different vertical orientations.
    3. // So flip sampling of the texture when that is the case (main texture
    4. // texel size will have negative Y).
    5. #if SHADER_API_D3D9
    6. if (_MainTex_TexelSize.y < 0)
    7.         uv.y = 1-uv.y;
    8. #endif
    9.  
    to my shader

    Code (csharp):
    1.  
    2. Shader "Transparent/VertexLit Colored" {
    3.     Properties {
    4.         _Color ("Main Color", Color) = (1,1,1,1)
    5.         _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
    6.     }
    7.  
    8.     SubShader {
    9.         Alphatest Greater 0
    10.         Tags { "Queue" = "Transparent" }
    11.    
    12.         Blend SrcAlpha OneMinusSrcAlpha
    13.         ColorMask RGBA
    14.         Pass {
    15.             ColorMaterial AmbientAndDiffuse
    16.             Lighting Off
    17.  
    18.  
    19.             SetTexture [_MainTex] {
    20.                 Combine texture * primary
    21.             }
    22.             SetTexture [_MainTex] {
    23.                 ConstantColor [_Color]
    24.                 Combine previous * constant, previous * constant
    25.             }
    26.         }
    27.     }
    28.  
    29.     Fallback "Alpha/VertexLit", 1
    30. }
    but I'm not really a shader programmer so I don't know where/how to add it...
    i'm trying to convert my shader to a CGPROGRAM without luck...

    any helps?

    Thank you
     
    Last edited: Oct 15, 2010
  2. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,631
    What kind of problem? Inverted picture? If you take the "uv.y = 1-uv.y;" out of the the IF statement, does it work? What other effects do you have on the main camera?
     
  3. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    That shader isn't a full-screen image effect. You don't need to worry about that code for it. If you're seeing the image on the screen inverted, then you're using an out-of-date version of an image effect. Make sure you're using the ones from the latest Pro Standard Assets for your version of Unity.
     
  4. arioch82

    arioch82

    Joined:
    Dec 3, 2009
    Posts:
    253
    the textures with my shader are shown correctly but is like the DOF is applied to the inverted picture
    the problem is that my shader is not in a CGPROGRAM so i don't know "how/where to add" that piece of code...

    I'm using the latest DOF available and If I select another shader for my material the DOF is shown correctly that's why I think that has to be something in that shader...

    Also if it's useless to add that piece of code to my shader, can you please help me to convert it into a CGPROGRAM?
    I'm trying to study shader programming, I've read about vertex fragment block but I've no idea on how to convert it (like setting ColorMaterial, or combine with "primary" or the ColorMask...); would be really useful for me to see a 1-1 conversion for a better understanding of how CG works.

    Thank you
     
  5. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Can you post a screen shot of what happens when you use this shader in conjunction with depth of field? That might help someone figure out what's going on. As far as I can tell from what you've said, you're trying to fix the problem in the wrong place right now.
     
  6. arioch82

    arioch82

    Joined:
    Dec 3, 2009
    Posts:
    253
    sorry can't post a screenshot... I'm working for a company and the project has not been revealed yet, I can't share any shot.

    the effect that I have is the DOF showing the blurred edges of the mesh rendered on the mesh itself as it's up and down are inverted, e.g. with a character it will show something like the blurred shape of the head at the feet level and the blurred feet edges on the head.

    If you could just please help me converting that shader into a CGPROGRAM it would help a lot, I would really give it a try adding that piece of code.

    sorry for my english, can't explain myselef in a better way :(
     
  7. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    That UV inversion code has nothing to do with the shader you posted. If you converted the shader and put the UV code in there, your texture would be applied upside-down in UV space, not in screen space.

    Can't you reproduce the problem with your shader and default Unity resources? Nobody needs to see any of your game assets other than that shader.
     
  8. arioch82

    arioch82

    Joined:
    Dec 3, 2009
    Posts:
    253
    ok will try to reproduce it with a standard asset.

    anyway as I said I'm studying shaders (or trying to) and I'd love to see a conversion of that shader (looks like a simple one), can you please help me with that?

    Cheers