Jump to content

Decals disappearing from view.


Recommended Posts

Hello everyone.

I'm working on a new demo for Twisted Minds and wanted to use decals for drawing a path on the floor. (See the screenshot below.)

vlcsnap-2021-05-15-15h33m58s739.thumb.png.c553aef7516b532a0d7a19080c39eb39.png

However, whenever the decal entity left the screen, the whole decal disappears. Here is a little video showing this problem.

As you can see on the video, I set up the view range to infinite just to test and occlusion culling is disabled.

I don't know what I'm missing, if I'm missing something, or if I'm not using decals correctly.
Could anyone lighten up my lantern, please?

Kindly, 
Ttiki.

Just making games for fun. Currently working on T3-L4

Linka logo

Link to comment
Share on other sites

It looks like a culling issue regardless of your settings. Try making the decal box higher.

 

Also, what vender is your GPU and Graphics Card version? Does this issue happen with the MyGame example?

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

Yes, sorry, I forgot to add this information. I'm running with an AMD Ryzen 7 1700 with an NVIDIA GeForce GTX 660.


I also thought it was a culling issue, but I wanted to be sure and see if someone did encounter this bug. I've tried scaling up the height and it kind of worked. However, to fix this issue I would need to make my decals way too high. Of course, I could always subdivide the big lines which cause me problems into smaller bits.


