Sign in to follow this  
reuomi

Beginer to effect editor and .fx files

Recommended Posts

reuomi    139
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.

Share this post


Link to post
Share on other sites
Armadon    1091
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.

Share this post


Link to post
Share on other sites
reuomi    139
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?

Share this post


Link to post
Share on other sites
reuomi    139
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"; // model

int 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 intensity
float4 I_a
<
bool SasUiVisible = false;
string SasBindAddress= "Sas.AmbientLight[0].Color";
> = { 0.1f, 0.1f, 0.1f, 1.0f }; // ambient

float4 I_d
<
bool SasUiVisible = false;
string SasBindAddress= "Sas.DirectionalLight[0].Color";
> = { 1.0f, 1.0f, 1.0f, 1.0f }; // diffuse

float4 I_s
<
string SasUiLabel = "light specular";
string SasUiControl = "ColorPicker";
> = { 1.0f, 1.0f, 1.0f, 1.0f }; // specular

// material reflectivity
float4 k_a : MATERIALAMBIENT
<
string SasUiLabel = "material ambient";
string SasUiControl = "ColorPicker";
> = { 1.0f, 1.0f, 1.0f, 1.0f }; // ambient

float4 k_d : MATERIALDIFFUSE
<
string SasUiLabel = "material diffuse";
string SasUiControl = "ColorPicker";
> = { 1.0f, 1.0f, 1.0f, 1.0f }; // diffuse

float4 k_s : MATERIALSPECULAR
<
string SasUiLabel = "material specular";
string SasUiControl = "ColorPicker";
> = { 1.0f, 1.0f, 1.0f, 1.0f }; // specular

float 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

// texture
texture Tex0
<
string SasUiLabel = "Texture Map";
string SasUiControl= "FilePicker";
string name = "c:/Texture1.dds";
>;

// transformations
float4x4 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;
}
}


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this