Jump to content

Loading a material with a script


Recommended Posts

Alright so I looked around, and apparently it can't be done directly and I need to go through a shader loader first.

I put the following code together from rbray's work and nlight's work but it still doesn't work



public static Shader GetShader()
{
Assembly assembly = Assembly.GetExecutingAssembly();
StreamReader shaderStreamReader = new StreamReader(assembly.GetManifestResourceStream(KSPUtil.ApplicationRootPath+"/Sky.shader"));
String shaderTxt = shaderStreamReader.ReadToEnd();
return new Material(shaderTxt).shader;
}


I tried every filename and path combination and nothing seems to work. Any help would be appreciated at this point.

- - - Updated - - -

If anyone is interested in this, I got the shader to load with this code


public static Material GetMatFromShader2()
{
string codeBase = Assembly.GetExecutingAssembly().CodeBase;
UriBuilder uri = new UriBuilder(codeBase);
string path = Uri.UnescapeDataString(uri.Path);

StreamReader shaderStream = new StreamReader(new FileStream(Path.GetDirectoryName(path) + "\\" + "Sky.shader", FileMode.Open, FileAccess.Read));
string shaderContent = shaderStream.ReadToEnd();
return new Material (shaderContent);
}

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...