Author Topic: shader forge?  (Read 8567 times)

ltethe

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
shader forge?
« on: June 02, 2014, 07:04:25 PM »
Has anyone successfully utilized shader forge and ngui together? They appeared to work together in the game view, but ngui won't pick up the shader forge shaders when I do a build, was wondering what other's mileage has been.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: shader forge?
« Reply #1 on: June 03, 2014, 07:19:37 AM »
I have.

You have to use UITextures for it, so you can give a custom material that uses that shader. Setting up and atlas to do it is potentially a much bigger headache. You also might have a bad time trying to get the texture to clip with a UIPanel.

ltethe

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: shader forge?
« Reply #2 on: June 03, 2014, 11:15:15 AM »
Can't you define a custom shader in the material slot of the Atlas? I slotted it in, and it appears to work great in the game view, but disappears completely when I did a build. Are custom shaders just a bad idea for atlases?


Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: shader forge?
« Reply #3 on: June 03, 2014, 04:55:48 PM »
Well.. I won't say you just can't, because it's possible, but you won't be able to do all the things you otherwise can with atlases necessarily, and you might get unexpected behavior since it already relies on certain things (UV mapping, for instance). I'm sure arenmook can give you some better help than I can, since I'm by no means a shader expert.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: shader forge?
« Reply #4 on: June 04, 2014, 01:28:43 AM »
Shaders must be either referenced, or be present in the Resources folder in order to be included. In a typical situation you will have materials on objects referencing shaders, and this will cause those shaders to be included in a build. I'm not familiar with what's different about how Shader Forge approaches this, but if you have an atlas material referencing some shader, then that shader should get included just fine. You can always test it by creating a material using this shader and placing a cube in the scene that uses it.

ltethe

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: shader forge?
« Reply #5 on: June 04, 2014, 02:03:29 PM »
The shaders work great. I use quite a few shader forge shaders in the scene. Even my custom atlas works fine on a cube placed in the scene. I dumped my custom atlas material into the resources directory as per your suggestion, but to no avail.

Everything works well until I do a build, then the custom atlas on the NGUI sprite disappears. The same custom atlas material placed on the cube remains.

Shader forge code is pretty standard stuff except with a wrapper so the Shader forge gui can interface with it appropriately.

Your hunch with the resource directory sounds quite reasonable to me, but no luck so far.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: shader forge?
« Reply #6 on: June 05, 2014, 12:28:20 AM »
Well, NGUI can actually replace the original material shader with a different version. Check inside UIDrawCall's CreateMaterial() function (line 245 of UIDrawCall.cs). My guess is that it's trying to find this shader of yours by name and fails. You can try adding this line after line 284 (else shader = Shader.Find(shaderName) line)
  1. if (shader == null && mMaterial != null) shader = mMaterial.shader;

ltethe

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: shader forge?
« Reply #7 on: June 05, 2014, 12:48:35 PM »
Thanks for the lead, but the code snippet doesn't change anything.

Really puzzling. The same atlas works perfectly fine if applied to a NGUI texture, but not so much if applied to a NGUI sprite.

I don't know if this is related, but the console spits out the following error:

"Shader wants normals, but the mesh frostyAtlasMat doesn't have them."

frostyAtlasMat is a material though. Where does a mesh come into this?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: shader forge?
« Reply #8 on: June 06, 2014, 02:11:44 AM »
Ah, so your shader is bump-mapped. To make it work, select the UIPanel and check "Normals".

Also note that if you happen to have multiple textures, then you're likely going to be out of luck unless you modify the shader to make it use the first texture's UVs everywhere instead of UVs of other textures.

ltethe

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: shader forge?
« Reply #9 on: June 06, 2014, 02:11:46 PM »
Ah, yes, that makes that error go away.

I went back to basics, tried to put a simple diffuse shader (no texture maps, nothing but a color node plugged into diffuse) from shader forge as the material for the shaderAtlas. No go at build.

I've been hacking at the code trying to strip the shader forge code down to see what makes it unhappy, no luck so far, quite a bit more sophisticated shader declaration to create a simple diffuse then what I'm used to.