move glsl file to resource file

This commit is contained in:
Perfare 2017-08-21 19:51:32 +08:00
parent 14bd7f9789
commit 9d87fead21
7 changed files with 313 additions and 65 deletions

120
Unity Studio/Resource1.Designer.cs generated Normal file
View File

@ -0,0 +1,120 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本:4.0.30319.42000
//
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
namespace Unity_Studio {
using System;
/// <summary>
/// 一个强类型的资源类,用于查找本地化的字符串等。
/// </summary>
// 此类是由 StronglyTypedResourceBuilder
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
// 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
// (以 /str 作为命令选项),或重新生成 VS 项目。
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resource1 {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resource1() {
}
/// <summary>
/// 返回此类使用的缓存的 ResourceManager 实例。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Unity_Studio.Resource1", typeof(Resource1).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// 使用此强类型资源类,为所有资源查找
/// 重写当前线程的 CurrentUICulture 属性。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// 查找类似 #version 140
///
///in vec3 surfaceNormal;
///in vec3 toLightVector;
///in vec4 color;
///
///out vec4 outputColor;
///
///void main()
///{
/// vec3 lightColor = vec3(0.5, 0.5, 0.5);
///
/// // Ambient
/// float ambientStrength = 0.9;
/// vec3 ambient = ambientStrength * lightColor;
///
/// // Diffuse
/// vec3 unitNormal = normalize(surfaceNormal);
/// vec3 unitLightVector = normalize(toLightVector);
/// float nDotProduct = dot(unitNormal, unitLightVector);
/// float brightness = clamp(nDotProduct, 0, 1); // max(nDotProduct, 0.0);
/// vec3 diffuse [字符串的其余部分被截断]&quot;; 的本地化字符串。
/// </summary>
internal static string fs {
get {
return ResourceManager.GetString("fs", resourceCulture);
}
}
/// <summary>
/// 查找类似 #version 140
///
///in vec3 vertexPosition;
///in vec3 normalDirection;
///in vec4 vertexColor;
///uniform mat4 viewMatrix;
///
///out vec3 surfaceNormal;
///out vec3 toLightVector;
///out vec4 color;
///
///void main()
///{
/// vec3 lightPosition = vec3(200.0, 200.0, 200.0);
/// gl_Position = viewMatrix * vec4(vertexPosition, 1.0);
/// surfaceNormal = normalDirection;
/// toLightVector = lightPosition - vertexPosition;
/// color = vertexColor;
///} 的本地化字符串。
/// </summary>
internal static string vs {
get {
return ResourceManager.GetString("vs", resourceCulture);
}
}
}
}

170
Unity Studio/Resource1.resx Normal file
View File

@ -0,0 +1,170 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="fs" xml:space="preserve">
<value>#version 140
in vec3 surfaceNormal;
in vec3 toLightVector;
in vec4 color;
out vec4 outputColor;
void main()
{
vec3 lightColor = vec3(0.5, 0.5, 0.5);
// Ambient
float ambientStrength = 0.9;
vec3 ambient = ambientStrength * lightColor;
// Diffuse
vec3 unitNormal = normalize(surfaceNormal);
vec3 unitLightVector = normalize(toLightVector);
float nDotProduct = dot(unitNormal, unitLightVector);
float brightness = clamp(nDotProduct, 0, 1); // max(nDotProduct, 0.0);
vec3 diffuse = brightness * lightColor;
// Output Color
vec4 result = color * vec4((ambient + diffuse/2), 0.0);
outputColor = result;
}</value>
</data>
<data name="vs" xml:space="preserve">
<value>#version 140
in vec3 vertexPosition;
in vec3 normalDirection;
in vec4 vertexColor;
uniform mat4 viewMatrix;
out vec3 surfaceNormal;
out vec3 toLightVector;
out vec4 color;
void main()
{
vec3 lightPosition = vec3(200.0, 200.0, 200.0);
gl_Position = viewMatrix * vec4(vertexPosition, 1.0);
surfaceNormal = normalDirection;
toLightVector = lightPosition - vertexPosition;
color = vertexColor;
}</value>
</data>
</root>

View File

