www.xbdev.net
xbdev - software development
Thursday June 26, 2025
Home | Contact | Support | ShaderX.. Making our graphics card work for us..
>>
     
 

ShaderX..

Making our graphics card work for us..

 

Basic Effect Files with Directx and X-Files


We have Effect Files, but we can also link them directly with models—one popular modeling format in DirectX is the X-File format, which can specify which Effect Files should be used. X-Files store 3D models, including their geometry, textures, and animations, making it easier to import complex objects into a Direct3D scene.

Effect Files define how these models are rendered, controlling everything from shading techniques to lighting models. By associating an X-File with an Effect File, we can dictate how the model appears—whether it has realistic reflections, a stylized toon-shaded look, or advanced lighting effects. The X-File itself contains material and texture information, but without an Effect File, rendering is limited to basic fixed-function graphics. Applying an Effect File enables programmable shaders in HLSL, allowing finer control over appearance and rendering optimizations.


Hide effects in x-files. Image dipicts the scene when
Hide effects in x-files. Image dipicts the scene when 'Red' is shown hiding in an egg (from "The Angry Birds Movie") - he was a surprise - as with the x-file format - it has more than just model data - it has a whole lot more inside.


The X-File holds the raw data of a 3D object, it doesn't dictate how the model is rendered or how lighting interacts with its surfaces. That’s where Effect Files step in. Effect Files contain shader programs written in HLSL (High-Level Shader Language) and define rendering techniques like lighting, reflections, and texture blending.

Look at a little example


Basic effect file (basic.fx)

// Basic effect file using a simple shader
technique BasicTech
{
    
pass P0
    
{
        
VertexShader compile vs_2_0 BasicVS();
        
PixelShader compile ps_2_0 BasicPS();
    }
}

float4 BasicVS(float4 pos POSITION) : SV_POSITION
{
    return 
pos// Simple passthrough vertex shader
}

float4 BasicPS(float4 color COLOR) : SV_Target
{
    return 
color// Basic coloring pixel shader
}



Simple model (cube.x) - we specify the Effect File to be used through a mesh attribute, linking it directly to the model.

xof 0303txt 0032
Frame Cube
{
    
// Transformation Matrix
    
FrameTransformMatrix {
        
1.00.00.00.0,
        
0.01.00.00.0,
        
0.00.01.00.0,
        
0.00.00.01.0;
    }

    
Mesh CubeMesh
    
{
        
8// Vertices
        
---1--11 1 -1; -1 1 -1;
        -
-1 1-1 11 1 1; -1 1 1;

        
6// Faces
        
40,1,2,3;
        
44,5,6,7;
        
40,1,5,4;
        
41,2,6,5;
        
42,3,7,6;
        
43,0,4,7;

        
// Reference to Effect File
        
EffectInstance {
            
"basic.fx"; <---****NOTICE THIS*****
        }
    }
}


Just to note - can also use the 'frame' attribute to link to the effect file (not just the mesh attribute).












 
Advert (Support Website)

 
 Visitor:
Copyright (c) 2002-2025 xbdev.net - All rights reserved.
Designated articles, tutorials and software are the property of their respective owners.