Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Correctly account for lmap and hemi in FFP #1379

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/Layers/xrRender/Blender_Recorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,16 @@ void CBlender_Compile::StageSET_TMC(LPCSTR T, LPCSTR M, LPCSTR C, int UVW_channe

void CBlender_Compile::StageTemplate_LMAP0()
{
StageSET_Address(D3DTADDRESS_CLAMP);
StageSET_Color(D3DTA_TEXTURE, D3DTOP_SELECTARG1, D3DTA_DIFFUSE);
StageSET_Alpha(D3DTA_TEXTURE, D3DTOP_SELECTARG1, D3DTA_DIFFUSE);
StageSET_TMC("$base1", "$null", "$null", 1);
StageSET_Color(D3DTA_TEXTURE, D3DTOP_SELECTARG1, D3DTA_CURRENT); // select color of lmap texture, output to next stage.
StageSET_Alpha(D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT); // use current alpha, ignore lmap texture alpha
}

void CBlender_Compile::StageTemplate_HEMI()
{
StageSET_TMC("$base2", "$null", "$null", 1);
StageSET_Color(D3DTA_TEXTURE | D3DTA_ALPHAREPLICATE, D3DTOP_ADD, D3DTA_CURRENT); // select alpha of hemi texture as RGB, output to next stage.
StageSET_Alpha(D3DTA_TEXTURE, D3DTOP_SELECTARG2, D3DTA_CURRENT); // use current alpha, ignore hemi texture alpha.
}

void CBlender_Compile::Stage_Texture(LPCSTR name, u32, u32 fmin, u32 fmip, u32 fmag)
Expand Down
1 change: 1 addition & 0 deletions src/Layers/xrRender/Blender_Recorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class CBlender_Compile
void Stage_Texture(LPCSTR name, u32 address = D3DTADDRESS_WRAP, u32 fmin = D3DTEXF_LINEAR,
u32 fmip = D3DTEXF_LINEAR, u32 fmag = D3DTEXF_LINEAR);
void StageTemplate_LMAP0();
void StageTemplate_HEMI();
void Stage_Matrix(LPCSTR name, int UVW_channel);
void Stage_Constant(LPCSTR name);
void StageEnd();
Expand Down
27 changes: 19 additions & 8 deletions src/Layers/xrRender/blenders/BlenderDefault.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,22 @@ void CBlender_default::CompileFFP(CBlender_Compile& C) const
C.PassSET_Blend_SET();
C.PassSET_LightFog(false, true);

// Stage0 - Lightmap
if (ps_r1_flags.test(R1FLAG_FFP_LIGHTMAPS))
{
C.StageBegin();
C.StageTemplate_LMAP0();
C.StageEnd();
}
// target output: base_texture * (lmap_texture + (hemi_color * (hemi_texture).a)) * 2

// input: null
// output: lmap_texture (t_lmap in shader)
C.StageBegin();
C.StageTemplate_LMAP0();
C.StageEnd();

// input: lmap_texture
// currently outputs: lmap_texture + hemi_texture.a
C.StageBegin();
C.StageTemplate_HEMI();
C.StageEnd();

// Stage1 - Base texture
// input: lmap_texture + hemi_texture.a
// output: base_texture * (lmap_texture + hemi_texture.a) * 2
C.StageBegin();
C.StageSET_Color(D3DTA_TEXTURE, D3DTOP_MODULATE2X, D3DTA_CURRENT);
C.StageSET_Alpha(D3DTA_TEXTURE, D3DTOP_MODULATE2X, D3DTA_CURRENT);
Expand All @@ -136,6 +143,10 @@ void CBlender_default::CompileFFP(CBlender_Compile& C) const
C.StageBegin();
C.StageTemplate_LMAP0();
C.StageEnd();

C.StageBegin();
C.StageTemplate_HEMI();
C.StageEnd();
}
}
C.PassEnd();
Expand Down
12 changes: 12 additions & 0 deletions src/Layers/xrRender/blenders/Blender_LaEmB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ void CBlender_LaEmB::compile_2(CBlender_Compile& C)
C.StageBegin();
C.StageTemplate_LMAP0();
C.StageEnd();

C.StageBegin();
C.StageTemplate_HEMI();
C.StageEnd();
}

// Stage1 - Environment map
Expand Down Expand Up @@ -272,6 +276,10 @@ void CBlender_LaEmB::compile_3(CBlender_Compile& C)
C.StageBegin();
C.StageTemplate_LMAP0();
C.StageEnd();

C.StageBegin();
C.StageTemplate_HEMI();
C.StageEnd();
}

// Stage1 - [+] Env-map
Expand Down Expand Up @@ -343,6 +351,10 @@ void CBlender_LaEmB::compile_L(CBlender_Compile& C)
C.StageBegin();
C.StageTemplate_LMAP0();
C.StageEnd();

C.StageBegin();
C.StageTemplate_HEMI();
C.StageEnd();
}

// Stage1 - Environment map
Expand Down
8 changes: 8 additions & 0 deletions src/Layers/xrRender/blenders/Blender_Lm(EbB).cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ void CBlender_LmEbB::compile_2(CBlender_Compile& C) const
C.StageBegin();
C.StageTemplate_LMAP0();
C.StageEnd();

C.StageBegin();
C.StageTemplate_HEMI();
C.StageEnd();
}
}
C.PassEnd();
Expand Down Expand Up @@ -217,6 +221,10 @@ void CBlender_LmEbB::compile_L(CBlender_Compile& C) const
C.StageBegin();
C.StageTemplate_LMAP0();
C.StageEnd();

C.StageBegin();
C.StageTemplate_HEMI();
C.StageEnd();
}
}
C.PassEnd();
Expand Down
8 changes: 8 additions & 0 deletions src/Layers/xrRender/blenders/Blender_default_aref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ void CBlender_default_aref::CompileFFP(CBlender_Compile& C) const
C.StageBegin();
C.StageTemplate_LMAP0();
C.StageEnd();

C.StageBegin();
C.StageTemplate_HEMI();
C.StageEnd();
}

// Stage1 - Base texture
Expand Down Expand Up @@ -137,6 +141,10 @@ void CBlender_default_aref::CompileFFP(CBlender_Compile& C) const
C.StageBegin();
C.StageTemplate_LMAP0();
C.StageEnd();

C.StageBegin();
C.StageTemplate_HEMI();
C.StageEnd();
}
}
C.PassEnd();
Expand Down