Need help with creating visual effects - Resolved

The place to discuss scripting and game modifications for X4: Foundations.

Moderators: Moderators for English X Forum, Scripting / Modding Moderators

Post Reply
MrDGY
Posts: 23
Joined: Sat, 16. Nov 19, 04:53
x4

Need help with creating visual effects - Resolved

Post by MrDGY » Wed, 8. Dec 21, 16:05

Resolution: I found a better way to implement the lensing effect using the built-in distortion blendmode. The updated mod is available at https://www.nexusmods.com/x4foundations/mods/812

I try to make an alternative main battery for Asgard where I want to include a singularity/black hole as eye candy, but I'm stuck on creating a good looking black hole. I knew nothing about shader before but I have read some basics about it on the internet after starting this project. Hope someone in this forum can help me with it. Here are my two questions (sorry they are quite long):

Question 1: What is the correspondence between in game distance and the depth value accessed in the shader from the texture T_maindepth_mips?
Description: To create the black hole effects I use screen space ray tracing in the shader. If a ray propagates some long distance without hitting anything, then I want to terminate tracing and use
environment map instead. So I write something like this
Spoiler
Show

Code: Select all

float hit_z = texelFetch(T_maindepth_mips, uv, 0).x;
if (hit_z < 0)
{
	OUT_Color.a=1;
	OUT_Color.rgb = textureLod(T_ibl_envmap, out_dir, 0).rgb;
	return;
}
[the rest of the code]
The result looks like this https://ibb.co/jHCwwt9. The nearby objects are displayed properly while the background is purely black. So the if code is never executed and I guess hit_z is always positive. However when I simply change the condition to hit_z < 0.000001
Spoiler
Show

Code: Select all

float hit_z = texelFetch(T_maindepth_mips, uv, 0).x;
if (hit_z < 0.000001)
{
	OUT_Color.a=1;
	OUT_Color.rgb = textureLod(T_ibl_envmap, out_dir, 0).rgb;
	return;
}
[the rest of the code]
the result is totally different and looks like this https://ibb.co/8ccyJLr. This seems to imply that the condition hit_z<0.000001 is always true so only the environment map is used, the rest of the code never gets executed. Did I make some mistakes or misunderstand something? If not, then what is the typical value of depth (hit_z)? For reference, this is what it should look like without the black hole https://ibb.co/vBH2LNf .


Question 2: Is it possible to retrieve the glow color from gbuffer?
Description: This is the function I used in the shader to return colors
Spoiler
Show

Code: Select all

vec4 Col_out(vec2 uv)
{
	vec3 NORMAL;
	RETRIEVE_GBUFFER_UV_NORMAL0(uv, NORMAL);
	vec4 col = textureLod(T_gbuffer2, uv, 0);
	vec3 view_pos;
	RetrieveZBufferViewPos(view_pos, uv);
	float SMOOTH = 0;
	float METAL = 0;
	vec3 GLOW = vec3(0);
	col.rgb = GLOW + global_lights(NORMAL, view_pos, col.rgb, METAL, smooth2rough(SMOOTH), false);
	col.a=1;
	// col.rgb = textureLod(T_maincolor_last, uv, 0).rgb;
	return col;
}
The result is https://ibb.co/vsLKnTy . Note in this screenshot I have tweaked the size of the black hole to better illustrate the issue. The metal surfaces look good enough. But since I cannot access glow information in this function, the luminous surfaces does not glow, only its basic color is displayed. Ideally, those light blueish surfaces within the 'black hole' region should be as bright as the other luminous ones.

Thanks for your patience for reading these loooong questions. If you need I can also provide all the mod files, though they are still highly WIP.
Last edited by MrDGY on Sat, 16. Apr 22, 09:43, edited 1 time in total.

MrDGY
Posts: 23
Joined: Sat, 16. Nov 19, 04:53
x4

Re: Need help with creating visual effects

Post by MrDGY » Sat, 25. Dec 21, 05:34

===================================================================================
Updata 25 Dec, 2021
===================================================================================


Name: Singularity Burst Cannon
Description: An alternative main weapon for Asgard.


The mod in its current form is far from satisfactory, but it at least is in a working state now. I have uploaded it to Nexus at https://www.nexusmods.com/x4foundations/mods/812/ . Feel free to download and test it. I did not balance the weapon carefully, but IMO it is not more OP than the original one.

Disclaimer: I used some dirty tricks to get around certain technical difficulties (I just learnt a little bit of shaders because of this mod and I do not know much about how X4 renders graphics, so these might just be my own foolishness due to lack of knowledge) and I do not know how many internal errors they would cause to the game program. So use it at your own risk!

Regarding the two questions in the original post:

Question 1: What is the correspondence between in game distance and the depth value accessed in the shader from the texture T_maindepth_mips?
I still do not know. I simply leave the background black because at least in this mod you will seldom see the background through the black hole.

Question 2: Is it possible to retrieve the glow color from gbuffer?
I found a dirty way around this. I store the glow color in the base color buffer in a deferred draw and use the alpha channel as a flag. If alpha<0.1 then it is the glow color, while alpha>0.1 it is the normal base color. In case of the glow texture used in this mod, the alpha channel seems to be irrelevant so I can use it as a control value, but it will not work in more general cases where alpha does matter.

User avatar
Shuulo
Posts: 1629
Joined: Mon, 14. Apr 08, 17:03
x4

Re: Need help with creating visual effects

Post by Shuulo » Wed, 29. Dec 21, 23:47

This is really impressive, I doubt anyone here did the work of this extent on visual part.
Do you mind if Ill dissect your mod for interesting parts?

MrDGY
Posts: 23
Joined: Sat, 16. Nov 19, 04:53
x4

Re: Need help with creating visual effects

Post by MrDGY » Thu, 30. Dec 21, 03:43

Shuulo wrote:
Wed, 29. Dec 21, 23:47
This is really impressive, I doubt anyone here did the work of this extent on visual part.
Do you mind if Ill dissect your mod for interesting parts?
Thanks for your interest! I am glad part of this little mod can be of some help to you.

This is also for anyone who might be interested: Feel free to reuse anything that interests you in this mod.

MrDGY
Posts: 23
Joined: Sat, 16. Nov 19, 04:53
x4

Re: Need help with creating visual effects

Post by MrDGY » Sat, 16. Apr 22, 09:41

I managed to find a better way to implement the lensing effect and get rid of some of the dirty workarounds. The lensing effect now has more realistic colors and looks less out of place. I have updated the mod at https://www.nexusmods.com/x4foundations/mods/812.

Post Reply

Return to “X4: Foundations - Scripts and Modding”