[Solved]Render Target Cube Texture Cube How to questions.

Thats from inside the the light cube what it sees as shadows red green blue represent different depths.

The first issue with lines showing up here and there i just figured out.
The RenderTargetCube texture sampler needs to have its Address u v set to clamp.

The other issue with those circles and lines in purple appearing on the spheres and cubes i havent. Looking at it from the lights depth view above it appears to be localized and have some pattern. They are extremely ugly shadow depth errors.

This is what its doing visibly.

But im thinking its another sampler state issue, or thier just simply isnt enough precision.

I stuck the encoding back in to get the extra 8 bits and also because i was going to code a reflection cube, but i got side tracked on trying to figure out why these shadows look so bad.
Ive got it bumped up to 32 bits encoded at this point doesnā€™t really make a difference.

The only artifacts Iā€™m seeing are in the transition areas btw. light and shadow. Iā€™m not seeing anything from those purple circle artifacts.
The light-shadow artifacts get better if you increase the RenderTargetCube resolution, but Iā€™m sure thereā€™s something else you can do to improve this.

SurfaceFormat.Single is already 32 bits per pixel, if you go to Vector4 you get 128 bits per pixel, which is complete overkill for depth. For reflections you should use 8 bit per channel, or 16 bit if you do HDR rendering, otherwise those cubemaps get so large.

if you go to Vector4 you get 128 bits per pixel

Oh i didnā€™t realize Vector4 in that context was actually 32 bits per element.
Well i probably should of picked color i was only encoding 8 bits per element anyways.

Anyways i cant get a decimal resolution bias less then about here
if (shadowDepth + 0.05 < pixelToLightDist)
For 32 bits of floating point accuracy that doesnā€™t seem right.

Well this really sucks ^^^^.

The light-shadow artifacts get better if you increase the
RenderTargetCube resolution, but Iā€™m sure thereā€™s something else you can
do to improve this.

Ya uping the res doesnā€™t do to much im not sure what those circles and lines are going across but they are there. If i lower the bias a bit they become extremely visible. Which is the resolution problem, the lower the bias the better the shadows, but those circles and lines are were z fighting is about to occur, What is causing them i have no clue they shouldnā€™t be there at all.
The fact they are there is just a additional limitation on lowering the depth bias. Itā€™s just irking me that i donā€™t know what is going on with that.

What else i can do im not sure, should i look into using a alternate techqnique to blend the shadows or do more sampling around the first sample or something ? Those edges look horrible.

Now that i think about it maybe its wiser to move the shadows onto the vertice shader ?
Possibly even shadow against the normals ?

You mean you RGB encoding? I donā€™t think you need that anyway, but if you use it, why not encode to 32-bit?

My guess is that a lot of the artifacts come from the cubemap not beeing filtered. Keep in mind that automatic texture filtering for floating point textures only works in newer shader models. In older shader models you have to do it manually. I donā€™t know off top of my head what the minimum shader model is for automatic filtering.

Ah i dunno what i mean.
The more i think about it the more it doesnā€™t make sense.

.06 isnā€™t even 8 bits !

I cant get accurracy to .01 with a 24 bit float ? Worse still a 32 bit float.
Even encoding it im not getting any different accuracy which makes no sense.

Maybe i should just try squaring these values and comparing them instead of finding the lengths.

Itā€™s like any small fractional value has super bad precision period.

Well i couldnā€™t get more then .06 precision safely no matter what i did so i gave up on it.

Anyways i fliped the culling on the rendered depth cubes.
backed up the shadow.
cut the lighting off the back of the objects

looks decent.

I just have one little problem other then the spritebatch issue.

Im getting specular highlight bleeding thru.

Heres my shader atm i didnā€™t use the half vector last time but im trying to use it this time the only problem is i donā€™t know how to stop the bleed thru when using it.
I tried to dot the surface normal against the pixel to camera why its not working i dunno i guess cause the half vector flips.

