Question .FX (directx) coding - help needed.

Coolhand

Addon Developer
Addon Developer
Joined
Feb 7, 2008
Messages
1,150
Reaction score
7
Points
0
Website
www.scifi-meshes.com
Hey all, this is not totally related to orbiter but i'm attempting to add bump, specular and ambient mapping to this model for use in FFED3D

http://forums.frontier.co.uk/showthread.php?t=1399

you may be wondering, what is FFED3D... Remember elite? remember Frontier Elite 2? Remember its sequel: First Encounters? no?

It was really buggy, near unplayable and unfinished space exploration game when released in 1995.... however a couple of years ago a reverse engineered version was released by a russian team which makes it look a lot better. I recently found out about it and quickly developed a new cockpit model and a Viper Defense craft. However, i've been disappointed about the lack of shader support or documentation. It does apparently support shaders, but the example shader provided is very simple and in many ways looks worse than the default shader, i've attempted to add another texture and make it affect the specular, but i don't really have a clue and i've had no joy other than being able to change the constant value for specular.

I would also like to add gloss and bump, and some way of adding or increasing ambient lighting as the unshaded side of the model in the engine is completely black and looks unattractive.

I know we have some code gurus here, perhaps someone could give me a clue as to what to change, or ideally help develop the shader.

this is what i have so far

float4x4 viewprojmat; // view*proj
float4x4 worldmat; // world
float4 light; // light source
float4 lightcol; // light color
float4 ambient = 128; // ambient color


texture skin; // skin.png

sampler s_tex = sampler_state
{
texture = <skin8>;
AddressU = WRAP;
AddressV = WRAP;
MIPFILTER = LINEAR;
MINFILTER = LINEAR;
MAGFILTER = LINEAR;
};

texture skin8;

sampler SpecularTexSampler = sampler_state

{
texture = <skin8>;
AddressU = WRAP;
AddressV = WRAP;
MIPFILTER = LINEAR;
MINFILTER = LINEAR;
MAGFILTER = LINEAR;
};




struct VS_OUTPUT
{
float4 position : POSITION;
float3 normal : TEXCOORD1;
float4 color : COLOR0;
float3 tex_vu : TEXCOORD0;
float3 eyepos : TEXCOORD3;
};

VS_OUTPUT Vexel_Sh(
float4 pos : POSITION,
float3 nor : NORMAL,
float4 col : COLOR0,
float3 tex_vu : TEXCOORD0
)
{
VS_OUTPUT Out = (VS_OUTPUT)0;

Out.position = mul( mul(pos, worldmat), viewprojmat);

Out.normal = normalize(mul(nor, worldmat));
Out.color = col;
Out.tex_vu = tex_vu;
float3 worldpos = normalize(mul(pos, worldmat));
Out.eyepos = light-worldpos;

return Out;
}

float4 Pixel_Sh(
float2 tex_vu : TEXCOORD0,
float3 normal : TEXCOORD1,
float3 lightDir : TEXCOORD2,
float3 eye : TEXCOORD3,
float4 color : COLOR0
) : COLOR0

{
float4 ut;
ut.a=1;

float4 texcol = tex2D(s_tex, tex_vu);
float3 lightn = normalize(light);
float4 diffuse = saturate(dot(lightn, normal));
float3 normalized = normalize(normal);
float3 reflection = tex2D(SpecularTexSampler, tex_vu);
float3 eyen = normalize(eye);
float4 specular = tex2D(SpecularTexSampler, tex_vu);

ut.rgb = (1+ambient)*diffuse * lightcol * texcol + specular;

return ut;
}

technique PixelLight
{
pass P0
{
VertexShader = compile vs_1_1 Vexel_Sh();
PixelShader = compile ps_2_0 Pixel_Sh();
}
}



which works, but only gives diffuse shading, as the developer is russian, documentation is hard to come by.... this is the only data i've found about the shaders, crudely translated via google.

shaders introduced in patch 1.12. If the card does not support shaders, just do not use the game.
Zagruzhaeyutsya from the file directory effect.fx model. Examples are from Medel 31 (Saker) and 131 (starting planet). The main function of "Main", one pass.

In shader transmitted:

General parameters:
float4x4 viewprojmat - matrix multiplication and projection type
float4x4 worldmat - global matrix model
float4 light - the coordinates of the light source
float4 lightcol - the color of the light source
float4 ambient - the color of ambient music, is that not even the lighted parts were not completely black

