-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
177 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
// This file is part of the Prowl Game Engine | ||
// Licensed under the MIT License. See the LICENSE file in the project root for details. | ||
using System; | ||
|
||
using Vortice.Direct3D11; | ||
|
||
namespace Prowl.Runtime; | ||
|
||
|
||
public enum ShaderPropertyType | ||
{ | ||
Float, | ||
Vector2, | ||
Vector3, | ||
Vector4, | ||
Color, | ||
Matrix, | ||
Texture2D, | ||
Texture3D | ||
} | ||
|
||
|
||
public struct ShaderProperty | ||
{ | ||
public string Name; | ||
public string DisplayName; | ||
|
||
[field: SerializeField] | ||
public ShaderPropertyType PropertyType { get; private set; } | ||
|
||
public Vector4 Value; | ||
public Matrix4x4 MatrixValue; | ||
|
||
public AssetRef<Texture2D> Texture2DValue; | ||
public AssetRef<Texture3D> Texture3DValue; | ||
|
||
|
||
public void Set(ShaderProperty other) | ||
{ | ||
if (other.PropertyType != PropertyType) | ||
return; | ||
|
||
Value = other.Value; | ||
MatrixValue = other.MatrixValue; | ||
Texture2DValue = other.Texture2DValue; | ||
Texture3DValue = other.Texture3DValue; | ||
} | ||
|
||
public ShaderProperty(double value) | ||
{ | ||
Value = new(value); | ||
PropertyType = ShaderPropertyType.Float; | ||
} | ||
|
||
public static implicit operator ShaderProperty(double value) | ||
=> new ShaderProperty(value); | ||
|
||
public static implicit operator double(ShaderProperty value) | ||
=> value.Value.x; | ||
|
||
public ShaderProperty(Vector2 value) | ||
{ | ||
Value = new(value); | ||
PropertyType = ShaderPropertyType.Vector2; | ||
} | ||
|
||
public static implicit operator ShaderProperty(Vector2 value) | ||
=> new ShaderProperty(value); | ||
|
||
public static implicit operator Vector2(ShaderProperty value) | ||
=> new Vector2(value.Value.x, value.Value.y); | ||
|
||
public ShaderProperty(Vector3 value) | ||
{ | ||
Value = new(value); | ||
PropertyType = ShaderPropertyType.Vector3; | ||
} | ||
|
||
public static implicit operator ShaderProperty(Vector3 value) | ||
=> new ShaderProperty(value); | ||
|
||
public static implicit operator Vector3(ShaderProperty value) | ||
=> new Vector3(value.Value.x, value.Value.y, value.Value.z); | ||
|
||
public ShaderProperty(Vector4 value) | ||
{ | ||
Value = value; | ||
PropertyType = ShaderPropertyType.Vector4; | ||
} | ||
|
||
public static implicit operator ShaderProperty(Vector4 value) | ||
=> new ShaderProperty(value); | ||
|
||
public static implicit operator Vector4(ShaderProperty value) | ||
=> value.Value; | ||
|
||
public ShaderProperty(Color value) | ||
{ | ||
Value = new(value.r, value.g, value.b, value.a); | ||
PropertyType = ShaderPropertyType.Color; | ||
} | ||
|
||
public static implicit operator ShaderProperty(Color value) | ||
=> new ShaderProperty(value); | ||
|
||
public static implicit operator Color(ShaderProperty value) | ||
=> new Color((float)value.Value.x, (float)value.Value.y, (float)value.Value.z, (float)value.Value.w); | ||
|
||
public ShaderProperty(Matrix4x4 value) | ||
{ | ||
MatrixValue = value; | ||
PropertyType = ShaderPropertyType.Matrix; | ||
} | ||
|
||
public static implicit operator ShaderProperty(Matrix4x4 value) | ||
=> new ShaderProperty(value); | ||
|
||
public static implicit operator Matrix4x4(ShaderProperty value) | ||
=> value.MatrixValue; | ||
|
||
public ShaderProperty(AssetRef<Texture2D> value) | ||
{ | ||
Texture2DValue = value; | ||
PropertyType = ShaderPropertyType.Texture2D; | ||
} | ||
|
||
public static implicit operator ShaderProperty(AssetRef<Texture2D> value) | ||
=> new ShaderProperty(value); | ||
|
||
public static implicit operator AssetRef<Texture2D>(ShaderProperty value) | ||
=> value.Texture2DValue; | ||
|
||
public ShaderProperty(AssetRef<Texture3D> value) | ||
{ | ||
Texture3DValue = value; | ||
PropertyType = ShaderPropertyType.Texture3D; | ||
} | ||
|
||
public static implicit operator ShaderProperty(AssetRef<Texture3D> value) | ||
=> new ShaderProperty(value); | ||
|
||
public static implicit operator AssetRef<Texture3D>(ShaderProperty value) | ||
=> value.Texture3DValue; | ||
} |