Rick Posted March 26, 2013 Share Posted March 26, 2013 I can't attach any files for some reason as I did try to put this in the asset store under shaders and even on this post but it kept giving me an error: https://dl.dropbox.c...iled-Shader.rar INSTALL: Place the .shader files into your projects Shaders/Dynamic folder. It won't overwrite anything as they are new files. THANKS: MASSIVE thanks to shadmar for the offsetting code and talking things out with me, and niosp for his LE2 original shader that gave the idea of using the color (he used alpha as an index but I think this required a different shader for different number of sub textures per row which this method doesn't require) for doing this as the color seems to be unique per model instance which is what we need and the reason we use the color variable to get this effect. DESCRIPTION: I don't really know what to call this shader, but it allows you to combine multiple textures into 1 big texture, and then allow you to pick which texture from that you want to show on a given model instance. This is "needed" because models are by default instanced, and so changing material on 1 instance changes it on all instances. You can create unique copies, but doing so at run-time is slower than using instancing so for mobile this will give a big savings I think.To be able to have 1 model instance, but apply different textures to it, you use this shader, and then you use entity:SetColor(row, col, 1.0 / 4.0, 1) to get the subtexture you want to actually apply. entity:SetColor(row, col, 1.0 / 4.0, 1) explained: 1) Your big texture will have rows & cols made up of your sub textures (see screenshot below) 2) When calling SetColor() the first parameter is the row, and the second is the column, the 3rd is 1 / how many texture per row fit on your big texture, and the last parameter is ignored so just put 1 NEGATIVES: You lose the functionality of SetColor(). This means you can't tint your model a certain color using SetColor() when using this shader. I rarely use SetColor() on models myself so this probably isn't a massive limitation. RANT: Ideally, we would be able to define use variables of certain types, per model instance dynamically, that then get exposed to the shaders by the engine automatically. Not sure if that's possible, but it would allow for way more functionality and not hacking around using things like color for something else. Maybe even a couple holders for each type would help if doing this dynamically isn't possible. EXTRA: Note below I only did 3 textures and left the rest blank. I will have more for my game, but did this as just an example of what I mean. In my case I'm using this for completely different textures, but you could also give a progression of your character getting beat up with blood and ripped clothes or something cool like that. 4 Quote Link to comment Share on other sites More sharing options...
shadmar Posted March 26, 2013 Share Posted March 26, 2013 This is a win, and a new shader programmer is born Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
Pancakes Posted March 26, 2013 Share Posted March 26, 2013 awesome thanks Quote Core I5 2.67 / 16GB RAM / GTX 670 Zbrush/ Blender / Photoshop CS6 / Renoise / Genetica / Leadwerks 3 Link to comment Share on other sites More sharing options...
YouGroove Posted March 26, 2013 Share Posted March 26, 2013 Amazing. Could you put it on Asset-> scripts ? or shader ? Or it will be loosen on the tons of posts here. Quote Stop toying and make games Link to comment Share on other sites More sharing options...
Rick Posted March 26, 2013 Author Share Posted March 26, 2013 I tried, but the website was giving me errors when I tried to attach anything. Will try again tomorrow maybe. Quote Link to comment Share on other sites More sharing options...
Daimour Posted April 2, 2013 Share Posted April 2, 2013 Brilliant solution! Quote Link to comment Share on other sites More sharing options...
Josh Posted April 2, 2013 Share Posted April 2, 2013 FYI, you can also load different instances of the model and use a different material on each. See the Asset class for the constants to pass to the load function. But your solution is really good. 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...
neseir Posted April 8, 2013 Share Posted April 8, 2013 Thanks for sharing ! This was right on the spot what I needed for a smal project I'm working on. BR Eirik 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.