Skip to content

Commit

Permalink
RTSS: normalmap - parallax texcoord should also affect normalmap lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
paroj committed May 11, 2023
1 parent c181321 commit bf9613b
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions Components/RTShaderSystem/src/OgreShaderExNormalMapLighting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,22 @@ bool NormalMapLighting::createCpuSubPrograms(ProgramSet* programSet)
auto normalMapSampler = psProgram->resolveParameter(GCT_SAMPLER2D, "gNormalMapSampler", mNormalMapSamplerIndex);
fstage.callFunction(SGX_FUNC_FETCHNORMAL, normalMapSampler, psInTexcoord, newViewNormal);

if (mNormalMapSpace == NMS_PARALLAX)
{
// assuming: lighting stage computed this
auto vsOutViewPos = vsMain->resolveOutputParameter(Parameter::SPC_POSITION_VIEW_SPACE);
auto viewPos = psMain->resolveInputParameter(vsOutViewPos);

// TODO: user specificed scale and bias
fstage.callFunction("SGX_Generate_Parallax_Texcoord", {In(normalMapSampler), In(psInTexcoord), In(viewPos),
In(Vector2(0.04, -0.02)), Out(psInTexcoord)});

// overwrite texcoord0 unconditionally, only one texcoord set is supported with parallax mapping
// we are before FFP_PS_TEXTURING, so the new value will be used
auto texcoord0 = psMain->resolveInputParameter(Parameter::SPC_TEXTURE_COORDINATE0, GCT_FLOAT2);
fstage.assign(psInTexcoord, texcoord0);
}

if (mNormalMapSpace & NMS_TANGENT)
{
auto vsInTangent = vsMain->resolveInputParameter(Parameter::SPC_TANGENT_OBJECT_SPACE);
Expand All @@ -115,22 +131,6 @@ bool NormalMapLighting::createCpuSubPrograms(ProgramSet* programSet)
fstage.callFunction(FFP_FUNC_TRANSFORM, normalMatrix, newViewNormal, newViewNormal);
}

if (mNormalMapSpace == NMS_PARALLAX)
{
// assuming: lighting stage computed this
auto vsOutViewPos = vsMain->resolveOutputParameter(Parameter::SPC_POSITION_VIEW_SPACE);
auto viewPos = psMain->resolveInputParameter(vsOutViewPos);

// TODO: user specificed scale and bias
fstage.callFunction("SGX_Generate_Parallax_Texcoord", {In(normalMapSampler), In(psInTexcoord), In(viewPos),
In(Vector2(0.04, -0.02)), Out(psInTexcoord)});

// overwrite texcoord0 unconditionally, only one texcoord set is supported with parallax mapping
// we are before FFP_PS_TEXTURING, so the new value will be used
auto texcoord0 = psMain->resolveInputParameter(Parameter::SPC_TEXTURE_COORDINATE0, GCT_FLOAT2);
fstage.assign(psInTexcoord, texcoord0);
}

return true;
}

Expand Down

0 comments on commit bf9613b

Please sign in to comment.