Effects. How to reference a second texture

0 favourites
  • 15 posts
From the Asset Store
This is a Dungeon Master tool & the 1st of 12 Combat Engines from the Building Combat Engines for Browser Games workshop
  • Hey everybody,

    This has been bothering me for a week now. Does anyone know if you can reference another texture besides samplerfront and samplerback?

    I want to make a dirty lens bloom and a color lookup filter. Both require a second texture.

    I've looked around the javascript files that you can access and didn't find anything that was in communication with the fragshader.

    If there is no way to do this then I think this is a major missing feature. But I could have missed it. Given the level of shader development with c2 I could see the majority would care none at all though.

  • Ruskul

    'This has been bothering me for a week now. Does anyone know if you can reference another texture besides samplerfront and samplerback?

    I want to make a dirty lens bloom and a color lookup filter. Both require a second texture.'

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

    Use a 'color lookup filter' as your 'samplerback' or 'samplerfront'.

    Or introduce a color gradient as a vec4.

  • "samplerfront" and "samplerback" are the only two that C2 sets up for you.

    You could use a sprite as a second texture. Put it at the top and give it your effect then samplerfront would be your lookup and samplerback would be everything drawn so far.

    In cases where you want to do everything webgl allows you to do with a shader you'll have to write your own plugin. specifically in the drawgl function. You can look at the creature2d plugin I started for an example of using custom webgl outside of what C2's renderer provides. Basically you use the endBatch() function then do anything you want. Only be sure to set the webgl state back to the state it was before your custom code. It'll probably need some trial and error and you'll need to dig around the source a bit but the end result could be cool.

  • chrisbrobs - I don't understand, how would those work in replacement of a second texture? By color lookup filter I meant that you generate an rgb color space of your own choosing... either using photoshop or other programs, You save it as a texture then you then reference the texture using the rgb values from sampler front as coordinates for the color space you created. Does this make sense?

    Basically, I want to introduce a second texture in the asset pipeline that I can access via the shader. To be honest I could use two or three... lol. It just dawned on me. I need to check the bump lighting effect... but I thought even it required the use of two sprites lined up where the effect was applied to the second and it read samplerback to get the color values or vica verca.

  • R0J0hound - that makes sense. I'll have to check that out. I might have to mess with the way you said to do it... The problem that I can see though is that you couldn't apply it to a layer or layout, which is suboptimal, but hey it may work. It just seems like Construct 2 should have a place to put textures, that you could feed to your shaders.

  • To make it work on the entire layout you could put the sprite on a top layer that doesn't scroll or scale and make the sprite cover the screen. To effect just a layer could be a bit trickier, worst case the sprite would be on that layer and you'd need to do the math so it covers the screen.

  • Ruskul

    When you say 'color lookup filter', is it the same as the 'ramp' texture that cocos 2d uses.

  • chrisbrobs hm - I'm not sure. Imagine laying out an rgb color space onto a 2d texture. it could represent 255*255*255 colors or 2*2*2. It really doesn't matter. Obviously the color space and the texture size go hand in hand.

    In the original image you then use the rgb value to essentially get texture coordinates for the look up table/ texture. Red = x, green = y, x+= blue * 255. In this case the lookup table is a very wide image where blocks of red and green have been laid out with increasing blue value. Does that make sense? The lookup table can then be altered anyway you like. You could make it super small and force a limited palette, you could use photshop to alter the levels and so on. The advantage is that you can have mathematically complex color conversions, arbitrary filters, etc, all at a low cost. The downside is that you have to create the lookup tables ahead of time.

    The end result is that you can get an incredible amount of diversity of assets without creating that many assets. It also makes it possible in 3d games to have a general lighting scheme and then use lookup filters to drastically alter the mood of the scene. It has some great uses. Essentially you could even use it as a shade, tint, etc tool. Or hsv. But it works more efficiently than actually mathematically calculating/converting from rgb -> hsv -> change values ->rgb. This is most pronounced when doing lab space color corrections.

    If none of this makes sense, check out this link. It is for Unity's color lookup, but the same principle can be applied to c2!

    http://docs.unity3d.com/Manual/script-C ... ookup.html

    As is mentioned and worth noting again is the fact that you can use photoshop to generate the color transforms. Basically you could take a scene from the game and apply filters/levels/etc until you like the way it looks. You then do the same thing to the lookup texture. and poof! quality color correction <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile"> and at a very low cost.

  • Ruskul

    I posted an example in the effects forum, Its not 100% finished, but it's no good stuck on my hard drive!.

  • chrisbrobs - thanks, I'll check it out when I get a chance!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • chrisbrobs - blast! I forgot about this conversation. I had to drop tinkering with the graphics card to do other things .

    I just spent the last day and a half figuring out how to do this through trial and error (moslty cause I still know nothing of shaders - I'm like "Hey this should work, the math checks out!" but nope. >.< Well then, thanks for the effort!

  • R0J0hound - So I checked out your creature plugin, now as I understand it, its not much different than the sprite pluggin in a way right (as far as drawing and textures go)... but I'm confused, because I thought you can't change the editor which would be required for attaching multiple images right?

    I mean, is it possible to actually pass another texture to the shaders in c2? (like so that I could have samplerback, samplerfront, samplercustom1, sampler custom2) does this make sense?

    And you would have to somehow be able to attach that image in the editor eh?

  • Ruskul

    I just saw your post here after replying in that other topic.

    Picking multiple textures to use to can be done in events easily. In my paster object the "draw textured quad" action just grabs the texture form some other object you specify. The same thing could be done in this case.

    Also to be clear you'd have to run the shader through the plugin instead of using C2's effects. Previewing in the editor wouldn't be possible in C2.

  • R0J0hound - so basically one would have to have a plugin that only does an effect then? (ie for each shader you wanted to make you would have create a plugin for that effect? This is probably way over my head. I think I understand.? This is probably going to take more work than I originally thought at the beginning. I'm trying to decide if its worth it.

    I think I like the world of physics engines... you just have to know math... but this architecture stuff frustrates me for some reason.

  • Ruskul

    Ideally you'd just make one plugin. A simplish design would be the make it an object you can put on the layout with zorder. That would mark where the effect would be applied. The plugin by default wouldn't have a effect loaded so it would do nothing when it draws. You'd load an effect as some text with an action which would compile the effect so it can be used. Then you'd need an action to set texture parameters and number parameters. That would give you a way to do full screen effects. Not terribly hard, just need an evening of motivation to put it together.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)