Jump to content

Missing reflection shader


YouGroove
 Share

Recommended Posts

I was going to select reflective shader for some ball game , but found nothing.

 

Yep there is no more reflective environment shader in 3.1 , or fake one using some bitmap for environment.

That's usefull for windows, or metal like cars.

We had a good one in 3.0 for BSP if i remember well.

 

Or for tiles textures we could have as good as this one below (perhas not real time reflection caus more GPU consuming)

balloonhead_1.png

  • Upvote 1

Stop toying and make games

Link to comment
Share on other sites

How to make a reflective cubemap shader

 

1. Open up diffuse.shader in the shader editor :

2. Click Vertex in the left tab

3. Add under outputs

 

out vec4 ex_vertexposition;

 

4. Find :

 

vec4 modelvertexposition = entitymatrix_ *....

 

Add after :

 

ex_vertexposition = modelvertexposition;  //we need this position the fragment shader

 

5. Click Fragment in the left tab

6. Add under Uniforms

 

uniform samplerCube texture4; //cube map for reflection texture from material
uniform mat3 cameranormalmatrix;  //need normalmatrix from camera for correct reflection in relation to camera rotation
uniform vec3 cameraposition; //need camera position so we know the distance from the fragment. (pixel)

 

7. Add under Inputs

 

in vec4 ex_vertexposition;

 

8. find :

 

outcolor *= texture(texture0,ex_texcoords0);

 

after add :

 

vec3 cubecoord = reflect( normalize( ex_vertexposition.xyz - cameraposition ) , normalize(cameranormalmatrix * normal).xyz );  //this is industy standard cubecoordinates for reflection..
outcolor = mix(outcolor,texture(texture4,cubecoord),0.5); //mix diffuse with cubemap reflection 50%

 

See that it compiles, save

 

Make material with a diffusemap in texture0 and cubemap in texture4

 

Result should be like this :

post-747-0-52613400-1395859658_thumb.jpg

  • Upvote 2

HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB

Link to comment
Share on other sites

Will it be added to Leadwerks 3.1 official shaders ?

Is it possible with normal map ?

 

