Beginer to effect editor and .fx files

Started by
3 comments, last by reuomi 18 years, 6 months ago
I've been tinkering around before i jump full onto buildign all my maps for my game project. I've noticed that my personaly made fx files run in effect editor, but only the sample files in the dx sdk will actualy show up when i export through Maya. Then i looked aroud and have seen things abotu compiling FX files, i dont quite understand this, how is this done? i've just been savign the fx files.
Indy to Pro: Journeyhttp://phiendstudios.blogspot.com
Advertisement
Hi there reuomi,
How are you doing?

The Problem
FX files and how they are used.

The Solution
With effect files, DirectX makes it very simple to use. What it does is provide you with the D3DXCreateEffect method that will create a method from the given source ASCII or binary file. If you want to use effect files you will generally follow this pattern.

1) Write your effect in the editor of your choice (notepad, fx composers, effectedit...)
2) Load the effect in your engine using D3DXCreateEffect(). This will create an effect for you that you can use to render objects in your world. It will give you a ID3DXEffect.
3) You then use the ID3DXEffect and set it's parameters.
4) You will then begin the technique, begin a pass.
5) Render your objects
6) End the pass, end the technique.

I hope this helps.
PS: As far as your question goes. Direct3D compiles your effect files using the D3DXCreateEffect() or you can use the Effect Command Line Compiler which is included with the SDK.
this is another API question:

How do i turn off Backface culling in a effect file? i've tried to find it in the api reference but i cant. any help?
Indy to Pro: Journeyhttp://phiendstudios.blogspot.com
CullMode = None;
Place this in the technique, like this

technique Bleh
{
pass p0
{
CullMode = None;
}
}
Thanks for the help, but i noticed somthign really weird happend when i turned off the cull mode. The backfaces seem to overlap the polygons they should be showing. I am useing Alpha blending to billboard a clipmap onto a polygon for trees. What happens is when i change the angle to look around the transparency paints blue (background color) onto what ever it overlaps rather than alowing the object behind it to be visable. can anyone help me out?


here is my effect code if anyone needs it, the texture is a basic dds with transparency values:

 //// Simple Lighting Model// Copyright (c) Microsoft Corporation. All rights reserved.//// Note: This effect file works with EffectEdit.// Note: This effect file is SAS 1.0.1 compliant and will work with DxViewer.//int sas : SasGlobal<    bool SasUiVisible = false;    int3 SasVersion= {1,1,0};>;string XFile< bool SasUiVisible = false; > = "tiger\\tiger.x";   // modelint    BCLR< bool SasUiVisible = false; > = 0xff202080;          // background// light direction (view space)float3 lightDir <      bool SasUiVisible = false;    string SasBindAddress= "Sas.DirectionalLight[0].Direction";    string UIDirectional = "Light Direction"; > = {0.577, -0.577, 0.577};// light intensityfloat4 I_a<    bool SasUiVisible = false;    string SasBindAddress= "Sas.AmbientLight[0].Color";> = { 0.1f, 0.1f, 0.1f, 1.0f };    // ambientfloat4 I_d<    bool SasUiVisible = false;    string SasBindAddress= "Sas.DirectionalLight[0].Color";> = { 1.0f, 1.0f, 1.0f, 1.0f };    // diffusefloat4 I_s<    string SasUiLabel = "light specular";    string SasUiControl = "ColorPicker";> = { 1.0f, 1.0f, 1.0f, 1.0f };    // specular// material reflectivityfloat4 k_a : MATERIALAMBIENT<    string SasUiLabel = "material ambient";    string SasUiControl = "ColorPicker";> = { 1.0f, 1.0f, 1.0f, 1.0f };    // ambientfloat4 k_d : MATERIALDIFFUSE<    string SasUiLabel = "material diffuse";    string SasUiControl = "ColorPicker";> = { 1.0f, 1.0f, 1.0f, 1.0f };    // diffusefloat4 k_s : MATERIALSPECULAR<    string SasUiLabel = "material specular";    string SasUiControl = "ColorPicker";> = { 1.0f, 1.0f, 1.0f, 1.0f };    // specularfloat  k_n   : MATERIALPOWER<    string SasUiLabel = "Material Specular Power";    string SasUiControl = "Slider";     float SasUiMin = 1.0f;     float SasUiMax = 32.0f;     int SasUiSteps = 31;> = 8.0f;                           // power// texturetexture Tex0 <     string SasUiLabel = "Texture Map";    string SasUiControl= "FilePicker";    string name = "c:/Texture1.dds"; >;// transformationsfloat4x4 World      : WORLD<    bool SasUiVisible = false;    string SasBindAddress= "Sas.Skeleton.MeshToJointToWorld[0]";>;float4x4 View       : VIEW<    bool SasUiVisible = false;    string SasBindAddress= "Sas.Camera.WorldToView";>;float4x4 Projection : PROJECTION<    bool SasUiVisible = false;    string SasBindAddress= "Sas.Camera.Projection";>;struct VS_OUTPUT{    float4 Pos  : POSITION;    float4 Diff : COLOR0;    float4 Spec : COLOR1;    float2 Tex  : TEXCOORD0;};VS_OUTPUT VS(    float3 Pos  : POSITION,     float3 Norm : NORMAL,     float2 Tex  : TEXCOORD0){    VS_OUTPUT Out = (VS_OUTPUT)0;    float3 L = -lightDir;    float4x4 WorldView = mul(World, View);    float3 P = mul(float4(Pos, 1), (float4x3)WorldView);  // position (view space)    float3 N = normalize(mul(Norm, (float3x3)WorldView)); // normal (view space)    float3 R = normalize(2 * dot(N, L) * N - L);          // reflection vector (view space)    float3 V = -normalize(P);                             // view direction (view space)    Out.Pos  = mul(float4(P, 1), Projection);             // position (projected)    Out.Diff = I_a * k_a + I_d * k_d * max(0, dot(N, L)); // diffuse + ambient    Out.Spec = I_s * k_s * pow(max(0, dot(R, V)), k_n/4);   // specular    Out.Tex  = Tex;                                           return Out;}sampler Sampler<bool SasUiVisible = false;> = sampler_state{    Texture   = (Tex0);    MipFilter = LINEAR;    MinFilter = LINEAR;    MagFilter = LINEAR;};float4 PS(    float4 Diff : COLOR0,    float4 Spec : COLOR1,    float2 Tex  : TEXCOORD0) : COLOR{    return tex2D(Sampler, Tex) * Diff + Spec;}technique TVertexShaderOnly{    pass P0    {        // lighting        Lighting       = FALSE;        SpecularEnable = TRUE;        // samplers        Sampler[0] = (Sampler);        // texture stages        ColorOp[0]   = MODULATE;        ColorArg1[0] = TEXTURE;        ColorArg2[0] = DIFFUSE;        AlphaOp[0]   = MODULATE;        AlphaArg1[0] = TEXTURE;        AlphaArg2[0] = DIFFUSE;        ColorOp[1]   = DISABLE;        AlphaOp[1]   = DISABLE;  // Disable texture stage 1        AlphaBlendEnable =true;        DestBlend = 4;        SrcBlend = 4;        ColorOp[1] = Disable;        AlphaOp[1] = Disable;   CullMode = NONE;        // shaders        VertexShader = compile vs_1_1 VS();        PixelShader  = NULL;    }}
Indy to Pro: Journeyhttp://phiendstudios.blogspot.com

This topic is closed to new replies.

Advertisement