YouGroove Posted March 26, 2014 Share Posted March 26, 2014 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) 1 Quote Stop toying and make games Link to comment Share on other sites More sharing options...
shadmar Posted March 26, 2014 Share Posted March 26, 2014 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 : 2 Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
AggrorJorn Posted March 26, 2014 Share Posted March 26, 2014 Nice work Shadmar. I have added it to the wiki for future reference: http://leadwerks.wikidot.com/wiki:reflective-cubemap-shader 1 Quote Link to comment Share on other sites More sharing options...
YouGroove Posted March 26, 2014 Author Share Posted March 26, 2014 Will it be added to Leadwerks 3.1 official shaders ? Is it possible with normal map ? (the less i touch shader code the best , 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. Quote Stop toying and make games Link to comment Share on other sites More sharing options...
shadmar Posted March 26, 2014 Share Posted March 26, 2014 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 1 Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
YouGroove Posted March 27, 2014 Author Share Posted March 27, 2014 Didn't imagined it could be so easy I think bunch of people could be interested a lot, just need to show real working example. Quote Stop toying and make games Link to comment Share on other sites More sharing options...
AggrorJorn Posted March 27, 2014 Share Posted March 27, 2014 These are great items for the Steam workshop. Quote Link to comment Share on other sites More sharing options...
YouGroove Posted March 27, 2014 Author Share Posted March 27, 2014 Great items to be integrated in Leadwerks 3.1 as standard shaders instead Why always have to go workshop, download, install, test, if they would be present in 3.1 ? 1 Quote Stop toying and make games Link to comment Share on other sites More sharing options...
AggrorJorn Posted March 27, 2014 Share Posted March 27, 2014 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. 1 Quote Link to comment Share on other sites More sharing options...
YouGroove Posted March 27, 2014 Author Share Posted March 27, 2014 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 ? Quote Stop toying and make games Link to comment Share on other sites More sharing options...
AggrorJorn Posted March 27, 2014 Share Posted March 27, 2014 It is in private beta atm. see Josh's blog post. Quote Link to comment Share on other sites More sharing options...
wayneg Posted March 27, 2014 Share Posted March 27, 2014 Nice work Shadmar ! Quote Link to comment Share on other sites More sharing options...
YouGroove Posted March 28, 2014 Author Share Posted March 28, 2014 @Shadmar : I don't see any effect ? (I put texture diffuse and sky texture on Slot 4 , shader file attached to test) environment.zip Quote Stop toying and make games Link to comment Share on other sites More sharing options...
gamecreator Posted March 28, 2014 Share Posted March 28, 2014 Do you have the private beta version of Leadwerks? I imagine it wouldn't work without that. Quote Link to comment Share on other sites More sharing options...
YouGroove Posted March 28, 2014 Author Share Posted March 28, 2014 Steam 3.1 Beta Do you have same ? Could you try the file environnment shader (it's diffuse + shadmar modifications) Quote Stop toying and make games Link to comment Share on other sites More sharing options...
shadmar Posted March 28, 2014 Share Posted March 28, 2014 Should work in any 3.1. Remember to assign this shader to your material. Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
YouGroove Posted March 28, 2014 Author Share Posted March 28, 2014 yes i did , but nothing, just try my shader file. Quote Stop toying and make games Link to comment Share on other sites More sharing options...
shadmar Posted March 29, 2014 Share Posted March 29, 2014 Yes it works just fine. 1 Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
DanceTweety Posted April 2, 2014 Share Posted April 2, 2014 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 Quote Link to comment Share on other sites More sharing options...
YouGroove Posted April 2, 2014 Author Share Posted April 2, 2014 @DanceTweety : It's perhaps not the shader the problem. Could you try to choose simple shader like normal map and see if the problem is occuring ? (It could be some bug with Material editor) Quote Stop toying and make games Link to comment Share on other sites More sharing options...
DanceTweety Posted April 2, 2014 Share Posted April 2, 2014 @DanceTweety : It's perhaps not the shader the problem. Could you try to choose simple shader like normal map and see if the problem is occuring ? (It could be some bug with Material editor) Yes I will reinstall leadwerks just to besure Quote Link to comment Share on other sites More sharing options...
DanceTweety Posted April 2, 2014 Share Posted April 2, 2014 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? Quote Link to comment Share on other sites More sharing options...
shadmar Posted April 2, 2014 Share Posted April 2, 2014 I dont think this is a shader problem. Yougrooves shader should work out of the box. However LE3 seems to be sensitive to which folders where shader and materials are stored atm. Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
YouGroove Posted April 2, 2014 Author Share Posted April 2, 2014 @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. Quote Stop toying and make games Link to comment Share on other sites More sharing options...
YouGroove Posted April 6, 2014 Author Share Posted April 6, 2014 Now material editor is fixed i tried again with previously attached file i put here. But it don't work ? Quote Stop toying and make games Link to comment Share on other sites More sharing options...
Recommended Posts
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.