@ -136,6 +136,11 @@
<Compile Include="AboutBox.Designer.cs">
<DependentUpon>AboutBox.cs</DependentUpon>
</Compile>
<Compile Include="Resource1.Designer.cs">
<DependentUpon>Resource1.resx</DependentUpon>
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
</Compile>
<Compile Include="Unity Classes\AssetBundle.cs" />
<Compile Include="Unity Studio Classes\AssetPreloadData.cs" />
<Compile Include="Unity Classes\AudioClip.cs" />
@ -198,14 +203,15 @@
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<EmbeddedResource Include="Resource1.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resource1.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Include="UnityStudioForm.resx">
<DependentUpon>UnityStudioForm.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<None Include="app.config" />
<None Include="fs.glsl">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
@ -215,9 +221,6 @@
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<None Include="vs.glsl">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.0,Profile=Client">

View File

@ -136,6 +136,11 @@
<Compile Include="AboutBox.Designer.cs">
<DependentUpon>AboutBox.cs</DependentUpon>
</Compile>
<Compile Include="Resource1.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resource1.resx</DependentUpon>
</Compile>
<Compile Include="Unity Classes\AssetBundle.cs" />
<Compile Include="Unity Studio Classes\AssetPreloadData.cs" />
<Compile Include="Unity Classes\AudioClip.cs" />
@ -198,14 +203,15 @@
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<EmbeddedResource Include="Resource1.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resource1.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Include="UnityStudioForm.resx">
<DependentUpon>UnityStudioForm.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<None Include="app.config" />
<None Include="fs.glsl">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
@ -215,9 +221,6 @@
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<None Include="vs.glsl">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.0,Profile=Client">

View File

@ -1712,8 +1712,8 @@ namespace Unity_Studio
GL.Viewport(0, 0, glControl1.ClientSize.Width, glControl1.ClientSize.Height);
GL.ClearColor(Color.CadetBlue);
pgmID = GL.CreateProgram();
loadShader("vs.glsl", ShaderType.VertexShader, pgmID, out vsID);
loadShader("fs.glsl", ShaderType.FragmentShader, pgmID, out fsID);
loadShader("vs", ShaderType.VertexShader, pgmID, out vsID);
loadShader("fs", ShaderType.FragmentShader, pgmID, out fsID);
GL.LinkProgram(pgmID);
GL.UseProgram(pgmID);
attributeVertexPosition = GL.GetAttribLocation(pgmID, "vertexPosition");
@ -1726,10 +1726,8 @@ namespace Unity_Studio
private void loadShader(string filename, ShaderType type, int program, out int address)
{
address = GL.CreateShader(type);
using (StreamReader sr = new StreamReader(filename))
{
GL.ShaderSource(address, sr.ReadToEnd());
}
var str = (string)Resource1.ResourceManager.GetObject(filename);
GL.ShaderSource(address, str);
GL.CompileShader(address);
GL.AttachShader(program, address);
GL.DeleteShader(address);

View File

@ -1,27 +0,0 @@
#version 140
in vec3 surfaceNormal;
in vec3 toLightVector;
in vec4 color;
out vec4 outputColor;
void main()
{
vec3 lightColor = vec3(0.5, 0.5, 0.5);
// Ambient
float ambientStrength = 0.9;
vec3 ambient = ambientStrength * lightColor;
// Diffuse
vec3 unitNormal = normalize(surfaceNormal);
vec3 unitLightVector = normalize(toLightVector);
float nDotProduct = dot(unitNormal, unitLightVector);
float brightness = clamp(nDotProduct, 0, 1); // max(nDotProduct, 0.0);
vec3 diffuse = brightness * lightColor;
// Output Color
vec4 result = color * vec4((ambient + diffuse/2), 0.0);
outputColor = result;
}

View File

@ -1,19 +0,0 @@
#version 140
in vec3 vertexPosition;
in vec3 normalDirection;
in vec4 vertexColor;
uniform mat4 viewMatrix;
out vec3 surfaceNormal;
out vec3 toLightVector;
out vec4 color;
void main()
{
vec3 lightPosition = vec3(200.0, 200.0, 200.0);
gl_Position = viewMatrix * vec4(vertexPosition, 1.0);
surfaceNormal = normalDirection;
toLightVector = lightPosition - vertexPosition;
color = vertexColor;
}