https://forum.game-guru.com/thread/217636#msg2574358
I like a challenge, GPU would assume your having a really zoomed out image and select wrong mip. Think about it this way first pixel is at UV 0.111 next pixel is at 0.3333 (just a sample ) the GPU will see this (REALLY ZOOMED) and use the avg. to select the mip. so it get totally wrong at the edges.
Simple fix use the org. uv. Simple solutions are always the best
void Atlas16DiffuseLookup( in float4 VegShadowColor, in float2 TexCoord, in out float4 diffusemap )
{
// vars
int texcol = 0;
int texrow = 0;
float2 texatlasuv = float2(0,0);
float texselectorV = min(VegShadowColor.b,0.9375f);
// center sample
float texcenterfactor = Atlas16GetUV(texselectorV,texselectorV,TexCoord,texatlasuv,texcol,texrow);
float2 finaluv = float2(texatlasuv+float2(texcol*0.25f,texrow*0.25f));
//float2 texDdx = ddx(finaluv);
//float2 texDdy = ddy(finaluv);
float2 texDdx = ddx(TexCoord*0.125f);
float2 texDdy = ddy(TexCoord*0.125f);
diffusemap += tex2Dgrad(DiffuseSampler,finaluv,texDdx,texDdy) * texcenterfactor;
// higher sample
float texhigherfactor = Atlas16GetUV((texselectorV+0.0625f),texselectorV,TexCoord,texatlasuv,texcol,texrow);
finaluv = float2(texatlasuv+float2(texcol*0.25f,texrow*0.25f));
// texDdx = ddx(finaluv);
// texDdy = ddy(finaluv);
texDdx = ddx(TexCoord*0.125f);
texDdy = ddy(TexCoord*0.125f);
diffusemap += tex2Dgrad(DiffuseSampler,finaluv,texDdx,texDdy) * texhigherfactor;
// lower sample
if ( texselectorV >= 0.0625f )
{
float texlowerfactor = Atlas16GetUV((texselectorV-0.0625f),texselectorV,TexCoord,texatlasuv,texcol,texrow);
finaluv = float2(texatlasuv+float2(texcol*0.25f,texrow*0.25f));
//texDdx = ddx(finaluv);
//texDdy = ddy(finaluv);
texDdx = ddx(TexCoord*0.125f);
texDdy = ddy(TexCoord*0.125f);
diffusemap += tex2Dgrad(DiffuseSampler,finaluv,texDdx,texDdy) * texlowerfactor;
}
}
void Atlas16DiffuseNormalLookup( in float4 VegShadowColor, in float2 TexCoord, in out float4 diffusemap, in out float3 normalmap )
{
// vars
int texcol = 0;
int texrow = 0;
float2 texatlasuv = float2(0,0);
float texselectorV = min(VegShadowColor.b,0.9375f);
// center sample
float texcenterfactor = Atlas16GetUV(texselectorV,texselectorV,TexCoord,texatlasuv,texcol,texrow);
float2 finaluv = float2(texatlasuv+float2(texcol*0.25f,texrow*0.25f));
// float2 texDdx = ddx(finaluv);
// float2 texDdy = ddy(finaluv);
float2 texDdx = ddx(TexCoord*0.125f);
float2 texDdy = ddy(TexCoord*0.125f);
diffusemap += tex2Dgrad(DiffuseSampler,finaluv,texDdx,texDdy) * texcenterfactor;
normalmap += tex2Dgrad(NormalMap1Sampler,finaluv,texDdx,texDdy).xyz * texcenterfactor;
// higher sample
float texhigherfactor = Atlas16GetUV((texselectorV+0.0625f),texselectorV,TexCoord,texatlasuv,texcol,texrow);
finaluv = float2(texatlasuv+float2(texcol*0.25f,texrow*0.25f));
// texDdx = ddx(finaluv);
// texDdy = ddy(finaluv);
texDdx = ddx(TexCoord*0.125f);
texDdy = ddy(TexCoord*0.125f);
diffusemap += tex2Dgrad(DiffuseSampler,finaluv,texDdx,texDdy) * texhigherfactor;
normalmap += tex2Dgrad(NormalMap1Sampler,finaluv,texDdx,texDdy).xyz * texhigherfactor;
// lower sample
if ( texselectorV >= 0.0625f )
{
float texlowerfactor = Atlas16GetUV((texselectorV-0.0625f),texselectorV,TexCoord,texatlasuv,texcol,texrow);
finaluv = float2(texatlasuv+float2(texcol*0.25f,texrow*0.25f));
// texDdx = ddx(finaluv);
// texDdy = ddy(finaluv);
texDdx = ddx(TexCoord*0.125f);
texDdy = ddy(TexCoord*0.125f);
diffusemap += tex2Dgrad(DiffuseSampler,finaluv,texDdx,texDdy) * texlowerfactor;
normalmap += tex2Dgrad(NormalMap1Sampler,finaluv,texDdx,texDdy).xyz * texlowerfactor;
}
}
best regards Preben Eriksen,