float4 PsLightShadowNormal(VsOutLightShadowNormal input) : Color
{
    float3 pixelToCamera = normalize(CameraPosition - input.Position3D);
    float3 pixelToLight = WorldLightPosition - input.Position3D;
    float pixelToLightDist = length(pixelToLight);
    pixelToLight = pixelToLight / pixelToLightDist; // cheapen a normalize.
    float3 cubelookup = -pixelToLight;
    //float LightDistanceIntensity = 1.0f - saturate(pixelToLightDist / (IlluminationRange + 0.001f));
    float LightDistanceIntensity = 1.0f;
    //float shadowDepth = DecodeFloatRGBA(texCUBE(TextureDepthSampler, float4(cubelookup, 0)).xyzw);
    float shadowDepth = texCUBE(TextureDepthSampler, float4(cubelookup, 0)).x;
    float4 TexelColor = tex2D(TextureSamplerA, input.TexureCoordinateA);
    // shadow
    float LightOrShadow = 1.0f;
    if (shadowDepth + .2f < pixelToLightDist)
        LightOrShadow = 0.0f;
    // lighting
    float3 L = pixelToLight;
    float3 N = input.Normal;
    float3 H = normalize(pixelToCamera + L);
    float DiffuseIntensity = max(dot(N, L) *.9 +.1f, 0.0f);

  // Arrrrrrgggggggggggggggg......

    float NS = 1.0f;
    //float NS = max(dot(N, L), 0.0f);
    //NS = sign(DiffuseIntensity); // this straight cuts it off
    //float NS =DiffuseIntensity; // this dims it and destroys the specular too much
    //float specularRange = max( (dot(N, L) - 0.33f) * 1.5f , 0.0f); //sign(DiffuseIntensity);  //  sign(dot(N, -CameraForward));
    //float NS = max((dot(N, L) + 0.33f) * .66f, 0.0f);

    float SpecularIntensity = saturate(dot(H, N) * NS);
    SpecularIntensity = pow(SpecularIntensity, SpecularSharpnes);
    float3 Ambient = AmbientStrength * TexelColor.rgb;
    float3 Diffuse = LightDistanceIntensity * DiffuseIntensity  * DiffuseStrength * LightOrShadow * (TexelColor.rgb * LightColor.rgb);
    float3 Specular = LightDistanceIntensity * SpecularIntensity * SpecularStrength * LightOrShadow *(TexelColor.rgb * LightColor.rgb);
    float3 FinalColor = Ambient + Diffuse + Specular;
    return float4(FinalColor, 1.0f);
}

That doesnā€™t look like a proper specular highlight though. Looks like the light source is exactly behind the bleeding point, or is this just accidental in this image?

Is (pixelToCamera + L) maybe just too close to zero for the normalize to work well?

Looks like the light source is exactly behind the bleeding point, or is this just accidental in this image?

Ya i put it there to show the artifact.
Itā€™s even more extreme if i mess with it a little set the pow(ā€¦) to one. I can see a hour glass spray sort of image if i exasperate it to be as bad as possible.
Whats happening is the H value gets really warped when the average is close to zero. I canā€™t cut it off because that looks terrible and sliding it back requires blending which destroys the specular and twists it into diffuse.

Is (pixelToCamera + L) maybe just too close to zero for the normalize to work well?

Thats possible too, im thinking its when the light the pixel and the camera position are nearly aligned that roasts the H value. but im not sure there is a real fix either way.

Reading up on this i found that the way this blinn phong thing works it happens.
Its a real problem with it to were the solution is to set a very high specular power value.
Thats actually terrible im suprised its so popular, that basically defines broken.

Itā€™s at pow 30 here in that image and the recommendation is to start at 50.

Im just about to reimplement my old one.

Edit here is my old one ts kinda hard to adjust it right.
I like the other one but i dont like that bleed thru.

Maybe later ill try to blend it in with mine and see if i can correct it and get that nice long edge glow. Mine can do it but its more of globular glow on the edge. i have no idea what they would call this. Its basically just a specular reflection using a actual reflection vector.

float4 PsLightShadowNormal(VsOutLightShadowNormal input) : Color
{
    float3 pixelToCamera = normalize(CameraPosition - input.Position3D);
    float3 pixelToLight = WorldLightPosition - input.Position3D;
    float pixelToLightDist = length(pixelToLight);
    pixelToLight = pixelToLight / pixelToLightDist; // cheapen a normalize.
    float LightDistanceIntensity = 1.0f - saturate(pixelToLightDist / (IlluminationRange + 0.001f));
    float shadowDepth = texCUBE(TextureDepthSampler, float4(-pixelToLight, 0)).x;
    float4 TexelColor = tex2D(TextureSamplerA, input.TexureCoordinateA) * LightColor;
    // shadow   dunno if this is better then the if or not ?
    LightDistanceIntensity = saturate( sign((shadowDepth + .2f) - pixelToLightDist) ); 
    // lighting
    float3 L = -pixelToLight;
    float3 N = input.Normal;    
    float diffuse = saturate(dot(N, -L)); // the light to normal theta, this is the diffuse.
    float3 R = reflect(L, N); // incidence vector of the light reflected via the surface normal.
    float Rtheta = saturate(dot(-pixelToCamera, -R)); // theta for the reflected light against the pixel to camera normal
    float Atheta = (dot(L, N) + 1.2f) *0.45f; // this is adjustable... given a range of -1 to 1 plus the first term * the second this should return at maximum 1.0.
    float specular =  pow(Rtheta, SpecularSharpness) * Atheta; // sharpen the specular range using it like this requires the strength to be doubled
    //
    float3 additiveAmbient = AmbientStrength;
    float3 additiveDiffuse =  diffuse * DiffuseStrength * LightDistanceIntensity;
    float3 additiveSpecular = specular * SpecularStrength  * LightDistanceIntensity;
    float3 FinalColor = TexelColor * (additiveAmbient + additiveDiffuse + additiveSpecular);
    return float4(FinalColor, 1.0f);
}