depth of field D3D

hi everyone,

i was having some problem with DOF and reading Unity - Manual: Writing shaders for different graphics APIs I found out that I should add this piece of code

// On D3D when AA is used, the main texture  scene depth texture
// will come out in different vertical orientations.
// So flip sampling of the texture when that is the case (main texture
// texel size will have negative Y).
#if SHADER_API_D3D9
if (_MainTex_TexelSize.y < 0)
        uv.y = 1-uv.y;
#endif

to my shader

Shader "Transparent/VertexLit Colored" {
	Properties {
		_Color ("Main Color", Color) = (1,1,1,1)
		_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
	}

	SubShader {
		Alphatest Greater 0
		Tags { "Queue" = "Transparent" }
	
		Blend SrcAlpha OneMinusSrcAlpha
		ColorMask RGBA
		Pass {
			ColorMaterial AmbientAndDiffuse
			Lighting Off


			SetTexture [_MainTex] {
				Combine texture * primary
			}
			SetTexture [_MainTex] {
				ConstantColor [_Color]
				Combine previous * constant, previous * constant
			}
		}
	}

	Fallback "Alpha/VertexLit", 1
}

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

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?

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.

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

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.

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 :frowning:

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.

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