sbox-scenestaging
sbox-scenestaging copied to clipboard
Transparency renders as skybox
In some cases, transparency on objects renders the skybox instead of opaque objects behind the object with transparency.
I encountered this while working on a shader; the pixel shader disables culling, enables transparency, and (depending on texture coordinates) discards some pixels. This results in gaps that show the back side of the test sphere. This renders as intended in the material editor but not in the scene or game views. Other than setting DevShader
and DebugInfo
to true
in the header, the only changes I've made to the template shader file are in the pixel shader:
PS
{
#include "common/pixel.hlsl"
RenderState( CullMode, NONE );
BoolAttribute( translucent, true );
float g_flDensity < UiType( Slider ); UiStep( 1 ); Default( 100 ); Range( 1, 1000 ); >;
//
// Main
//
float4 MainPs( PixelInput i ) : SV_Target0
{
Material m = Material::From( i );
float2 denseTexCoords = i.vTextureCoords * g_flDensity;
float2 localTexCoords = frac(denseTexCoords) * 2 - 1;
float localDistanceFromCenter = length(localTexCoords);
if (localDistanceFromCenter > 1) discard;
return ShadingModelStandard::Shade( i, m );
}
}
ShadowBrain mentioned encountering the same behavior with some transparent objects when I brought this up in Discord.