(the less i touch shader code the best laugh.png , but i'll try it perhaps)

 

-----------------

The ultimate shader now :

Would it be possible to make vary reflectivity of cube map depending on alpha channel of diffuse texture of the object ?

diffuse texture Alpha channel = 0 (fully transparent) -> shader = fully reflective

diffuse texture Alpha channel = 1 (fully opaque) -> shader = no reflection on diffuse texture

Between = variation between cube map and diffuse map

This would open new possibility like making metal less or more reflective, and make some water on floor depending on alpha of diffuse texture.

 

 

It's not something i ask or want right now, but more a suggestion and good idea i think to ahve such advanced shader in LE 3.1.

 

 

---------------

 

Thanks Shadmar.

Stop toying and make games

Link to comment
Share on other sites

diffuse texture Alpha channel = 0 (fully transparent) -> shader = fully reflective

diffuse texture Alpha channel = 1 (fully opaque) -> shader = no reflection on diffuse texture

 

yes, just replace

outcolor = mix(outcolor,texture(texture4,cubecoord),0.5); //mix diffuse with cubemap reflection 50%

 

with

 

outcolor = mix(outcolor,texture(texture4,cubecoord),ex_color.a); //mix diffuse with cubemap reflection based on alpha

  • Upvote 1

HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB

Link to comment
Share on other sites

That is the advantage of the workshop. Just subscribe to the item.

you dont have to install it, the item is automatically downloaded, placed in your project folder.

 

The person responsible for the item in the workshop can make sure that the file is always up to date. So no need for testing on your end either. Making the community more responsible for the content will result in quick fixes. If you leave all of this in Josh's area you will have to wait longer since Josh has other priorities to attend to.

  • Upvote 1
Link to comment
Share on other sites

That is the advantage of the workshop. Just subscribe to the item.

you dont have to install it, the item is automatically downloaded, placed in your project folder.

I thaught LE3 downloads, yes Steam workshop, good , i'll have to try it, didn't thaught it was so easy to integrate new stuff in Leadwerks 3.

That's great.

 

 

If you leave all of this in Josh's area you will have to wait longer since Josh has other priorities to attend to.

Right indeed.

 

How will do people using a non Steam Workshop ? will LE3 propose same style workshop ?

 

-------------------

 

I see workshops ,but no LE3 workshop in Steam app ? Must we launch Steam from browser to see it ?

Stop toying and make games

Link to comment
Share on other sites

Hi Shadmar,

 

I have edited the diffuse.shader to make it a reflective cubemap shader. But I have a problem every time I put a cubemap file in to the shader it seems like it is changed. It seem to work in material editor till I save it them the cubemap turns drank in the material editor and the cubemap file it self turns dark to.

 

This is how the Vertex part looks:

 

#version 400
#define MAX_INSTANCES 256
//Uniforms
//uniform mat4 entitymatrix;
uniform vec4 materialcolordiffuse;
uniform mat4 projectioncameramatrix;
uniform mat4 camerainversematrix;
uniform instancematrices { mat4 matrix[MAX_INSTANCES];} entity;
//Attributes
in vec3 vertex_position;
in vec4 vertex_color;
in vec2 vertex_texcoords0;
in vec3 vertex_normal;
in vec3 vertex_binormal;
in vec3 vertex_tangent;
//Outputs
out vec4 ex_color;
out vec2 ex_texcoords0;
out float ex_selectionstate;
out vec3 ex_VertexCameraPosition;
out vec3 ex_normal;
out vec3 ex_tangent;
out vec3 ex_binormal;
out vec4 ex_vertexposition;
void main()
{
mat4 entitymatrix = entity.matrix[gl_InstanceID];
mat4 entitymatrix_=entitymatrix;
entitymatrix_[0][3]=0.0;
entitymatrix_[1][3]=0.0;
entitymatrix_[2][3]=0.0;
entitymatrix_[3][3]=1.0;

vec4 modelvertexposition = entitymatrix_ * vec4(vertex_position,1.0);
ex_VertexCameraPosition = vec3(camerainversematrix * modelvertexposition);
gl_Position = projectioncameramatrix * modelvertexposition;
ex_vertexposition = modelvertexposition;  //we need this position the fragment shader
mat3 nmat = mat3(camerainversematrix);//[0].xyz,camerainversematrix[1].xyz,camerainversematrix[2].xyz);//39
nmat = nmat * mat3(entitymatrix[0].xyz,entitymatrix[1].xyz,entitymatrix[2].xyz);//40
ex_normal = normalize(nmat * vertex_normal);
ex_tangent = normalize(nmat * vertex_tangent);
ex_binormal = normalize(nmat * vertex_binormal);

ex_texcoords0 = vertex_texcoords0;

ex_color = vec4(entitymatrix[0][3],entitymatrix[1][3],entitymatrix[2][3],entitymatrix[3][3]);

//If an object is selected, 10 is subtracted from the alpha color.
//This is a bit of a hack that packs a per-object boolean into the alpha value.
ex_selectionstate = 0.0;
if (ex_color.a<-5.0)
{
 ex_color.a += 10.0;
 ex_selectionstate = 1.0;
}

ex_color *= vec4(1.0-vertex_color.r,1.0-vertex_color.g,1.0-vertex_color.b,vertex_color.a) * materialcolordiffuse;
}

 

This is how the Fragment part looks:

 

#version 400
#define BFN_ENABLED 1
//Uniforms
uniform sampler2D texture0;//diffuse map
uniform samplerCube texture15;//BFN map
uniform vec4 materialcolorspecular;
uniform vec4 lighting_ambient;
uniform samplerCube texture4; //cube map for reflection texture from material
uniform mat3 cameranormalmatrix;  //need normalmatrix from camera for correct reflection in relation to camera rotation
uniform vec3 cameraposition; //need camera position so we know the distance from the fragment. (pixel)
//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;
in vec4 ex_vertexposition;
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;
//Modulate blend with diffuse map
outcolor *= texture(texture0,ex_texcoords0);
vec3 cubecoord = reflect( normalize( ex_vertexposition.xyz - cameraposition ) , normalize(cameranormalmatrix * normal).xyz );  //this is industy standard cubecoordinates for reflection..
outcolor = mix(outcolor,texture(texture4,cubecoord),0.5); //mix diffuse with cubemap reflection 50%

//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);
}

 

Maybe I did something wrong?

 

b.t.w I use 3.1 indi version

Link to comment
Share on other sites

Reinstalled leadwerks

 

And I have the same error now no matter what texture or shader I use when I try to make a material in the material editor:

 

Error: Texture file header not found.

Error: Failed to load texture "D:/leadwerks/RescueDrYoung/Materials/Metal/diamondsteel_spec.tex"

Failed to load thumbnail 6 for D:/leadwerks/RescueDrYoung/Materials/Metal/diamondsteel_spec.tex

Loading texture "D:/leadwerks/RescueDrYoung/Materials/Metal/diamondsteel_spec.tex..."

 

This looks like a bug in the material editor to me?

Link to comment
Share on other sites

@shadmar :

Even trying on other folders like models or otehr non shader ones, Material editor still turns .tex files black when saving material.

We posted some bugs to that related problem.

 

Like DanceTweety said it's a bug in the material editor program when you save material.

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