Hey!
I saw you e-mail (by accident, I never log into that account usually in weeks).
You will have to create a ZPrePass before you can even begin to be able to apply it on a particle.
The material of the particle is very simple, just two textures (one is the particle texture and the second you have to set manually in code to the ZPrePass texture):
Code: Select all
material FireParticle
{
technique
{
pass
{
lighting off
depth_write off
scene_blend add
vertex_program_ref SoftParticles_VS
{
}
fragment_program_ref SoftParticles_PS
{
}
texture_unit
{
texture fireParticle.png
tex_address_mode clamp
}
texture_unit ZPrePass
{
texture white.tga // This gets filled in later
tex_address_mode clamp
filtering none
}
}
}
}
And here is the material for the already posted soft particles shader:
Code: Select all
vertex_program SoftParticles_VS hlsl
{
source SoftParticles.hlsl
entry_point main_vs
target vs_3_0
default_params
{
param_named_auto modelViewProj worldviewproj_matrix
param_named_auto worldView worldview_matrix
}
}
fragment_program SoftParticles_PS hlsl
{
source SoftParticles.hlsl
entry_point main_ps
target ps_3_0
default_params
{
param_named fadeDistance float 0.2
param_named_auto fogParams fog_params
param_named_auto eyePosition camera_position_object_space
param_named_auto nearClipDistance near_clip_distance
param_named_auto farClipDistance far_clip_distance
param_named_auto inverseViewportWidth inverse_viewport_width
param_named_auto inverseViewportHeight inverse_viewport_height
}
}
If you want the shader to use "scene_blend alpha_blend" instead of "scene_blend add" in the particle material, you will have to replace this:
Code: Select all
float4 color = tex2D(DiffuseMap, uv) * vertexColour;
color.xyz *= softMultiplier;
float fogEnabled = fogParams.x; // x is expDensity, which holds whether or not it is enabled
float fogStart = fogParams.y * fogParams.y;
float fogEnd = fogParams.z * fogParams.z;
float3 squaredLengthVec = eyePosition - position;
float squaredLength = dot(squaredLengthVec, squaredLengthVec);
float fogFactor = (1.0 - saturate((fogEnd - squaredLength) / (fogEnd - fogStart))) * fogEnabled;
color.xyz *= 1.0 - fogFactor;
with this:
Code: Select all
float4 color = tex2D(DiffuseMap, uv) * vertexColour;
color.a *= softMultiplier;
float fogEnabled = fogParams.x; // x is expDensity, which holds whether or not it is enabled
float fogStart = fogParams.y * fogParams.y;
float fogEnd = fogParams.z * fogParams.z;
float3 squaredLengthVec = eyePosition - position;
float squaredLength = dot(squaredLengthVec, squaredLengthVec);
float fogFactor = (1.0 - saturate((fogEnd - squaredLength) / (fogEnd - fogStart))) * fogEnabled;
color.xyz = lerp(color.xyz, fogColour.xyz, fogFactor);
I use both shaders in my game, one for each.
You will clearly see the difference when particles are close to a wall if it works. It will never intersect with it.
If you want, you can try it in my game (Spellheart), just make sure Soft Particles and Replays is checked in the options menu. Then you can cast an ability like Meteor close to a wall and go into the replay of the game where you can watch it from all angles. Then you will see particles never collide with any 3D in the world at all, which is the end goal of course.
You can also try it in my in-game map editor to see how it works against the floor or a wall.