Skip to content

Putting HLSL in the shader file

Zack edited this page Nov 5, 2024 · 5 revisions

Replace PixelShader = <pSdr> with PixelShader = compile ps_1_1 ShaderName() to use the game's compiler

// Thanks to shader playground, and working on figuring out the UC shaders, I know what to do here now (in theory)

float4x4 localToScreen : register(c0);
float4x4 localToWorld : register(c4);
float4 CAMERA : register(c8);

struct VSInput
{
    float3 pos : POSITION;
    float3 nrm : NORMAL;
    float4 diff : COLOR;
    float2 uv : TEXCOORD0;
}

struct PSInput
{
    float4 pos : POSITION; // Has to be here but I'm not sure if it can be given to the pixel shader
    float2 uv : TEXCOORD0;
    float4 AMBIENT : COLOR0;
    float4 EXTRA : COLOR1;
};

PSInput MyVertexShader(VSInput i)
{
    PSInput o;

    o.pos = mul(i.pos, localToScreen);
    o.uv = i.uv;
    //...

    return o;
}


float4 SHADOW : register(c2);

// There's a problem that makes this a bit tedious
// constants can't be declared in the code like usual, as FlatOut 2 wants them defined in the pass.
// You'll have to bind it to the register outside the function like so
float4 blue : register(c3);

// I guess for consistency you use s[n] instead of t[n].
sampler2D colour : register(s0);
samplerCUBE specular : register(s1);
sampler2D dirt : register(s2);
samplerCUBE lighting : register(s3);

float4 MyPixelShader(PSInput i) : COLOR
{
    return tex2D(colour, i.uv) * blue;
}

// The technique and pass name is the same across everything
Technique T0
{
    Pass P0
    {
        PixelShaderConstantF[3] = float4(0.0, 0.0, 1.0, 1.0); // blue

        // In FlatOut 2 the pass can require either a bit of setup or a lot depending on the shader
        Texture[0] = <Tex0>;
	Texture[1] = <Tex1>;
	Texture[2] = <Tex2>;
	Texture[3] = <Tex3>;
        

        VertexShader = compile vs_1_1 MyVertexShader();
        PixelShader = compile ps_1_1 MyPixelShader();
    }
}
Clone this wiki locally