shaders basic question

Started by
1 comment, last by GameDev.net 17 years, 7 months ago
hey is it possible to work with both pixel and vertex shaders together in a sinlge program. if so Can you tell how do i go about. Thank you
Advertisement
By "one program" do you mean in the same file ?

Yes you can combine the pixel and vertex shader into the same shader file, then deal with techniqes and passes in your code rather than indivdual pixel and vertex programs, though this is just a conveinence feature underneath the system will just be calling SetPixelShader/SetVertexShader:

VertexOut SimpleVS (VertexIn In){	VertexOut Out=(VertexOut)0;	Out.oPosition		= mul(In.position , modelViewProj  );	Out.oColor 			= In.color;	Out.oDiffuseUV 		= In.uv;	Out.oLocalPos		= In.position;	Out.oLocalNormal	= In.normal;	return Out;}float4 SimplePS(float4 color_in      : COLOR, float2 uv : TEXCOORD0,  float3 localPos : TEXCOORD1,  float3 normal : TEXCOORD2) : COLOR{..}technique Simple{    pass p0     {				VertexShader = compile vs_3_0 SimpleVS();		PixelShader = compile ps_3_0 SimplePS();	}}	


You cannot combine pixel and vertex shader commands in the same actual program as they do different things in the graphics hardware (you cannot have a single "main" function that is used by the pixel and vertex shader). The "unified" shader archtitecture that is implemented by ATI just means the different shaders share the same registers ect. (so that GPR that are not used by the vertex shader can be used by the pixel shader and vice versa) they are still doing very diffrent things.
The most common way is to combine shaders, actually I can't think of one single time where I just used one of them.

This topic is closed to new replies.

Advertisement