CatDogEngine icon indicating copy to clipboard operation
CatDogEngine copied to clipboard

[shaderc] variable in fragment shader seems optimized but actually used in bgfx shader language

Open T-rvw opened this issue 3 years ago • 1 comments
trafficstars

fs_SingleScattering_RayMarching.sc
void main()
{
	vec3 rayStart = u_cameraPos;
	vec3 rayDir = normalize(v_worldPos.xyz);

        // lightDir was optimized here
	vec3 lightDir = normalize(-u_LightDir);
	
	// We assume that camera always in atmosphere.
	vec2 atmIntersection = RaySphereIntersection(rayStart, rayDir, _PlanetCenter, _PlanetRadius + _AtmosphereHeight);
	float rayLength = atmIntersection.y;

        // It is ok to put here
	// vec3 lightDir = normalize(-u_LightDir);

	// If ray intersect whith the earth.
	vec2 earthIntersection = RaySphereIntersection(rayStart, rayDir, _PlanetCenter, _PlanetRadius);
	if (earthIntersection.x > 0.0) {
		rayLength = earthIntersection.x;
	}
	
	vec3 inscattering = IntegrateInscattering(rayStart, rayDir, rayLength, lightDir);
	
	vec3 color = PostProcssing(inscattering, 0.0);
	gl_FragColor = vec4(color.x, color.y, color.z, 1.0);
}

T-rvw avatar Nov 19 '22 11:11 T-rvw

Not sure if bgfx_FragData0 will affect the compiler to judge if uniform variable contributes to gl_Color , the hlsl is:

void main( float4 gl_FragCoord : SV_POSITION , float3 v_worldPos : TEXCOORD1 , out float4 bgfx_FragData0 : SV_TARGET0 )
{
float4 bgfx_VoidFrag = vec4_splat(0.0);
float3 rayStart = u_params[0].xyz;
float3 rayDir = normalize(v_worldPos.xyz);
float3 lightDir = normalize(-u_params[1].xyz);
float2 atmIntersection = RaySphereIntersection(rayStart, rayDir, float3(0.0, -6371, 0.0), 6371 + 80);
float rayLength = atmIntersection.y;
float2 earthIntersection = RaySphereIntersection(rayStart, rayDir, float3(0.0, -6371, 0.0), 6371);
if (earthIntersection.x > 0.0) {
rayLength = earthIntersection.x;
}
float3 inscattering = IntegrateInscattering(rayStart, rayDir, rayLength, lightDir);
float3 color = PostProcssing(inscattering, 0.0);
bgfx_FragData0 = float4(color.x, color.y, color.z, 1.0);
}

T-rvw avatar Nov 19 '22 11:11 T-rvw