More texture, if you want to make a bump or something else. Handed over even if you do not have a foreign model. 2.7 rooms reserved and not transferred.
texture skin8 - texture from a file skin8.png
texture skin9 - texture from a file skin9.png
texture skin10 - texture from a file skin10.png

For internal models (including the planet):
texture tex - current texture polygon
int texnum - number of texture (corresponds to the number of directory textures)

For external models:
texture skin - texture from a file skin.png



any help is appreciated, thanks.
 

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,883
Reaction score
2,135
Points
203
Location
between the planets
ouhhh, that reminds me, I have to finish that darn Lanner lying around on my Disk... If only I knew how to do the animations... :shifty:

I'm afraid I can't help you with your problem, but it's great to see you over there.
 

Coolhand

Addon Developer
Addon Developer
Joined
Feb 7, 2008
Messages
1,150
Reaction score
7
Points
0
Website
www.scifi-meshes.com
hmm... thats interesting, i found animation to be astoundingly easy infact... just setup the parts you want to animate with keyframes and export using panda... it converts/samples the keyframes and assigns then to animation 1, which is the animation activated by hitting the raise landing gear button.

if you wanna send me your model, i'd take a look and see if i can get it working.
 

Potsmoke66

encounter
Joined
Apr 18, 2010
Messages
3
Reaction score
0
Points
0
hi (to both), i just came by here to shake hands
and ask a question did you get any further with the shaders?

i've worked on it to, this is my result but unfortunately the lightsource is beaming through the model :shrug:
Code:
float4x4 viewprojmat;    // view*proj
float4x4 worldmat;    // world
float4 light;        // light source
float4 lightcol;        // light color
float4 ambient;        // ambient color

const float specfactor = 64;

texture skin;        // skin.png

sampler s_tex = sampler_state 
{
    texture = <skin>;
    AddressU  = WRAP;        
    AddressV  = WRAP;
    MIPFILTER = LINEAR;
    MINFILTER = LINEAR;
    MAGFILTER = LINEAR;
};

struct VS_OUTPUT
{
    float4 position : POSITION;
    float3 normal    : TEXCOORD1;
    float4 color    : COLOR0;    
    float3 tex_vu    : TEXCOORD0;
    float3 eyepos    : TEXCOORD3;
};

VS_OUTPUT Vexel_Sh(
    float4 pos        : POSITION,
    float3 nor        : NORMAL,
    float4 col        : COLOR0,
    float3 tex_vu    : TEXCOORD0
    )
{
    VS_OUTPUT Out = (VS_OUTPUT)0;

    Out.position = mul( mul(pos, worldmat), viewprojmat);

    Out.normal = normalize(mul(nor, worldmat));
    Out.color = col;
    Out.tex_vu = tex_vu;
    float3 worldpos = normalize(mul(-pos, worldmat));
    Out.eyepos = worldpos;
    
    return Out;
}

float4 Pixel_Sh(
    float2 tex_vu    : TEXCOORD0,
    float3 normal    : TEXCOORD1,
    float3 lightDir : TEXCOORD2,
    float3 eye        : TEXCOORD3,
    float4 color    : COLOR0
  ) : COLOR0
{
    float4 ut;
    ut.a=1;
    
    float4 texcol = tex2D(s_tex, tex_vu);
    float3 lightn = normalize(light);
    float4 diffuse = saturate(dot(lightn, normal));
    float3 normalized = normalize(normal);
    float3 reflection = normalize(2 * diffuse * normalized - lightn);
    float3 eyen = normalize(eye);
    float4 specular = pow(saturate(dot(reflection, eyen)), specfactor);
        
    ut.rgb = (1+ambient)*diffuse * ((lightcol / 2) + texcol) * texcol + specular;
    
    return ut;
}

technique PixelLight
{
    pass P0
    {
        VertexShader = compile vs_1_1 Vexel_Sh();
        PixelShader  = compile ps_2_0 Pixel_Sh();
    }
}
i can't show you on a pic what is the difference, because it changes the specularity so that it moves with eyepos, like in reality.

maybe you find this helpful

anyway i'm not satisfied with the use of effect.fx, because it "kills" any alpha transparency :beathead:
 
Last edited:
Top