2 registered members (dr_panther, 7th_zorro),
1,203
guests, and 2
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
soft particle question
#474776
11/05/18 12:24
11/05/18 12:24
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
OP
Senior Expert
|
OP
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
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: 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 ) and without fog: Here are the .fx files: softparticle.fx
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
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
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:
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!
|
|
|
Re: soft particle question
[Re: 3run]
#474778
11/05/18 14:31
11/05/18 14:31
|
Joined: Apr 2002
Posts: 1,246 ny
jumpman
Serious User
|
Serious User
Joined: Apr 2002
Posts: 1,246
ny
|
hey 3run, try this if it fixes those small lines/offsets:
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:
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
}
|
|
|
Re: soft particle question
[Re: jumpman]
#474779
11/05/18 15:38
11/05/18 15:38
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
OP
Senior Expert
|
OP
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
Hey! Added all the changes, but I can't really see any difference White lines are still there, and about event and flags for the sky material, this is how I've done it:
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!
|
|
|
Re: soft particle question
[Re: 3run]
#474782
11/05/18 17:56
11/05/18 17:56
|
Joined: Jun 2007
Posts: 1,337 Hiporope and its pain
txesmi
Serious User
|
Serious User
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
|
Hi, I downloaded the pack and copied the sky setup from your post just before the main loop and it works fine
#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?
Last edited by txesmi; 11/05/18 17:57.
|
|
|
Re: soft particle question
[Re: txesmi]
#474783
11/05/18 18:10
11/05/18 18:10
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
OP
Senior Expert
|
OP
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
Hi txesmi! I copied code you've posted above but no changes for me :< Here are the results:
|
|
|
Re: soft particle question
[Re: 3run]
#474784
11/05/18 18:34
11/05/18 18:34
|
Joined: Jun 2007
Posts: 1,337 Hiporope and its pain
txesmi
Serious User
|
Serious User
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
|
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
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
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
|
|
|
|