havenphillip Posted January 11, 2022 Share Posted January 11, 2022 Any idea or anyone have success making something like this in Leadwerks? I'm thinking if I can get my hands on something like this I can create a shader for footprints or tire tracks in snow: https://medium.com/@strattonbrazil/writing-a-texture-painter-part-1-f0d732d287d1 1 Quote Link to comment Share on other sites More sharing options...
Vida Marcell Posted January 11, 2022 Share Posted January 11, 2022 Why inside leadwerks? Quote Link to comment Share on other sites More sharing options...
havenphillip Posted January 11, 2022 Author Share Posted January 11, 2022 I need a shader or shader/script combo that allows me to leave long trails like a painting shader like this: https://www.shadertoy.com/view/WdVyDR I need that buffer and I don't know how to go about that. Hoping someone who knows that stuff better will throw me a bone. Quote Link to comment Share on other sites More sharing options...
Josh Posted January 11, 2022 Share Posted January 11, 2022 It's easy, you just need the model to me UV mapped so that each area is unique (otherwise you will see duplicate changes all over the model), and you need to turn the picked position into a UV coordinate. Coincidentally, I was dealing with that problem yesterday. Here is my code. The position should be in local space (transformed from world space to the entity). "res" is the position I am finding the UV coordinate for: if (diffusemap) { diffuse[0] = 255; diffuse[1] = 0; diffuse[2] = 255; diffuse[3] = 255; V1 = a, V2 = b, V3 = c; DX1 = vertices[V2].position.x - vertices[V1].position.x; DY1 = vertices[V2].position.y - vertices[V1].position.y; DZ1 = vertices[V2].position.z - vertices[V1].position.z; DX2 = vertices[V3].position.x - vertices[V1].position.x; DY2 = vertices[V3].position.y - vertices[V1].position.y; DZ2 = vertices[V3].position.z - vertices[V1].position.z; NX = DY1 * DZ2 - DY2 * DZ1; NY = DX2 * DZ1 - DX1 * DZ2; NZ = DX1 * DY2 - DY1 * DX2; UX = NY * DZ2 - DY2 * NZ; UY = DX2 * NZ - NX * DZ2; UZ = NX * DY2 - NY * DX2; InvLength1 = 1.0f / sqrt(UX * UX + UY * UY + UZ * UZ); Length2 = sqrt(DX2 * DX2 + DY2 * DY2 + DZ2 * DZ2); InvLength2 = 1.0f / Length2; UX = UX * InvLength1; UY = UY * InvLength1; UZ = UZ * InvLength1; DX2 = DX2 * InvLength2; DY2 = DY2 * InvLength2; DZ2 = DZ2 * InvLength2; T1 = 0.0f; S1 = 0.0f; T2 = DX1 * UX + DY1 * UY + DZ1 * UZ; S2 = DX1 * DX2 + DY1 * DY2 + DZ1 * DZ2; T3 = 0.0f; S3 = Length2; T4 = (res.x - vertices[V1].position.x) * UX + (res.y - vertices[V1].position.y) * UY + (res.z - vertices[V1].position.z) * UZ; S4 = (res.x - vertices[V1].position.x) * DX2 + (res.y - vertices[V1].position.y) * DY2 + (res.z - vertices[V1].position.z) * DZ2; Denominator = 1.0f / ((S2 - S3) * (T1 - T3) + (T3 - T2) * (S1 - S3)); Lambda1 = ((S2 - S3) * (T4 - T3) + (T3 - T2) * (S4 - S3)) * Denominator; Lambda2 = ((S3 - S1) * (T4 - T3) + (T1 - T3) * (S4 - S3)) * Denominator; Lambda3 = 1.0f - Lambda1 - Lambda2; texcoords.x = vertices[V1].texcoords.x * Lambda1 + vertices[V2].texcoords.x * Lambda2 + vertices[V3].texcoords.x * Lambda3; texcoords.y = vertices[V1].texcoords.y * Lambda1 + vertices[V2].texcoords.y * Lambda2 + vertices[V3].texcoords.y * Lambda3; rgba = diffusemap->ReadPixel(Floor(Mod(texcoords.x, 1.0f) * float(diffusemap->size.x)), Floor(Mod(texcoords.y, 1.0f) * float(diffusemap->size.y))); diffuse[0] = Red(rgba); diffuse[1] = Green(rgba); diffuse[2] = Blue(rgba); diffuse[3] = 255; } 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
havenphillip Posted January 11, 2022 Author Share Posted January 11, 2022 Ok. I'll have to take some time to pull this apart. I can write something that puts a dot on the ground under the player but what part of this leaves the trail? Am I right about needing to create a frame buffer or some such buffer? 1 Quote Link to comment Share on other sites More sharing options...
Marcousik Posted January 12, 2022 Share Posted January 12, 2022 That crazy shader ? lol 1 Quote Link to comment Share on other sites More sharing options...
havenphillip Posted January 12, 2022 Author Share Posted January 12, 2022 Yep that thing. I can't isolate the principle. I'm racking my brain. Quote Link to comment Share on other sites More sharing options...
Josh Posted January 12, 2022 Share Posted January 12, 2022 You probably want to use render-to-texture to draw an image where the picked position is. This is how Leadwerks handles terrain editing. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Marcousik Posted January 12, 2022 Share Posted January 12, 2022 @havenphillipMaybe something like this.. It is not soo far away from mud, if you replace the smoke with mud-ground texture and make everything slower: https://www.shadertoy.com/view/WlVyRV Quote Link to comment Share on other sites More sharing options...
havenphillip Posted January 12, 2022 Author Share Posted January 12, 2022 That's a pretty sick shader but it has like 5 buffers. It's insane. The problem would still be how to do trails. I can draw a point at the player. But how to make it remember every point the player has been and draw that line? Sounds like Josh is saying use a render to texture - which makes me think of the minimap. Seems like maybe in script all I need is to bind a texture? I just need to start doing experiments. Quote Link to comment Share on other sites More sharing options...
Marcousik Posted January 12, 2022 Share Posted January 12, 2022 Yeah that's crazy, sure. I will try more experiments with decals but I don't expect to reach anything with movements like this mud (video) is moving under the force of the tires. I thought about using csgs too or adding sprites but still nothing really great. You did that veggies moving shader by going through, maybe it could generate such an illlusion, moving texture slowly apart, as mud has another physics.. I don't know just some confuse ideas.. Here I found others examples, with less buffers I don't know maybe could inspire https://www.shadertoy.com/view/4sKSzR https://www.shadertoy.com/view/4sXfDX Quote Link to comment Share on other sites More sharing options...
havenphillip Posted January 12, 2022 Author Share Posted January 12, 2022 The decals thing might work but you'd have to loan me the script. If so it would just be a matter of connecting the decals to a tesselation shader and figuring out some kind of tesselation lod. It would look cooler if it was drawing in height rather than on the diffuse, and it's possible you could randomize a few textures to get that mud up on the sides of the tires if a sprite sheet doesn't work. The veggies moving shader only records a small area around the player. It doesn't remember where the player has been - so no trails still. But if I could get trails that one could be useful, especially for improving that particular shader. 1 Quote Link to comment Share on other sites More sharing options...
Marcousik Posted January 12, 2022 Share Posted January 12, 2022 I don't understand what kind of script you need with the decals? I just use a script to put the decals - assigned with a tire track material - on the ground or terrain and align each decals to the spline the car takes in its movement, I don't have anything else as script. My idea about the "veggies moving shader" trails mud is that especially mud does not stay long on its form after a tire has been going through so it could take its original form back after the tire went through, at a speed depending on the tire speed? I don't know if it would work.. That's my problem with decals, they can give a great illusion of mud spread on a car but how do you want to give it the movements of mud waving slowly and going back down..? There is a last option they could have used in the video..maybe it is possible to create a surface with mud material and move it, as you want using the vertex coordinates. With this method it was easy to recreate little waves like water could do, so it could be possible to move a surface as mud would do? Quote Link to comment Share on other sites More sharing options...
havenphillip Posted January 13, 2022 Author Share Posted January 13, 2022 "There is a last option they could have used in the video..maybe it is possible to create a surface with mud material and move it, as you want using the vertex coordinates. With this method it was easy to recreate little waves like water could do, so it could be possible to move a surface as mud would do?" Yeah that's pretty much the idea. But I need to move the vertex according to the trails that are left in the wake of the tires. So the trails from the tires act as the heightmap. Getting the trails to "stay on the ground" is the trouble. If I can get that I can work out the rest of it. You posted a partial script for your trails recently: I think I would need that whole script - or some simplified version of it. From there I think I could work out a shader. I don't think it's the "proper" way, though, but it might work. I also don't know if I could get that working on terrain. On a model more likely. From what I understand the correct way to do it is to create a buffer and somehow mix the buffer and the color texture together so that the renderer saves the created trail path. 1 Quote Link to comment Share on other sites More sharing options...
Marcousik Posted January 13, 2022 Share Posted January 13, 2022 The whole script would be in this case the entire car script, means including a lot of non usable things for that. The decal are always staying there where you position them.. There just gone erased with a scripted time factor and you place new ones on the terrain each few seconds. So the question is for me: Could you work on a decal set on the terrain or model? Like that: - I have to say I tried to create a whole effect using normals... But it is nonsense, I mean, I didn't get anything usable 1 Quote Link to comment Share on other sites More sharing options...
Yue Posted January 13, 2022 Share Posted January 13, 2022 1 Quote Link to comment Share on other sites More sharing options...
havenphillip Posted January 13, 2022 Author Share Posted January 13, 2022 Ok I tried downloading a few cars and scripts. I cant get it working it's getting too complicated. Would it be easy for you to write a single track script in the 3rd person player script so that the player leaves one trail behind? I just need something simple. I think you understand this decal thing better. Quote Link to comment Share on other sites More sharing options...
Marcousik Posted January 14, 2022 Share Posted January 14, 2022 @Yue yeah they had this mud wonder simulation yet in games earlier than snowrunner. @havenphillip ok, please follow this steps, I added quickly the feature tire tracks to an old jeep script: 1) Open the workshop in engine and look at the jeep and please install it in a project 2) Replace the script on the jeep with this one: In the same folder .../scripts/objects/vehicules BuildCar46.lua 3) Add this Material in the decals assets: decals.zip 4) Start the map, drive the car, you need a FPSPlayer Leadwerks PLayer character. Okay the car script is olddated, but the car should be drivable enough to get the tire tracks on the ground lol You should get this: You can find the tire tracks script in the UpdateWolrd function of the car script (uploaded above.) Please tell if problems thx. 2 Quote Link to comment Share on other sites More sharing options...
havenphillip Posted January 14, 2022 Author Share Posted January 14, 2022 Ok awesome. Thanks. I got it working. Now what I need to do is find a way to set the height in the shader as the decals in the script. 2 Quote Link to comment Share on other sites More sharing options...
havenphillip Posted January 15, 2022 Author Share Posted January 15, 2022 bro I opened Leadwerks today the decals aren't working all of a sudden and there's no motor sound. Any idea what happened? Edit: nvm I had messed with the decal shader I fixed it. 1 Quote Link to comment Share on other sites More sharing options...
Marcousik Posted January 19, 2022 Share Posted January 19, 2022 So well I tried a lot things with vertex but it comes to no satisfying result because the vertex are not bound - so moving down a vertex positoin just made a hole in the mesh Then I tried moving csgs around the tires, with collision detection and I think - as I'm sure not going to make a snowrunner 2 (^^) - well it should be enough for my little game, until maybe Havenphillip finds something better with shadering... Here is the result of this: TEMP 2022-01-19 12-53-14.mp4 2 1 Quote Link to comment Share on other sites More sharing options...
Josh Posted January 19, 2022 Share Posted January 19, 2022 I know that is not the effect you were looking for, but that is pretty cool! In Ultra Engine, decals are drawn in the same forward rendering pass as the geometry, so it will be possible to use a decal to modify displacement of tessellated terrain. In Leadwerks, you probably need to modify the terrain height, and since the vertices aren't that close together, it's not going to make very detailed ruts. 2 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
havenphillip Posted January 19, 2022 Author Share Posted January 19, 2022 That looks pretty cool. Can you make them smaller, though? Can you manipulate the size and shape at all? This takes some pressure off me I wasn't getting anywhere. I need to try the buffer thing. 1 Quote Link to comment Share on other sites More sharing options...
Marcousik Posted January 19, 2022 Share Posted January 19, 2022 1 hour ago, havenphillip said: Can you make them smaller, though? Can you manipulate the size and shape at all? Yes size and shape can be changed as you want, but smaller, it will require to change the appearing rhythm or it will look a way less uniform (as mud should!) 1 hour ago, havenphillip said: This takes some pressure off me I wasn't getting anywhere. Please keep really cool.. nobody would never complain for becoming help, or whatever, and those things are really difficult, that must stay 100% hobby. 1 Quote Link to comment Share on other sites More sharing options...
Yue Posted January 19, 2022 Share Posted January 19, 2022 The result of this is that the mesh that deforms the ground must be of many triangles so that the effect is much more pleasing. But it is a good start. Quote 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.