soft particle question

Posted By: 3run

soft particle question - 11/05/18 12:24

Hi!

I've got that soft particle shader from the wiki, but it turned out that it won't work without sky, or with a sky that uses custom shader. I guess it's all related to it's 'depth' thing, but not sure. Can anyone help me out here, or point me in a right direction? Help you in advance.

Some screens:

Quote:
How it looks like with default acknex sky and without fog:

Default acknex sky + fog, what are those while lines on the edges?

Custom sky shader (thanks to txesmi laugh ) and without fog:


Here are the .fx files:

softparticle.fx
Code:
float4x4 matWorld;
float4x4 matWorldViewProj;
float4 vecViewPos;
float4 vecColor;
float vecSkill1;

texture entSkin1;
texture rttDepth_bmap;
sampler SKIN = sampler_state { texture = (entSkin1);};
sampler DEPTH = sampler_state { texture = (rttDepth_bmap);};

float4 VS (	in float4 P : POSITION, in float2 T : TEXCOORD0, out float2 tex : TEXCOORD0, out float3 depth : TEXCOORD1, out float4 pos : TEXCOORD2) : POSITION {

	tex = T;
	pos = mul(P,matWorld);
	depth = mul(P,matWorldViewProj).xyw;
	return mul(P,matWorldViewProj);
	
}

float4 PS (	in float2 tex : TEXCOORD0, in float3 depth : TEXCOORD1, in float4 pos : TEXCOORD2) : COLOR {

	float4 color = tex2D(SKIN,tex) * vecColor;
	float D = tex2D(DEPTH,0.5 * depth.xy / depth.z + 0.5);
	color.a *= saturate((D - distance(pos,vecViewPos)) / vecSkill1.x);

	return color;

}

technique t{
	
	pass p{
		
		VertexShader = compile vs_2_0 VS();
		PixelShader = compile ps_2_0 PS();
		
	}

}


depth.fx
Code:
float4x4 matWorld;
float4x4 matWorldViewProj;
float4 vecViewPos;

float4 VS (	in float4 P : POSITION, out float4 pos : TEXCOORD0) : POSITION {

	pos = mul(P,matWorld);
	return mul(P,matWorldViewProj);
	
}

float4 PS (	in float4 pos : TEXCOORD0) : COLOR {

	return distance(pos,vecViewPos);
	
}

technique t{ 
	pass p{
		
		VertexShader = compile vs_2_0 VS();
		PixelShader = compile ps_2_0 PS();
		
	}
}


custom sky shader
Code:
float4 vecViewPos;
float4 vecFog;
float4 vecFogColor;
float4 vecSkill1;

float4x4 matWorld;
float4x4 matWorldViewProj;

texture mtlSkin1;
samplerCUBE mtlSkin1SamplerCUBE = sampler_state { Texture = <mtlSkin1>; Mipfilter = NONE; Minfilter = NONE; Magfilter = NONE; };

void SkyVS (
in float4 inPos: POSITION,
out float4 outPos: POSITION,
out float4 outWorld: TEXCOORD1 )
{
	outPos = mul( inPos, matWorldViewProj );
	outWorld = mul( inPos, matWorld );
}


float4 SkyPS (
in float4 inWorld: TEXCOORD1 ) : COLOR0
{
	float3 Dir = normalize ( inWorld.xyz - vecViewPos.xyz );
	float4 Color0 = texCUBE ( mtlSkin1SamplerCUBE, Dir );
	Color0.a = 1.0f;
	
	float Fog = 1.0f - pow ( Dir.y, vecSkill1.x );
	Color0.rgb = lerp ( Color0.rgb, vecFogColor.rgb, Fog );
	
	return Color0;
}



technique Sky
{
	pass p0
	{
		CullMode = None;
		
		VertexShader = compile vs_3_0 SkyVS();
		PixelShader  = compile ps_3_0 SkyPS();
	}

}


