Jump to content

Alpha Faded Material Shader?


Dan22
 Share

Recommended Posts

I have been trying to get blood textures and various other materials such as faked volumetric lighting, to be implemented into my level but the thing is it has to be a solid colour and does not work if it has any slight fade to alpha.

 

Example (Tick Means It only works like that, Red Cross Means it won't work):

 

75bf5db1c58a249096fb4fa55685f3b2.png

 

 

cc1645f18d03b8bdaf9c18e7b4be89d3.png

 

 

As you can see, the top picture will not work as it has faded areas and using the alpha mask shader does not work with it, however it only works with solid materials with an alpha background.

 

Any solutions or methods doing this? Or does a shader need to be made specifically for this?

 

If so, please reply and if somone could kindly make a shader for this for the whole community it would be very good as its annoying having to use cartoony looking blood and other materials because it doesn't work.

 

Thanks.

Link to comment
Share on other sites

Well, I am not really getting why the above one doesn't work for you but you can just include a threshold in your fragment shader. Just add (after fragData0 was set):

if(fragData0.a > 0.5)
fragData0.a = 1;
else
fragData0.a = 0;

You can also use a threshold other than 0.5.

 

Edit:

What would be even easier:

 

fragData0.a = round(fragData0.a);

 

and if the shader also set fragData1 etc. just add the lines for them as well.

Link to comment
Share on other sites

Just to make it easier i'll paste the entire fragment section:

 

#version 400

#define BFN_ENABLED 1

 

//Uniforms

uniform sampler2D texture0;//diffuse map

uniform samplerCube texture15;//BFN map

uniform vec4 materialcolorspecular;

uniform vec4 lighting_ambient;

 

//Lighting

uniform vec3 lightdirection[4];

uniform vec4 lightcolor[4];

uniform vec4 lightposition[4];

uniform float lightrange[4];

uniform vec3 lightingcenter[4];

uniform vec2 lightingconeanglescos[4];

uniform vec4 lightspecular[4];

 

//Inputs

in vec2 ex_texcoords0;

in vec4 ex_color;

in float ex_selectionstate;

in vec3 ex_VertexCameraPosition;

in vec3 ex_normal;

in vec3 ex_tangent;

in vec3 ex_binormal;

 

out vec4 fragData0;

out vec4 fragData1;

out vec4 fragData2;

out vec4 fragData3;

 

void main(void)

{

vec4 outcolor = ex_color;

vec4 color_specular = materialcolorspecular;

vec3 normal = ex_normal;

 

vec4 texcolor = texture(texture0,ex_texcoords0);

 

if(texcolor.a < 0.15)

discard;

 

//Modulate blend with diffuse map

outcolor *= texcolor;

 

//Blend with selection color if selected

fragData0 = outcolor;// * (1.0-ex_selectionstate) + ex_selectionstate * (outcolor*0.5+vec4(0.5,0.0,0.0,0.0));

 

#if BFN_ENABLED==1

//Best-fit normals

fragData1 = texture(texture15,normalize(vec3(normal.x,-normal.y,normal.z)));

#else

//Low-res normals

fragData1 = vec4(normalize(normal)*0.5+0.5,1.0);

#endif

fragData1.a = materialcolorspecular.r * 0.299 + materialcolorspecular.g * 0.587 + materialcolorspecular.b * 0.114;

int materialflags=1;

if (ex_selectionstate>0.0) materialflags += 2;

fragData2 = vec4(0.0,0.0,0.0,materialflags/255.0);

}

 

Link to comment
Share on other sites

You can see, the shader uses fragData0, fragData1 and fragData2.

So try adding

fragData0.a = round(fragData0.a);
fragData1.a = round(fragData1.a);
fragData2.a = round(fragData2.a);

in the end, just before the closing }

 

@ScrotieFlapWack

I don't know whether it is documented anywhere but I also only found the answer via googling, which led me to Rastar's Blog:

http://www.leadwerks.com/werkspace/blog/117/entry-1167-up-part-2/

And now I have to take a deeper breath: Leadwerks 3.1 is using a deferred renderer. This means that all lighting calculations are done behind the scenes in a separate processing step taking place after the fragment shader has run. So you won't see lighting calculations for diffuse reflection, specular reflection etc. here, but rather a filling-up of several buffers:
  • fragData0 contains the diffuse color (rgb) and transparency (alpha) of the fragment
  • fragData1 stores the normal (rgb) and specularity (alpha)
  • fragData2 holds the emissive color (rgb) and a flag for lighting on/off (alpha)
  • fragData3 - no idea if this is being used and what it might hold

 

Edit:

Also what you are editing is just the alpha value. The code I provided just says: If the alpha value is over 0.5 then set it to 1, else set it to 0.

Link to comment
Share on other sites

What exactly is the problem?

I can create a Material, activate Z-Sort and switch the Blend mode to Alpha and use the fragment shader you provided above (I also used the vertex shader from the standard diffuse shader and made it fit to the fragment shader.)

With this I can get a material which is transparent.

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...