Jump to content
  • Advertisement
Sign in to follow this  
CodeReaver

Fixed function pipeline to vertex shader:

This topic is 2548 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have an old MDX program that I'm preparing to convert to XNA, so I need to make sure my shader technique is doing the same as my fixed function one. I also want to make sure I'm not setting any device states that were only needed for the FFP as they'll either do nothing or prevent the effect file from loading.

I think I remember reading that ColorOp and AlphaOp were removed with the fixed function pipeline, so I'm guessing all of ColorArg1, ColorArg2, AlphaArg1 and AlphaArg2 will have gone too along with MaterialAmbient, MaterialDiffuse MaterialAmbientSource, MaterialDiffuseSource etc. I've used these in the effect below along with several other effect states, but I havn't been able to find a definitive list of which states were removed with the FFP. Would anyone be able to refer me to one or if possible have a look over my effect file below? I imagine there's still a few more FFP features

Another thing I wanted to ask was how I might be able to use lighting and vertex colors at the same time. I think I managed to do that in the FFP, but not in my shader. I guess I'd just multiply the final lighting diffuse by the diffuse in the vertex color.


[font="Consolas"][font="Consolas"]

texture xTexture0;

bool bLighting;

bool bColorVertex;

int iCullMode;

int iFillMode;

int iColorOperation;

int iAlphaOperation;

int iTextureFilter;

int iAmbientMaterialSource;

int iDiffuseMaterialSource;

float4x4 xWorld : WORLD;

float4x4 xView : VIEW;

float4x4 xWorldViewProj : WORLDVIEWPROJ;

float4 xMaterialAmbient;

float4 xMaterialDiffuse;

float4 xMaterialSpecular;

float4 xMaterialEmissive;

struct Light

{

float4 Position;

float4 Direction;

float4 Diffuse;

float4 Specular;

float4 Ambient;

float4 Attenuation;

};

Light xLights[1];

//application to vertex structure

struct a2v

{

float4 position : POSITION0;

float3 normal : NORMAL;

float4 diffuse : COLOR0;

float2 tex0 : TEXCOORD0;

};

//vertex to pixel processing structure

struct v2p

{

float4 position : POSITION0;

float4 color : COLOR0;

float2 tex0 : TEXCOORD0;

};

void vs( in a2v IN, out v2p OUT )

{

OUT.position = mul(IN.position, xWorldViewProj);

float3 xWorldNormal = normalize(mul(IN.normal, xWorld));

float3 xWorldPosition = mul(IN.position, xWorld);

float3 xCameraPosition = mul(xWorldPosition, xView);

if (bLighting)

{

float4 diffuse = float4(0,0,0,1);

float4 specular = float4(0,0,0,1);

for (int i = 0; i < 1; i++)

{

float3 toLight = xLights.Position.xyz - xWorldPosition;

float lightDist = length(toLight);

float fAttenuation = 1.0 / dot(xLights.Attenuation, float4(1, lightDist, lightDist * lightDist, 0));

float3 lightDir = normalize(xLights.Direction); // normalize(toLight);

float3 halfAngle = normalize(normalize(-xCameraPosition) + lightDir);

diffuse += max(0, dot(lightDir, xWorldNormal) * xLights.Diffuse * fAttenuation) + xLights.Ambient;

specular += max(0, pow(dot(halfAngle, xWorldNormal), 64) * xLights.Specular * fAttenuation);

}



OUT.color = diffuse + specular;

}

else

{

OUT.color = IN.diffuse; //float4(1,1,1,1);

}

OUT.tex0 = IN.tex0;

}

float4 ps() : COLOR

{

return float4(1,1,1,1);

}

technique FixedFunctionPipeline

{

pass p0

{

Texture[0] = <xTexture0>;

MaterialAmbient = <xMaterialAmbient>;

MaterialDiffuse = <xMaterialDiffuse>;

Lighting = <bLighting>;

ColorVertex = <bColorVertex>;

CullMode = <iCullMode>;

FillMode = <iFillMode>;

ZEnable = TRUE;

ZWriteEnable = TRUE;

DitherEnable = TRUE;

SpecularEnable = FALSE;

NormalizeNormals = TRUE;

AlphaTestEnable = TRUE;

AlphaFunc = GREATER;

AlphaRef = 0xA0;

ColorOp[0] = <iColorOperation>;

ColorArg1[0] = TEXTURE;

ColorArg2[0] = CURRENT;

AlphaOp[0] = <iAlphaOperation>;

AlphaArg1[0] = TEXTURE;

AlphaArg2[0] = DIFFUSE;

MagFilter[0] = <iTextureFilter>;

MinFilter[0] = <iTextureFilter>;

AmbientMaterialSource = <iAmbientMaterialSource>;

DiffuseMaterialSource = <iDiffuseMaterialSource>;

WorldTransform[0] = <xWorld>;

}

}

technique Shader

{

pass p0

{

vertexshader = compile vs_1_1 vs();

//pixelshader = compile ps_1_1 ps();



Texture[0] = <xTexture0>;

MaterialAmbient = <xMaterialAmbient>;

MaterialDiffuse = <xMaterialDiffuse>;

Lighting = <bLighting>;

ColorVertex = <bColorVertex>;

CullMode = <iCullMode>;

FillMode = <iFillMode>;

ZEnable = TRUE;

ZWriteEnable = TRUE;

DitherEnable = TRUE;

SpecularEnable = FALSE;

NormalizeNormals = TRUE;

AlphaTestEnable = TRUE;

AlphaFunc = GREATER;

AlphaRef = 0xA0;

ColorOp[0] = <iColorOperation>;

ColorArg1[0] = TEXTURE;

ColorArg2[0] = CURRENT;

AlphaOp[0] = <iAlphaOperation>;

AlphaArg1[0] = TEXTURE;

AlphaArg2[0] = DIFFUSE;

MagFilter[0] = <iTextureFilter>;

MinFilter[0] = <iTextureFilter>;

AmbientMaterialSource = <iAmbientMaterialSource>;

DiffuseMaterialSource = <iDiffuseMaterialSource>;

WorldTransform[0] = <xWorld>;

}

}

[/font][/font]


Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!