Jump to content

Cone Step Mapping (Released)


franck22000
 Share

Recommended Posts

Here is a new shader for LE it's called cone step mapping ( CSM ) and it will give you a great relief effect for your materials :)

 

- CSM is very fast, it's faster and much more efficient than parralax occlusion mapping.

- CSM need a cone step map that you can generate ( it take the heightmap and generate cone step map from it ).

- CSM will be very good for those who want to make static scenes without gameplay.

- If you want to add this in your game, remember that decals will not apply correctly on the surface of your objects with this shader applied it can look bad, you will need to lower the depth to make it not too strange.

- CSM rendering is better if you use the FXAA 3.11 anti-aliasing shader.

 

 

SHADER UNIFORMS

 

conestep_depth : You can change this value to ajust the depth of the effect, be gentle with that otherwise you will get too much artifacts.

 

 

DOWNLOAD (version 1.0)

 

 

 

STANDARD INSTALLATION

 

1- Download the file in this post.

 

2- Put the 2 Shaders Presets files in the "Mesh" folder of your shaders.pak

 

3- Put this code in the Mesh.frag shader just before the Main() function:

 

#ifdef LW_CONESTEP
uniform sampler2D LW_CONESTEP;
varying vec3 eyevec;

uniform float conestep_depth = 0.08;

void conestep_10step (sampler2D csmMap, inout vec3 dp, in vec3 ds)
{

   float iz = max(abs(ds.x),abs(ds.y));
   float w = 1.2;
   vec4 t;

   // 10 Steps
   t=texture2D(csmMap,dp.xy);
   dp += ds * w * (t.r - dp.z) / (iz/(t.g*t.g) + 1.0);

   t=texture2D(csmMap,dp.xy);
   dp += ds * w * (t.r - dp.z) / (iz/(t.g*t.g) + 1.0);
   t=texture2D(csmMap,dp.xy);
   dp += ds * w * (t.r - dp.z) / (iz/(t.g*t.g) + 1.0);
   t=texture2D(csmMap,dp.xy);
   dp += ds * w * (t.r - dp.z) / (iz/(t.g*t.g) + 1.0);
   t=texture2D(csmMap,dp.xy);
   dp += ds * w * (t.r - dp.z) / (iz/(t.g*t.g) + 1.0);

   t=texture2D(csmMap,dp.xy);
   dp += ds * w * (t.r - dp.z) / (iz/(t.g*t.g) + 1.0);
   t=texture2D(csmMap,dp.xy);
   dp += ds * w * (t.r - dp.z) / (iz/(t.g*t.g) + 1.0);
   t=texture2D(csmMap,dp.xy);
   dp += ds * w * (t.r - dp.z) / (iz/(t.g*t.g) + 1.0);
   t=texture2D(csmMap,dp.xy);
   dp += ds * w * (t.r - dp.z) / (iz/(t.g*t.g) + 1.0);
   t=texture2D(csmMap,dp.xy);
   dp += ds * w * (t.r - dp.z) / (iz/(t.g*t.g) + 1.0);

   return;
}



void conestep_exp(sampler2D csmMap, inout vec3 dp, vec3 ds, float dist_factor)
{
	float iz = max(abs(ds.x), abs(ds.y));
	vec4  t = texture2D(csmMap,dp.xy);
	float ht, old_ht;
	float CR = 0.0;

	while (t.r > dp.z)
	{
		CR = t.g * t.g;

		dp += ds * (dist_factor + (t.r - dp.z) * CR) / (iz + CR);

		t = texture2DLod(csmMap, dp.xy, 0.0);
	}

	ht = (t.r - dp.z);
	dist_factor /= (iz + CR);
	dp -= ds * dist_factor;

	t = texture2D(csmMap,dp.xy);
	old_ht = t.r - dp.z;

	dp += ds * dist_factor * (1.0 - clamp (ht / (ht - old_ht), 0.0, 1.0));

	t = texture2D(csmMap, dp.xy);
	dp += ds * (t.r - dp.z) / (iz/(t.g*t.g) + 1.0);

	return;
}
#endif

 

4- Put this code in the Mesh.frag shader inside the Main() function just after the #ifdef LW_PARALLAXMAP section:

 

#ifdef LW_CONESTEP
	float a = -conestep_depth / eyevec.z;
	vec3 s = vec3((eyevec * a).xy, 1);

	float df = 0.1 * sqrt(length(fwidth(texcoord.xy)));

	vec3 uv = vec3(texcoord.xy, 0);

	// HIGH QUALITY
	conestep_exp(LW_CONESTEP, uv, s, df);

	// LOW QUALITY
	//conestep_10step(LW_CONESTEP, uv, s);

	texcoord = uv.xy;
#endif

 

5- It's done ! you can use the test material provided in the zip file downloaded on a 3D object to test the effect :D

 

 

Here is 2 new screenshots to show you the effect at various angles:

 

 

 

 

You guys are going to be the death of me. Josh
Link to comment
Share on other sites

Merci. It will take me a while to look at this and check it out but I think this might work well for the rocky/gravel boundary around areas of airstrips. Certainly can't wait to try it on the interior of our Chinook helicopter which has lots of quilted padding, that should suit this shader quite well.

6600 2.4G / GTX 460 280.26 / 4GB Windows 7

Author: GROME Terrain Modeling for Unity, UDK, Ogre3D from PackT

Tricubic Studios Ltd. ~ Combat Helo

Link to comment
Share on other sites

im used to generate the cone map from the heigthmap then tweak the cone map manualy like adding a little of gaussian blur to remove artifacts and minor modifications...

 

Sorry to be a pain, but what is the process of generating the heightmap from the diffuse?

 

Is it a greyscale? 0 to 255? Could you provide the original heightmap you used as a reference? I'm trying to create my own and getting odd results.

6600 2.4G / GTX 460 280.26 / 4GB Windows 7

Author: GROME Terrain Modeling for Unity, UDK, Ogre3D from PackT

Tricubic Studios Ltd. ~ Combat Helo

Link to comment
Share on other sites

You need to generate a heighmap ( grayscale image ) then with this just drag the heightmap on the tool provided to make a stepmap :)

But you will not have good result if you are not editing the heigthmap yourself, you need to work on the heigth map manually to have a good depth effect without too much artifacts.

You guys are going to be the death of me. Josh
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...