Wchris Posted July 15, 2016 Share Posted July 15, 2016 New puzzle for the community with an artistic result in an atempt to animate water (because current LE4 waterplane cannot be animated right ?) I downloaded an old LE3 Shadmar exemple "Water_with_examplemap" from this old thread http://www.leadwerks.com/werkspace/topic/10794-needing-help/#entry79138 It took me 2 days to figure out I had to use "drag & drop" to drag a camera to the Script.CameraOrPlayer=""--entity field and now it works but I my water is red. Can someone explain me why the water is red instead of blue ? Thank you PS: had to put a camera2 in the scene and modify this line self.camera=self.CameraOrPlayer.script.camera or self.CameraOrPlayer with this self.camera=self.CameraOrPlayer Otherwise it will crash if there is no FPS player attached to the CameraOrPlayer field Quote Windows 7 home - 32 bits Intel Quad Q6600 - nVidia GTX 460 1GB - 2 GB RAM Link to comment Share on other sites More sharing options...
nick.ace Posted July 15, 2016 Share Posted July 15, 2016 Without looking at the GLSL code, it's probably not setting the material flag correctly. Look at the examples for model shaders. Without this flag explicitly set, the lighting shader will by default assume that it's "selected." This is actually how objects are colored when you select them in the editor. 1 Quote Link to comment Share on other sites More sharing options...
Wchris Posted July 16, 2016 Author Share Posted July 16, 2016 Without looking at the GLSL code, it's probably not setting the material flag correctly. Look at the examples for model shaders. Without this flag explicitly set, the lighting shader will by default assume that it's "selected." This is actually how objects are colored when you select them in the editor. Thank you very much for the hint, this info definitely will be a great help. I had no idea what was going on. Thanks ! Quote Windows 7 home - 32 bits Intel Quad Q6600 - nVidia GTX 460 1GB - 2 GB RAM Link to comment Share on other sites More sharing options...
Wchris Posted July 16, 2016 Author Share Posted July 16, 2016 After experimenting, it turned out I had to comment those lines to get it working #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,fragData0.a); #endif I know nothing about shaders, what is fragData1 supposed to do ? 1 Quote Windows 7 home - 32 bits Intel Quad Q6600 - nVidia GTX 460 1GB - 2 GB RAM Link to comment Share on other sites More sharing options...
nick.ace Posted July 16, 2016 Share Posted July 16, 2016 fragData1 is the normal buffer. The alpha channel for the normal buffer is used to store flags such as selection state and decal stuff. Are there any other fragData1's being set? I thought that by default if you didn't write to it, the unselected state flag wasn't set (so it would be selected) because in my lighting tutorial I remember having to modify the lighting shader in order to prevent this from happening. Maybe that changed though. 1 Quote Link to comment Share on other sites More sharing options...
Wchris Posted July 16, 2016 Author Share Posted July 16, 2016 Oh tutorial ? is this tutorial from you ? I will definitely watch all those shader tutorial videos and attempt to understand what I do ! Thanks a lot ! 1 Quote Windows 7 home - 32 bits Intel Quad Q6600 - nVidia GTX 460 1GB - 2 GB RAM Link to comment Share on other sites More sharing options...
nick.ace Posted July 16, 2016 Share Posted July 16, 2016 Yeah, no problem! I don't actually show how to alter the lighting shader in a tutorial, but I mentioned it in a video because it took me forever to figure out why everything was red when I was overriding Leadwerks lighting lol. That's a very Leadwerks-specific thing though. Quote Link to comment Share on other sites More sharing options...
Wchris Posted July 17, 2016 Author Share Posted July 17, 2016 Hi, I learned some tricks from your tutorial 2, like how to transform a Vec4 into a Vec3.xyz+vec3.a to remove/tweak the alpha channel separately and set it back. I came up with this modification where I re-substract 10 to the alpha chanel to remove Leadwerks "red selection boolean" #if BFN_ENABLED==1 //Best-fit normals fragData1 = vec4(texture(texture15,normalize(vec3(normal.x,-normal.y,normal.z))).xyz,texture(texture15,normalize(vec3(normal.x,-normal.y,normal.z))).a-10); #else //Low-res normals fragData1 = vec4(normalize(normal)*0.5+0.5,fragData0.a-10); #endif It works but I see no difference compared to the version where fragData1 is completely commented out. An alternative is to remove the apha chanel completely and set it to 0 in the vec4 with the same result. I believe something is still wrong because I do not see the water go up & down at the shoreline. Quote Windows 7 home - 32 bits Intel Quad Q6600 - nVidia GTX 460 1GB - 2 GB RAM Link to comment Share on other sites More sharing options...
nick.ace Posted July 17, 2016 Share Posted July 17, 2016 Ok, my bad. The material flag has to contain a 2 to be selected. Don't subtract 10 though. You should be using bit operations or else you can go negative and cause a bunch of flags to be checked by accident. You can just set the alpha channel to 0, but I would just see what the example shaders do since they include a bunch of other useful flags. Don't comment it out though because then the lighting gets screwed up because the normals are needed for good lighting. Quote Link to comment Share on other sites More sharing options...
Wchris Posted July 17, 2016 Author Share Posted July 17, 2016 Ok, my bad. The material flag has to contain a 2 to be selected. Don't subtract 10 though. You should be using bit operations or else you can go negative and cause a bunch of flags to be checked by accident. I also wondered about this, but in the vertex stader he is adding 10 that's why I substract 10 to cancel this //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. 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; } I find it very difficult to understand what happens to "alpha chanel-10" once multiplied by the vertex_color and materialdiffuseI But 10 (00001010) contains the 2 (00000010) bit. I believe in binary addition and substract work like a bitwise boolean operation. You probably allready know this, but if someone else is reading he won't understand what we are talking about, so I'll explain binary additions and substractions a little. if you take 255 it is 11111111 in binary if you take 10 it is 00001010 in binary if youn take 2 it is 00000010 in binary if you do 255 - 10 in binary you get 11111111 - 00001010 = 11110101 = 245 if you do 255 - 2 in binary you get 11111111 - 00000010 = 11111101 = 253 you can try it here http://www.calculator.net/binary-calculator.html?number1=11111111&c2op=-&number2=00000010&calctype=op&x=84&y=16 I tryed it, and the fix also works with -2 instead of -10, so you are probably right. But when I tryed a bitwise operation and with "&& 253" or "& 253" shader failed to compile. Cheers PS: back to the shader tutorials #3 is waiting for me after a good night of sleep (by the way Is there a wiki about leadwerks shaders somewhere ?) Quote Windows 7 home - 32 bits Intel Quad Q6600 - nVidia GTX 460 1GB - 2 GB RAM Link to comment Share on other sites More sharing options...
nick.ace Posted July 17, 2016 Share Posted July 17, 2016 (edited) Well && isn't a bit operation, but were you setting a variable with &? I wish that the code for the model shaders used bitwise operations instead of addition because I think it would make more sense. What I was saying about subtracting was mainly if the total of the flags was less than ten. For example (using 8 bits instead of 32-bit int): 2 - 10 = -8 0000010 - 00001010 = 11111000 Now, you just checked a bunch of flags because the lighting shader uses bitwise operations to check for flags rather than subtraction. So far, there isn't a wiki page on it, but I can make one. Also, if you or anyone else wants me to make tutorials, I can do that. IDK how useful people find them. They do take time to make, but I like doing it, just not sure how good they are because I haven't gotten a lot of feedback. Edit: Just created a wiki page: http://leadwerks.wikidot.com/wiki:shader-specification Edited July 17, 2016 by nick.ace 1 Quote Link to comment Share on other sites More sharing options...
Wchris Posted July 18, 2016 Author Share Posted July 18, 2016 Well && isn't a bit operation What are the commands for bitwise operations ? I'm a complete beginner, maybe it is worth mentionning these commands in a tutorial. If it is allready in a video tutorial, please point me to it because I missed it and need to rewatch. Quote Windows 7 home - 32 bits Intel Quad Q6600 - nVidia GTX 460 1GB - 2 GB RAM Link to comment Share on other sites More sharing options...
nick.ace Posted July 18, 2016 Share Posted July 18, 2016 There are a bunch of commands, but they are part of the C standard, so they are not exclusive to shaders. I may make a tutorial on all of them because you can do some neat tricks with them, but there may already be a lot of material on them. https://en.wikipedia.org/wiki/Bitwise_operations_in_C The && is a boolean operator, and that makes a difference in many situations. You can abuse the bitwise operators if you are only dealing with booleans, but for every other data types you will get incorrect results for certain input. Quote Link to comment Share on other sites More sharing options...
shadmar Posted July 19, 2016 Share Posted July 19, 2016 I dont know where you found this, but it's not for LE4, it was an interim water for LE3 when there were no other water solutions. So it's not updated to work with LE4. Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
Wchris Posted July 19, 2016 Author Share Posted July 19, 2016 I dont know where you found this, but it's not for LE4, it was an interim water for LE3 when there were no other water solutions. So it's not updated to work with LE4. I know it's from LE3 (the link of the thread where I found it is provided in my first post). I did not find another water shader for LE4 and could not find how to animate current default water in LE4. So I tryed to use this one. Quote Windows 7 home - 32 bits Intel Quad Q6600 - nVidia GTX 460 1GB - 2 GB RAM Link to comment Share on other sites More sharing options...
blueapples Posted July 20, 2016 Share Posted July 20, 2016 Did you actually get this fully working? I'd love to play with it. Haven't really tweaked my water much at all past throwing shadmar's newer water + caustics shader on it (which looks really cool, especially in the dark). Quote Link to comment Share on other sites More sharing options...
Wchris Posted July 20, 2016 Author Share Posted July 20, 2016 Did you actually get this fully working? I'd love to play with it. Haven't really tweaked my water much at all past throwing shadmar's newer water + caustics shader on it (which looks really cool, especially in the dark). yes it works, but I'm just a beginner experimenting things so it's still 99% Shadmar's work, I just tweaked it while learning shaders. I would still prefer LE4 to be natively able to animate the water by providing a listbox under the scene root to add all animated normal maps and handle them itself. The biggest issue is that the water has no physics, it's just a visual, nothing will float and move with the waves. Here is the file : Shadmar_Water_with_examplemap.zip ask me if you need instructions Quote Windows 7 home - 32 bits Intel Quad Q6600 - nVidia GTX 460 1GB - 2 GB RAM Link to comment Share on other sites More sharing options...
tumira Posted October 24, 2016 Share Posted October 24, 2016 Hi Wchris I got error "attempt to index global 'watershader' (a nil value)" error on line 28 in water.lua How can I fix this ? ***Woops. Copied to wrong folder. Quote Link to comment Share on other sites More sharing options...
Wchris Posted October 30, 2016 Author Share Posted October 30, 2016 ***Woops. Copied to wrong folder. Hi. Juste Reading your post. Did you fix the issue ? Quote Windows 7 home - 32 bits Intel Quad Q6600 - nVidia GTX 460 1GB - 2 GB RAM 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.