I'm sorry if this sounds stupid, but I don't know the last question ^^ (IDK what's the MyGame example...)

 

And congrats for your 1600th post! 

Just making games for fun. Currently working on T3-L4

Linka logo

Link to comment
Share on other sites

5 minutes ago, Ttiki said:

I'm sorry if this sounds stupid, but I don't know the last question ^^ (IDK what's the MyGame example...)

Make a new game with the FPS template and play the "AI and Events" map and pay attention to the decals. Also make sure your blend modes are the same as the samples.

  • Thanks 1

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

1 hour ago, Slastraf said:

You might use 
https://www.leadwerks.com/learn?page=API-Reference_Object_Entity_SetOcclusionCullingMode
SetOcclusionCullingMode to true or false and look at the results.
For this you need to add a script to each decal, or make a "decal handler" that sets this for every decal entity.

I've tried this, it didn't work. Nothing seems to have changed. They still disappear when the player look away.

1 hour ago, reepblue said:

Make a new game with the FPS template and play the "AI and Events" map and pay attention to the decals. Also make sure your blend modes are the same as the samples.

Thank you, I completely forgot about this MyGame example, even though I've played with it a lot. Now, I made some testing, and they work correctly, even stretch out a lot like mine. And I couldn't reproduce the bug. No matter how much I would stretch a decal, it would not disappear. 

I made sure my materials were set up correctly, even copying the one from the example. But no matter what, mine still disappeared. I've used a technic from the demo and put all origins in the floor to extend the height as much as I could. 

 

I've compiled a quick project with everything needed. If you want to try by yourself with my assets. I will let this problem aside at the moment and finish my demo. 

DecalCullingTest.zip

Thank you very much for your help!

Just making games for fun. Currently working on T3-L4

Linka logo

Link to comment
Share on other sites

It even happens in the editor itself any time the decal has a different X and Z scale. It appears the smaller of the two is used.

I am looking at the source code in the engine right now and I do not see anything that would cause this. 

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Okay, I did find something.

The global AABB calculation has a mistake and assumes the decal has rotation 0,0,0. You can test this yourself by rotating a decal with this orientation and you will see the problem goes away.

  • Like 2

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

  • 3 months later...

I ran into this problem myself. I'm trying to prevent making another texture to accommodate this so I decided to try to make a custom shader to handle this. I have rotation code that works well for my effects but it's all distorted and weird if the Z value is greater than X's.

I'm hoping to get assistance with this. I was using current time to test the rotation.

#version 400
#define BFN_ENABLED 1

//Uniforms	
uniform vec2 buffersize;
uniform vec4 materialcolorspecular;
uniform samplerCube texture15;
uniform sampler2D texture0;
uniform sampler2D texture4;// normal map

//MSAA textures
uniform sampler2DMS texture6;// depth
uniform sampler2DMS texture7;// normal

uniform bool isbackbuffer;
uniform mat4 projectioncameramatrix;
uniform vec3 cameraposition;
uniform vec4 materialcolordiffuse;
uniform int RenderMode;

//Inputs
in float ex_selectionstate;
in vec4 vColor;
in mat4 inversemodelmatrix;
in vec3 modelposition;
in mat3 nmat;
in vec2 vTexCoords0;

//Outputs
out vec4 fragData0;
out vec4 fragData1;
out vec4 fragData2;
out vec4 fragData3;

uniform float currenttime;

float depthToPosition(in float depth, in vec2 depthrange)
{
	return depthrange.x / (depthrange.y - depth * (depthrange.y - depthrange.x)) * depthrange.y;
}

vec4 ScreenPositionToWorldPosition(in vec2 texCoord)
{
        float x = (texCoord.s / buffersize.x - 0.5) * 2.0;
        float y = (texCoord.t / buffersize.y - 0.5) * 2.0;
		float z;
		z = texelFetch(texture6, ivec2(texCoord),gl_SampleID).r;
		z = z / 0.5 - 1.0;
        vec4 posProj = vec4(x,y,z,1.0);
        vec4 posView = inverse(projectioncameramatrix) * posProj;
        posView /= posView.w;
        return posView;
}

int getMajorAxis(in vec3 v)
{
	vec3 b = abs(v);
	if (b.x>b.y)
	{
		if (b.x>b.z)
		{
			return 0;
		}
		else
		{
			return 2;
		}
	}
	else
	{
		if (b.y>b.z)
		{
			return 1;
		}
		else
		{
			return 2;
		}
	}
}

void main(void)
{
	vec3 normal;
	vec4 normaldata;
	float specular;	
	float depth;
	vec3 screencoord;
	vec4 worldcoord;
	vec4 worldpos;
	vec2 tc;
	vec4 emission = vec4(0,0,0,0);
	vec3 ex_normal;
	vec3 ex_binormal;
	vec3 ex_tangent;
	vec3 blendednormal;
	vec3 screennormal;
	vec3 worldnormal;
	float blendedspecular;
	ivec2 icoord = ivec2(gl_FragCoord.xy);
	if (isbackbuffer) icoord.y = int(buffersize.y) - icoord.y;
	
	depth = texelFetch(texture6, icoord,gl_SampleID).r;
	worldcoord = vec4(gl_FragCoord.x/buffersize.x,-gl_FragCoord.y/buffersize.y,depth,gl_FragCoord.w);
	worldcoord = inverse(projectioncameramatrix)*worldcoord;
	screencoord=worldcoord.xyz;
	worldpos = ScreenPositionToWorldPosition(gl_FragCoord.xy);
	screencoord = (inversemodelmatrix * worldpos).xyz;
	
	if (screencoord.x<-0.5) discard;
	if (screencoord.x>0.5) discard;
	if (screencoord.y<-0.5) discard;
	if (screencoord.y>0.5) discard;
	if (screencoord.z<-0.5) discard;
	if (screencoord.z>0.5) discard;
	
	normaldata = texelFetch(texture7, icoord,gl_SampleID);

	// Get The Entity's Scale
	vec2 entity_scale;
	entity_scale.x = length(nmat[0].xyz);
	entity_scale.y = length(nmat[2].xyz);

	// Next, Rotate it if the Z value is greater than X
	// If Z is greater than X, it's going vertical!
	if (entity_scale.y > entity_scale.x)
	{
		//find center
		vec2 uv = (vTexCoords0-0.5);

		//rotate Front
		float sinx = sin ( -0.002 * currenttime );
		float cosx = cos ( -0.002 * currenttime );
		float siny = sin ( -0.002 * currenttime );
		mat2 rotmatrix = mat2( cosx, -sinx, siny, cosx);

		//rotuv = rotmatrix*uv+0.5;
		tc +=rotmatrix*uv+0.5; 
	}

	int materialflags = int(normaldata.a * 255.0 + 0.5);
 
	//Filter
	bool draw = false;
	if ((1 & RenderMode)!=0)//Brushes
	{
		if ((4 & materialflags)!=0) draw=true;
	}
	if ((2 & RenderMode)!=0)//Models
	{
		if ((8 & materialflags)!=0) draw=true;
	}
	if ((4 & RenderMode)!=0)//Terrain
	{
		if ((16 & materialflags)!=0) draw=true;
	}	
	if (!draw) discard;
	
	screennormal = normalize(normaldata.xyz*2.0-1.0);
	worldnormal = inverse(nmat) * screennormal;
	
	// Only show up on floors/ceilings.
	if (getMajorAxis(worldnormal) != 1) discard;
	tc+=vec2(sign(worldnormal.y)*1.0,-1.0)*screencoord.xz-0.5;
	
	// Correct the scale.
	vec2 scale;
	scale.x = entity_scale.x * 0.78125;
	scale.y = entity_scale.y * (0.78125 * 4);
	tc.x = tc.x * scale.x;
	tc.y = tc.y * scale.y;

	//tc = mod(tc,1.0);

	fragData0 = texture(texture0,tc) * materialcolordiffuse;
	if (ex_selectionstate>0.0)
	{
		fragData0.xyz = (fragData0.xyz + vec3(1,0,0)) * 0.5;
	}

	emission = texture(texture4,tc) * vColor;
	fragData1 = normaldata;
	fragData2 = vec4(emission.rgb,fragData0.a);
}

 

  • Like 1

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

This is what I came up with in the meantime. I use 4 textures (2 diffuse, 2 emission) and the shader swaps what to draw based on the scale of the decal. I'd like to lower the texture budget, but if I can't get something better, this should be fine.

#version 400
#define BFN_ENABLED 1

//Uniforms	
uniform vec2 buffersize;
uniform vec4 materialcolorspecular;
uniform samplerCube texture15;

// Horizontal Textures:
uniform sampler2D texture0;
uniform sampler2D texture4;

// Vertical Textures:
uniform sampler2D texture1;
uniform sampler2D texture2;// normal map

//MSAA textures
uniform sampler2DMS texture6;// depth
uniform sampler2DMS texture7;// normal

uniform bool isbackbuffer;
uniform mat4 projectioncameramatrix;
uniform vec3 cameraposition;
uniform vec4 materialcolordiffuse;
uniform int RenderMode;

//Inputs
in float ex_selectionstate;
in vec4 vColor;
in mat4 inversemodelmatrix;
in vec3 modelposition;
in mat3 nmat;
in vec2 vTexCoords0;

//Outputs
out vec4 fragData0;
out vec4 fragData1;
out vec4 fragData2;
out vec4 fragData3;

uniform float currenttime;

float depthToPosition(in float depth, in vec2 depthrange)
{
	return depthrange.x / (depthrange.y - depth * (depthrange.y - depthrange.x)) * depthrange.y;
}

vec4 ScreenPositionToWorldPosition(in vec2 texCoord)
{
        float x = (texCoord.s / buffersize.x - 0.5) * 2.0;
        float y = (texCoord.t / buffersize.y - 0.5) * 2.0;
		float z;
		z = texelFetch(texture6, ivec2(texCoord),gl_SampleID).r;
		z = z / 0.5 - 1.0;
        vec4 posProj = vec4(x,y,z,1.0);
        vec4 posView = inverse(projectioncameramatrix) * posProj;
        posView /= posView.w;
        return posView;
}

int getMajorAxis(in vec3 v)
{
	vec3 b = abs(v);
	if (b.x>b.y)
	{
		if (b.x>b.z)
		{
			return 0;
		}
		else
		{
			return 2;
		}
	}
	else
	{
		if (b.y>b.z)
		{
			return 1;
		}
		else
		{
			return 2;
		}
	}
}

void main(void)
{
	vec3 normal;
	vec4 normaldata;
	float specular;	
	float depth;
	vec3 screencoord;
	vec4 worldcoord;
	vec4 worldpos;
	vec2 tc;
	vec4 outcolor = vec4(0,0,0,0);
	vec4 emission = vec4(0,0,0,0);
	vec3 ex_normal;
	vec3 ex_binormal;
	vec3 ex_tangent;
	vec3 blendednormal;
	vec3 screennormal;
	vec3 worldnormal;
	float blendedspecular;
	ivec2 icoord = ivec2(gl_FragCoord.xy);
	if (isbackbuffer) icoord.y = int(buffersize.y) - icoord.y;
	
	depth = texelFetch(texture6, icoord,gl_SampleID).r;
	worldcoord = vec4(gl_FragCoord.x/buffersize.x,-gl_FragCoord.y/buffersize.y,depth,gl_FragCoord.w);
	worldcoord = inverse(projectioncameramatrix)*worldcoord;
	screencoord=worldcoord.xyz;
	worldpos = ScreenPositionToWorldPosition(gl_FragCoord.xy);
	screencoord = (inversemodelmatrix * worldpos).xyz;
	
	if (screencoord.x<-0.5) discard;
	if (screencoord.x>0.5) discard;
	if (screencoord.y<-0.5) discard;
	if (screencoord.y>0.5) discard;
	if (screencoord.z<-0.5) discard;
	if (screencoord.z>0.5) discard;
	
	normaldata = texelFetch(texture7, icoord,gl_SampleID);

	// Get The Entity's Scale
	vec2 entity_scale;
	entity_scale.x = length(nmat[0].xyz);
	entity_scale.y = length(nmat[2].xyz);

	int materialflags = int(normaldata.a * 255.0 + 0.5);
 
	//Filter
	bool draw = false;
	if ((1 & RenderMode)!=0)//Brushes
	{
		if ((4 & materialflags)!=0) draw=true;
	}
	if ((2 & RenderMode)!=0)//Models
	{
		if ((8 & materialflags)!=0) draw=true;
	}
	if ((4 & RenderMode)!=0)//Terrain
	{
		if ((16 & materialflags)!=0) draw=true;
	}	
	if (!draw) discard;
	
	
	screennormal = normalize(normaldata.xyz*2.0-1.0);
	worldnormal = inverse(nmat) * screennormal;
	
	// Only show up on floors/ceilings.
	if (getMajorAxis(worldnormal) != 1) discard;
	tc=vec2(sign(worldnormal.y)*1.0,-1.0)*screencoord.xz-0.5;
	
	vec2 scale = entity_scale;
	bool vertical = false;
	if (scale.y > scale.x)
	{
		// MArk as vertical:
		vertical = true;

		// Correct the scale.
		scale.x = entity_scale.x * (0.78125 * 4);
		scale.y = entity_scale.y * 0.78125;	
	}
	else
	{

		// Correct the scale.
		scale.x = entity_scale.x * 0.78125;
		scale.y = entity_scale.y * (0.78125 * 4);
	}

	tc.x = tc.x * scale.x;
	tc.y = tc.y * scale.y;

	tc = mod(tc,1.0);

	if (vertical)
	{
		outcolor = texture(texture1,tc);
		emission = texture(texture2,tc);
	}
	else
	{
		outcolor = texture(texture0,tc);
		emission = texture(texture4,tc);
	}

	fragData0 = outcolor * materialcolordiffuse;
	if (ex_selectionstate>0.0)
	{
		fragData0.xyz = (fragData0.xyz + vec3(1,0,0)) * 0.5;
	}

	emission *= vColor;
	fragData1 = normaldata;
	fragData2 = vec4(emission.rgb,fragData0.a);
}

Result:

image.thumb.png.4b4a64e6a0ab13c9149587d12f7266ca.png

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

Does this fix the other issues with the beta? If you have time to push out a new Leadwerks build, I can start making a list of things I came across with Cyclone.

I stopped reporting these issues because it seemed you were really involved with the new engine for the last few years.

Tonight I'll give this a go and see what else I can find.

  • Like 1

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...