Strange transparency and shadow behavior
Asked Answered
C

4

0

Hello!

I have two issues with the 3D project I cannot find a solution to. Godot version is 3.5.2-custim build on Windows 10.

1) Shadows stop rendering at some (not very far) distance. And I can see a very distinct and obvious line where there are no more shadows. Is there a control for it? Please see the first image attached.

2) I have a shader material which is essentially a scaled noise for the color and for the transparency. What I notice is it works as intended only when the background is not too far. And there seems to be some threshold distance beyond which semitransparent parts become 100% transparent. Please see the second and 3-rd images attached. If it matters, I've pasted the shader code below.

I'd appreciate any advice! Thank you!



shader_type spatial;
render_mode unshaded, cull_disabled;

uniform float size_y        = 15.0;

// Color related.
uniform float decay         = 0.05;
uniform float power         = 0.0;
uniform float exhaust_speed = 150.0;
uniform vec2  texture_scale = vec2( 2.0, 0.2 );

// Geometry related.
uniform float displacement_gain = 5.0;

uniform sampler2D noise;
uniform sampler2D displacement_x;
uniform sampler2D displacement_z;

uniform vec4 color_bright: hint_color = vec4( 0.6471, 0.8039, 1.0, 1.0 );
uniform vec4 color_dark:   hint_color = vec4( 0.3529, 0.3529, 0.3529, 1.0 );

varying float time;
varying vec3 point3d;
varying vec3 normal3d;
varying vec2 tex_coords;



vec4 compute_color( sampler2D tex, float t, vec3 r )
{
	float v = exhaust_speed / size_y;
	vec2 uv = tex_coords * texture_scale;
	uv.y -= v*t;
	uv.y = mod( uv.y, 1.0 );
	vec4 c = texture( tex, uv );
	float coef = c.x;
	vec3 color = color_bright.rgb * coef + color_dark.rgb * (1.0-coef);
	
	float sz = size_y * (1.0 + power);
	float a = 1.0 - pow( abs(r.y/sz), decay );
	
	if (a < 0.0)
		a = 0.0;
	
	return vec4(color.rgb, a);
}

vec2 compute_displacement( float t, float v, vec3 r, vec3 n )
{
	v /= size_y;
	vec2 uv = tex_coords;
	uv.y -= v*t;
	uv.y = mod( uv.y, 1.0 );

	float gain = abs(r.y/size_y) * displacement_gain;
	
	float dx = texture( displacement_x, uv ).r - 0.5;
	float dz = texture( displacement_z, uv ).r - 0.5;
	
	dx *= gain;
	dz *= gain;
	return vec2( dx, dz );
}


void vertex()
{
	time       = TIME;
	point3d    = VERTEX;
	normal3d   = NORMAL;
	tex_coords = UV;
	
	vec2 d = compute_displacement( time, exhaust_speed, point3d, normal3d );
	float x = VERTEX.x + d.x;
	float z = VERTEX.z + d.y;
	VERTEX.x = x;
	VERTEX.z = z;
}

void fragment() {
	vec4 c = compute_color( noise, time, point3d );
	ALBEDO = c.rgb;
	ALPHA  = c.a;
}
Corymb answered 24/3, 2023 at 4:59 Comment(0)
A
0

For the first issue, shadow maps have a fixed depth range. You can click on a direction light, look at the shadow options and it says max distance (in meters).

You can also adjust the mode and the splits. I'm not sure about the second issue.

Also, if you want to post code on the forum, you have to type 3 tildes on a line by themselves ~~~ directly above and directly below the pasted code. I'll fix it for you this time.

Araceli answered 24/3, 2023 at 6:54 Comment(0)
W
0

Sorry to not being actually helpful, I cannot resist seeing you're working on such ambitious project, a Kerbal Space Program clone 🙂 !
I spent so much time on this game in about two years, from 0.20 maybe to 0.23.5 mostly, I've tried then 1.x releases without much commitment.

I've made many new parts and play with others mods, it was/is a great game to experiment and do crazy things, but exploration was not so great with all those empty area everywhere.
Hope you'll think about make the universe more alive with tons of airport/airfield at least AND support modding.

I remember a github project on generating planetary surface at the same scale as KSP but don't get the exact name, if I found it back on my harddrives, I could give you the ref or the source code if you wish.

I'll looking forward to your progress.

Wheatley answered 24/3, 2023 at 18:52 Comment(0)
C
0

Wheatley

I'm glad to see your excitement! Yes, cannot disagree that KSP is not quite a game about exploration rather than about space flight dynamics 🙂 The prototype is at github, in theory anybody can play around with it...

Just in case, if you still have those part models laying around with no purpose, could you consider sharing? I could put those to a good use...

Yes, it has modding support, it parses the whole folder looking for part designs right after executable has been started. It probably is not very polished and as convenient to make new parts as I think yet though...

Yes, please, share the full scale planet github project if you find it! I'd appreciate it very much!

Corymb answered 27/3, 2023 at 16:13 Comment(0)
C
0

Araceli
Thank you so much! Shadow distance works perfectly!

As for the transparency issue, just in case if anybody runs into a similar trouble, I believe I've found the problem. I've been rendering close and far objects in separate scenes and superimposing near scene on top of the far scene using viewport with transparent background. In order to fix the transparency issue I swapped it. Near objects are rendered normally and far objects are rendered onto ViewportTexture applied to a plane located at Camera.far. That swap fixes the transparent materials issue.

Corymb answered 27/3, 2023 at 16:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.