Sign in to follow this  

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

This topic is 1121 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


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

This topic is 1121 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this