And the way it's created:
Code:
sky_ent = ent_createlayer(SPHERE_MDL,  SHOW | SKY | CUBE, 1);
vec_fill(&sky_ent->scale_x, (camera->clip_far * 0.99) / 16);
sky_ent->material = mtl_create();
sky_ent->material->skin1 = bmap_create(sky_bbox_tga);
bmap_to_cubemap(sky_ent->material->skin1);
effect_load(sky_ent->material, "mtl_sky.fx");
sky_ent->material->skill1 = floatv(1.6);


Best regards!
Posted By: jumpman

Re: soft particle question - 11/05/18 14:31

hey 3run, try this if it fixes those small lines/offsets:

Code:
float D = tex2D(DEPTH,0.5 * depth.xy / depth.z + 0.5001);



I can confirm Ive had trouble getting correct depth values when I set NOSKY on the soft particle view. Put the sky back on.

In the sky material, try seting the flags ENABLE_RENDER and ENABLE_TREE. Then in the sky material's event do this:

Code:
if(render_view==soft_particle_depth) //if this view is the soft depth view
{
mtl=mtl_depth;  //manually force the sky material to use the depth shader
}

Posted By: 3run

Re: soft particle question - 11/05/18 15:38

Hey! laugh

Added all the changes, but I can't really see any difference frown White lines are still there, and about event and flags for the sky material, this is how I've done it:

Code:
void sky_event(){
	
	//if this view is the soft depth view
	if(render_view == vDepth){
		
		// manually force the sky material to use the depth shader
		mtl = mDepth;
		
	}
	
}

// create sky entity
void pipeline_sky_create(){
	
	sky_ent = ent_createlayer(SPHERE_MDL,  SHOW | SKY | CUBE, 1);
	vec_fill(&sky_ent->scale_x, (camera->clip_far * 0.99) / 16);
	sky_ent->material = mtl_create();
	sky_ent->material->skin1 = bmap_create(sky_bbox_tga);
	sky_ent->material->flags |= ENABLE_RENDER | ENABLE_TREE;
	sky_ent->material->event = sky_event;
	bmap_to_cubemap(sky_ent->material->skin1);
	effect_load(sky_ent->material, "mtl_sky.fx");
	sky_ent->material->skill1 = floatv(1.6);
	
}

But unfortunately this also makes no changes..

Thank you for your time man!
Posted By: txesmi

Re: soft particle question - 11/05/18 17:56

Hi,
I downloaded the pack and copied the sky setup from your post just before the main loop and it works fine confused



Code:
#include <acknex.h>
#include "shared.c"

var ParticleSmoothness = 200;

BMAP* rttDepth;					

MATERIAL* mDepth= {	
	effect = "depth.fx";				
	flags = AUTORELOAD | PASS_SOLID;}		

MATERIAL* mSoftParticle = {
	effect = "SoftParticle.fx";
	flags = AUTORELOAD;}

VIEW* vDepth = {					
	material = mDepth;
	aspect = -1;		
	flags = SHOW | NOFLAG1;}

function particle();

function main() {

	video_set (sys_metrics(0),sys_metrics(1),32,1);
//	video_set (700,700,32,0);fps_max=60;
	level_load (null);

	rttDepth = bmap_createblack(screen_size.x,screen_size.y,14);
	vDepth.bmap = rttDepth;

	you = ent_create ("what_is_it.mdl",nullvector,null);

	camera.x	= -2000;
	camera.z	= 2000;
	camera.tilt	=-45;
	
	ENTITY *sky_ent = ent_createlayer(SPHERE_MDL,  SHOW | SKY | CUBE, 1);
	vec_fill(&sky_ent->scale_x, (camera->clip_far * 0.99) / 16);
	sky_ent->material = mtl_create();
	sky_ent->material->skin1 = bmap_create("skycube+6.tga");
	bmap_to_cubemap(sky_ent->material->skin1);
	effect_load(sky_ent->material, "sky.fx");
	sky_ent->material->skill1 = floatv(1.6);

	while (1) {

	vec_set (vDepth.x,camera.x);
	vec_set (vDepth.pan,camera.pan);

	if (random(10) > 9) ent_create ("particle.tga",nullvector,particle);

	ParticleSmoothness += sign(mickey.z) * 50;
	ParticleSmoothness = clamp(ParticleSmoothness,0,1000);
	mSoftParticle.skill1 = floatv(ParticleSmoothness);

	wait(1);}}

