Jump to content
  • Advertisement
Sign in to follow this  
dqhendricks

Need shader guidance (the farther away from edge, the darker).

This topic is 1461 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi people,

 

I need a specific shader, and would like to know if it is possible to make an efficient version of what I need. I am not much of a graphics programmer myself, so any guidance is helpful.

 

The shader I would like to build makes the texture darker, the farther away from the edge the pixel is. So near the edge of an object, the texture would shine through 100%, but the farther away from the edge, the more black is added to the texture until it is 100% black in the center. Is it possible to do this efficiently using a shader?

 

A side question about this is, for this proposed shader, if I put two objects (same scale, same material) next to each other touching, will the "edge" be around each object individually, or will the edge be around both objects together as if they were one object?

 

Thanks for any help!

Edited by dqhendricks

Share this post


Link to post
Share on other sites
Advertisement


The shader I would like to build makes the texture darker, the farther away from the edge the pixel is. So near the edge of an object, the texture would shine through 100%, but the farther away from the edge, the more black is added to the texture until it is 100% black in the center. Is it possible to do this efficiently using a shader?

Do you talk about textures or surfaces ? Nevertheless, if you have a texture , you can fade it in/out to the center accordingly to the used texture coord. Here is one way of doing it:

var2 tex_coord = vec2(..) // between 0..1
tex_coord = tex_coord* 2.0 - 1.0; // between -1..0..1
float f  = min(1.0, dot(tex_coord,tex_coord));


vec3 final_color = base_color * f + black * (1-f); // use mix (GLSL), lerp(HLSL) etc


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!