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:
Here are the .fx files:
softparticle.fx
depth.fx
custom sky shader
And the way it's created:
Best regards!
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 ) 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
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!