Jump to content

New Reflection shader


YouGroove
 Share

Recommended Posts

It is based on LE3 environment shader and Shadmar tweak.

 

You can control specular and reflection using a specular map and a reflection map, instead of having some uniform specular (it works and looks lot better than the previous PBR style effect shader).

This is usefull for metal parts where you need to control the amount of reflection and specular on the model textures.

 

Enjoy smile.png

 

#version 400
#define BFN_ENABLED 1
//Uniforms
uniform sampler2D texture0;//diffuse map
uniform sampler2D texture1;//normal map
uniform sampler2D texture2;//reflection map
uniform sampler2D texture3;//specular map
uniform samplerCube texture5;//cube map
uniform samplerCube texture15;//BFN map
uniform mat4 cameramatrix;
uniform mat4 projectioncameramatrix;
uniform vec2 camerarange;
uniform float camerazoom;
uniform vec2 buffersize;
uniform mat4 camerainversematrix;
uniform vec4 ambientlight;
uniform vec4 materialcolorspecular;
uniform mat3 cameranormalmatrix;
uniform vec3 cameraposition;
uniform int decalmode;
//Inputs
in vec4 ex_vertexposition;
in vec2 ex_texcoords0;
in vec2 ex_texcoords1;
in vec4 ex_color;
in float ex_selectionstate;
in vec3 ex_normal;
in vec3 ex_tangent;
in vec3 ex_binormal;
in float clipdistance0;
out vec4 fragData0;
out vec4 fragData1;
out vec4 fragData2;
out vec4 fragData3;
float DepthToZPosition(in float depth) {
return camerarange.x / (camerarange.y - depth * (camerarange.y - camerarange.x)) * camerarange.y;
}
void main(void)
{
//Clip plane discard
if (clipdistance0>0.0) discard;
vec4 outcolor = ex_color;
float alpha;
//Modulate blend with diffuse map
outcolor *= texture(texture0,ex_texcoords0);
alpha = outcolor.a;


vec4 color_specular = texture(texture3,ex_texcoords0) * materialcolorspecular;


//Normal map
vec3 normal = ex_normal;
normal = normalize(texture(texture1,ex_texcoords0).xyz * 2.0 - 1.0);
float ao = normal.z;
normal = ex_tangent * normal.x + ex_binormal * normal.y + ex_normal * normal.z;

//Cubemap
vec3 cubecoord = normalize( ex_vertexposition.xyz - cameraposition );
vec3 reflectdir = cameranormalmatrix * normal;
//reflectdir.y *= -1.0;
//cubecoord = reflect(reflectdir,cubecoord);
cubecoord = reflect(cubecoord,reflectdir);

vec4 emission = texture(texture5,cubecoord) * texture(texture2,ex_texcoords0) ;


//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)));
fragData1.a = fragData0.a;
#else
//Low-res normals
fragData1 = vec4(normalize(normal)*0.5+0.5,fragData0.a);
#endif
//float specular = materialcolorspecular.r * 0.299 + materialcolorspecular.g * 0.587 + materialcolorspecular.b * 0.114;

float specular = color_specular.r * 0.299 + color_specular.g * 0.587 + color_specular.b * 0.114;

int materialflags=1;
if (ex_selectionstate>0.0) materialflags += 2;
if (decalmode==1) materialflags += 4;//brush
if (decalmode==2) materialflags += 8;//model
if (decalmode==4) materialflags += 16;//terrain
fragData1.a = materialflags/255.0;
fragData2 = vec4(emission.rgb,specular);
}

post-3271-0-10665200-1444066901_thumb.jpg

Stop toying and make games

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