- [Preview Panel] Fix black screen when previewing empty sdf shape.

This commit is contained in:
Tanasart 2024-07-05 08:20:38 +07:00
parent 63efb6be3c
commit 441fe2ab8c
2 changed files with 6 additions and 4 deletions

View File

@ -1193,9 +1193,10 @@ function Panel_Preview() : PanelContent() constructor {
shader_set_f("camRotation", [ d3_view_camera.focus_angle_y, -d3_view_camera.focus_angle_x, 0 ]);
shader_set_f("camScale", zm);
shader_set_f("camRatio", w / h);
shader_set_i("shapeAmount", 0);
_env.apply();
_obj.apply();
if(_obj) _obj.apply();
shader_set_i("drawBg", 0);
shader_set_f("depthInt", 0);

View File

@ -717,6 +717,7 @@ vec3 normal(vec3 p) {
}
float march(vec3 camera, vec3 direction, out vec3 blendIndx) {
if(shapeAmount == 0) return viewRange.y;
float depth = viewRange.x;
for (int i = 0; i < MAX_MARCHING_STEPS; i++) {
@ -806,13 +807,13 @@ vec4 scene() {
vec3 norm = normal(coll);
vec4 grid = vec4(0.);
if(drawGrid == 1 && sign(eye.y) != sign(coll.y)) {
if(drawGrid == 1 && (shapeAmount == 0 || sign(eye.y) != sign(coll.y))) {
vec3 gp = eye + dir * depth * (abs(eye.y) / (abs(coll.y) + abs(eye.y)));
grid = viewGrid( gp.xz, gridStep );
grid.a *= clamp(1. - length(gp.xz) * gridScale, 0., 1.) * 0.75;
}
if(depth > viewRange.y - EPSILON) // Not hitting anything.
if(shapeAmount == 0 || depth > viewRange.y - EPSILON) // Not hitting anything.
return drawGrid == 1? grid : vec4(0.);
///////////////////////////////////////////////////////////
@ -885,7 +886,7 @@ void main() {
}
vec4 result = drawBg == 1? bg : vec4(0.);
result = blend(result, scene());
result = blend(result, scene());
//////////////////////////////////////////////////