How to add .fsh/.vsh shader files to Xcode so they are added to Copy Bundle Resources phase automatically?

10,989

Solution 1

My workaround is that I go to File > New File > Others > Empty files and name them as shader.vertsh and shader.fragsh.

I guess Xcode automatically adds files with dot 3/4 extensions to compile phase.

And in case you're missing the Syntax Highlighting, change the File type to 'OpenGL Shading Language Source': Xcode change file type

Solution 2

Following is a workaround I found. If anyone has any other solutions I'd still appreciate the answer.

What you do to get the shaders into the Copy Bundle Resources build phase automatically is simply to put all the shaders in a common folder (or folder tree). I named the folder "Shaders". Then when adding the Shaders folder select Create folder references for any added folders.

As folder references the files are automatically assumed to be Bundle Resources by Xcode. You just need to be careful not to place any unwanted files into that folder respectively clean up the folder before making a release build. Also loading the shaders requires to use the path to the shader files, ie "Shaders/Examples/Blur.fsh".

Share:
10,989
LearnCocos2D
Author by

LearnCocos2D

Author of the Learn SpriteBuilder book published by Apress. Developer of OpenGW, a game world simulation engines / entity component system with Model-View-Controller architecture that can be used with any rendering engine. Developer of Kobold Kit, the Sprite Kit game engine with tilemap support, game components, scheduling and event dispatching, and all the other things missing from Sprite Kit. Developer of KoboldTouch (commercial) and Kobold2D (free), both game engines build on cocos2d-iphone. KoboldTouch adds MVC and component support and even improves cocos2d's own features, such as Tilemap rendering. Author of the Learn Cocos2D book series published by Apress. The latest edition "Learn cocos2d 2" uses cocos2d 2.0 with ARC enabled and also covers Kobold2D. Steffen's main website is Learn Cocos2D.

Updated on June 08, 2022

Comments

  • LearnCocos2D
    LearnCocos2D almost 2 years

    Whenever I add a new .fsh or .vsh OpenGL ES 2.0 shader file to my project's resources, the file is added to the Compile Sources build phase where it doesn't belong. I then have to manually remove it from that phase, and manually add it to the Copy Bundle Resources build phase.

    Is there any way I can tell Xcode to add files with the extension .fsh and .vsh automatically to the Copy Bundle Resources build phase?

    Or is it possible to create a Build Rule that has the same effect as adding the shaders to the Copy Bundle Resources build phase?

    I would prefer a solution that works for all users of the Xcode project/workspace, rather than a setting or system change each Xcode user would have to play individually.

  • jd.
    jd. about 12 years
    this did not work for me, and I wouldn't want to e.g. rename existing source files just for this case. I used the method of put-them-in-a-folder and add-to-project-via-folder-reference, mentioned by LearnCocos2D.
  • chunkyguy
    chunkyguy about 12 years
    @jd. Yes I too wouldn't care to rename all existing code, this workaround is only good if you're starting a new project, also I hope Apple fixes this issue as in their sample code they've used the .vsh and .fsh extensions and everybody would love to follow that, including me :)
  • aledalgrande
    aledalgrande almost 10 years
    Don't think this fix is necessary any more, on XCode 5.1.1 .vsh and .fsh files are automatically added to Copy Bundle Resources
  • chunkyguy
    chunkyguy almost 10 years
    @aledalgrande You're right. I'm quite surprised that Apple hasn't provided a template file for shaders yet.