function particle() {

	my.roll		= 1;
	my.alpha	= 100;
	set(my,PASSABLE | TRANSLUCENT | FLAG1 | BRIGHT);
	my.material = mSoftParticle;

	vec_scale (my.scale_x,random(4)+1);

	my.x	=-1024;
	my.y	= random(2048)-1024;
	my.z	= random(512) - 256;

	my.red = random(255);
	my.green = random(255);
	my.blue = random(255);

	while (my.x < 1000) {

	my.alpha = minv(100,1000 - abs(my.x));
	my.x += 5;

	wait(1);}
	ent_remove (me);}

PANEL* pHelp = {

	digits (  0, 0,"WASD:",font,1,0);
	digits (100, 0,"move camera",font,1,0);
	digits (  0,15,"mouse wheel:",font,1,0);
	digits (100,15,"change smoothness (%0.0f)",font,1,ParticleSmoothness);

	flags = SHOW | OUTLINE;}



edited__________________

maybe you needed to align the sky sphere with the camera?
Posted By: 3run

Re: soft particle question - 11/05/18 18:10

Hi txesmi!

I copied code you've posted above but no changes for me :<
Here are the results:
Posted By: txesmi

Re: soft particle question - 11/05/18 18:34

Maybe your system has different default values for shading than mine? Strange.

Try to set these states into the pass definition into the shader techniques:

sky.fx
Code:
ZEnable = True;           // Check the projection depth against the Z-buffer
ZWriteEnable = False;     // Do not write into the Z-buffer
AlphaBlendEnable = False; // Draw by substitution



particle.fx
Code:
ZEnable = True;          // Check the projection depth against the Z-buffer
ZWriteEnable = False;    // Do not write into the Z-buffer
AlphaBlendEnable = True; // Mix colors by the alpha value



I believe it has to be something related... let's see
Posted By: 3run

Re: soft particle question - 11/05/18 18:46

I've just added those into .fx files, but results are the same... :<
Posted By: txesmi

Re: soft particle question - 11/05/18 18:50

mmm

try setting the sky 'ZWriteEnable' state to 'True'...
Posted By: 3run

Re: soft particle question - 11/05/18 18:52

Still no changes... here are results (it's like I'm posting the same image over and over again):
Posted By: txesmi

Re: soft particle question - 11/05/18 19:00

crazy I am out of the run. No idea what can be happening.

Did you try unrelated things, like disabling the BRIGHT flags of the particles?
Posted By: 3run

Re: soft particle question - 11/05/18 19:03

Yep, just tried.. but no changes frown
Posted By: txesmi

Re: soft particle question - 11/05/18 19:11

As test, let's see if it runs compiled
https://app.box.com/s/kj4m6rxwsqcqon1g6fxuge2ddg1x2bc5
Posted By: 3run

Re: soft particle question - 11/05/18 19:25

Well that's now really weird... Compiled one works fine, but running 'SoftParticle.c' doesn't work? How come?
Edit: compiled 'SoftParticle.c' on my side and it didn't work...
Posted By: txesmi

Re: soft particle question - 11/05/18 19:40

No idea, man. I am sorry. That is really weird indeed.
Posted By: 3run

Re: soft particle question - 11/05/18 19:42

I'll try older shade-c volumetric particles out then. Didn't want to use them, cause they require too many skins etc, but we'll see how it goes out. Thank you for your time and help guys laugh

My best regards!
Posted By: 3run

Re: soft particle question - 11/06/18 10:46

Nope.. just tried out those volumetric particles from older shade-c. It's not what I'm looking for. So I guess no soft particles for me grin At least not with acknex,
© 2019 lite-C Forums