Skip to content
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
15c6805
Add ST to texture params
Nov 4, 2020
c76e53b
Working with Universal / Texture2D (but not CFN yet)
Nov 9, 2020
464c730
CustomFunctionNode Texture2D working, allows full bare/non-bare selec…
Nov 10, 2020
6def478
Started on Cubemap/Array/3D
Nov 10, 2020
7564cec
Partial fixes fore 3d/array/cubemap
Nov 10, 2020
6d95d2b
Fix for texelSize node
Nov 10, 2020
a1acbb3
Texture2D nodes all working
Nov 10, 2020
5529870
Fixes for cubemap nodes, Texture2DArray nodes, Texture3d nodes
Nov 11, 2020
2f57ecb
Fix for HDRP
Nov 11, 2020
51cd85a
Fixes for GLES2
Nov 11, 2020
59fd40d
Fixes for NormalFromTextureNode, Texture2dAssetNode
Nov 11, 2020
32c4aed
Added SamplerState handling, cleaned up code to remove macro usage
Nov 12, 2020
c6a191f
Fix for ParallaxOcclusionMappingNode
Nov 12, 2020
857ffb5
Fix for NormalFromTextureNode, cleanup, adding changelog
Nov 12, 2020
9025101
Fix for old Texture2DArray and Texture3D inputs to CustomFunctionNodes
Nov 13, 2020
152ab5d
Fix for ParallaxMapping and Triplanar nodes handling of SamplerState …
Nov 13, 2020
1d1cbed
Cleanup, removing unused code and _ST values (for now)
Nov 13, 2020
4451e34
Fix samplerstates on SampleRawCubemap and SampleTexture2DLOD nodes
Nov 13, 2020
5028e08
Fix for VFX support, additional cleanup
Nov 13, 2020
1dcee04
Fix for decals
Nov 14, 2020
c7eb890
Fix for tests
Nov 16, 2020
3507116
Fix VFX path generation issues with textures
Nov 16, 2020
aa1db2d
Improved backwards compatibility, added graphics tests, addressing fe…
Nov 23, 2020
228c1f8
Merge branch '10.x.x/release' into 10.x.x/sg/fix/textures
Nov 23, 2020
796dc2d
Fix for GLES2 compilation
Nov 23, 2020
6452658
Fix for OpenGL Core
Nov 24, 2020
babacdd
Adding GLCore support for LOAD_TEXTURE3D and LOAD_TEXTURE3D_LOD
Nov 24, 2020
3347c9a
Fix for consoles
Nov 24, 2020
684e3bb
Disallow creating v0 of custom function node (which will upgrade inco…
Nov 25, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#ifndef UNITY_TEXTURE_INCLUDED
#define UNITY_TEXTURE_INCLUDED

#ifdef SHADER_API_GLES
#define SAMPLERDECL(n) GLES2UnsupportedSamplerState n;
#else
#define SAMPLERDECL(n) SAMPLER(n);
#endif

struct GLES2UnsupportedSamplerState
{
};

struct UnitySamplerState
{
SAMPLERDECL(samplerstate)
};

#ifdef SHADER_API_GLES
#define UnityBuildSamplerStateStruct(n) UnityBuildSamplerStateStructInternal()
#else
#define UnityBuildSamplerStateStruct(n) UnityBuildSamplerStateStructInternal(n)
#endif

UnitySamplerState UnityBuildSamplerStateStructInternal(SAMPLER(samplerstate))
{
UnitySamplerState result;
ASSIGN_SAMPLER(result.samplerstate, samplerstate);
return result;
}

struct UnityTexture2D
{
TEXTURE2D(tex);
SAMPLERDECL(samplerstate)
float4 texelSize;
float4 scaleTranslate;
};

#define UnityBuildTexture2DStruct(n) UnityBuildTexture2DStructInternal(TEXTURE2D_ARGS(n, sampler##n), n##_TexelSize, n##_ST)
#define UnityBuildTexture2DStructNoScale(n) UnityBuildTexture2DStructInternal(TEXTURE2D_ARGS(n, sampler##n), n##_TexelSize, float4(1, 1, 0, 0))
UnityTexture2D UnityBuildTexture2DStructInternal(TEXTURE2D_PARAM(tex, samplerstate), float4 texelSize, float4 scaleTranslate)
{
UnityTexture2D result;
result.tex = tex;
ASSIGN_SAMPLER(result.samplerstate, samplerstate);
result.texelSize = texelSize;
result.scaleTranslate = scaleTranslate;
return result;
}

struct UnityTexture2DArray
{
TEXTURE2D_ARRAY(tex);
SAMPLERDECL(samplerstate)
};

#define UnityBuildTexture2DArrayStruct(n) UnityBuildTexture2DArrayStructInternal(TEXTURE2D_ARRAY_ARGS(n, sampler##n))
UnityTexture2DArray UnityBuildTexture2DArrayStructInternal(TEXTURE2D_ARRAY_PARAM(tex, samplerstate))
{
UnityTexture2DArray result;
result.tex = tex;
ASSIGN_SAMPLER(result.samplerstate, samplerstate);
return result;
}


struct UnityTextureCube
{
TEXTURECUBE(tex);
SAMPLERDECL(samplerstate)
};

#define UnityBuildTextureCubeStruct(n) UnityBuildTextureCubeStructInternal(TEXTURECUBE_ARGS(n, sampler##n))
UnityTextureCube UnityBuildTextureCubeStructInternal(TEXTURECUBE_PARAM(tex, samplerstate))
{
UnityTextureCube result;
result.tex = tex;
ASSIGN_SAMPLER(result.samplerstate, samplerstate);
return result;
}


struct UnityTexture3D
{
TEXTURE3D(tex);
SAMPLERDECL(samplerstate)
};

#define UnityBuildTexture3DStruct(n) UnityBuildTexture3DStructInternal(TEXTURE3D_ARGS(n, sampler##n))
UnityTexture3D UnityBuildTexture3DStructInternal(TEXTURE3D_PARAM(tex, samplerstate))
{
UnityTexture3D result;
result.tex = tex;
ASSIGN_SAMPLER(result.samplerstate, samplerstate);
return result;
}

#undef SAMPLERDECL

#endif // UNITY_TEXTURE_INCLUDED
10 changes: 10 additions & 0 deletions com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Pass
$splice(GraphKeywords)

#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl"

// Defines
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Pass
$splice(GraphKeywords)

#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ ${VFXBegin:VFXPassVelocityAdditionalPragma}#pragma multi_compile _ WRITE_MSAA_DE

${VFXBegin:VFXShaderGraphFunctionsInclude}
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Packing.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/EntityLighting.hlsl"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,7 @@ static class CorePragmas
static class CoreIncludes
{
const string kColor = "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl";
const string kTexture = "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl";
const string kCore = "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl";
const string kLighting = "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl";
const string kGraphFunctions = "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl";
Expand All @@ -612,6 +613,7 @@ static class CoreIncludes
public static readonly IncludeCollection CorePregraph = new IncludeCollection
{
{ kColor, IncludeLocation.Pregraph },
{ kTexture, IncludeLocation.Pregraph },
{ kCore, IncludeLocation.Pregraph },
{ kLighting, IncludeLocation.Pregraph },
{ kTextureStack, IncludeLocation.Pregraph }, // TODO: put this on a conditional
Expand Down
11 changes: 11 additions & 0 deletions com.unity.shadergraph/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ All notable changes to this package are documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [10.3.0] - 2020-11-12

### Added

### Changed
- Texture and SamplerState types are now HLSL structures (defined in com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl). CustomFunctionNode use of the old plain types is supported, but the user should upgrade to structures to avoid bugs.

### Fixed
- Fixed using TexelSize or reading sampler states from Textures output from a Subgraph or Custom Function Node [1284036]
- Shaders using SamplerState types now compile with GLES2 (SamplerStates are ignored, falls back to Texture-associated sampler state) [1292031]

## [10.2.0] - 2020-10-19

### Added
Expand Down
1 change: 1 addition & 0 deletions com.unity.shadergraph/Editor/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
[assembly: InternalsVisibleTo("Unity.ShaderGraph.GraphicsTests")]
[assembly: InternalsVisibleTo("Unity.ShaderGraph.Editor.GraphicsTests")]
[assembly: InternalsVisibleTo("Unity.RenderPipelines.HighDefinition.Editor")]
[assembly: InternalsVisibleTo("Unity.VisualEffectGraph.Editor")]
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public bool gpuInstanced
set { }
}

internal virtual string GetHLSLVariableName(bool isSubgraphProperty)
{
return referenceName;
}

// NOTE: this does not tell you the HLSLDeclaration of the entire property...
// instead, it tells you what the DEFAULT HLSL Declaration would be, IF the property makes use of the default
// to check ACTUAL HLSL Declaration types, enumerate the HLSL Properties and check their HLSLDeclarations...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,21 @@ public override VisualElement InstantiateControl()

public override string GetDefaultValue(GenerationMode generationMode)
{
var matOwner = owner as AbstractMaterialNode;
if (matOwner == null)
var nodeOwner = owner as AbstractMaterialNode;
if (nodeOwner == null)
throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode)));

return matOwner.GetVariableNameForSlot(id);
return $"UnityBuildTextureCubeStruct({nodeOwner.GetVariableNameForSlot(id)})";
}

public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)
{
var matOwner = owner as AbstractMaterialNode;
if (matOwner == null)
var nodeOwner = owner as AbstractMaterialNode;
if (nodeOwner == null)
throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode)));

var prop = new CubemapShaderProperty();
prop.overrideReferenceName = matOwner.GetVariableNameForSlot(id);
prop.overrideReferenceName = nodeOwner.GetVariableNameForSlot(id);
prop.modifiable = false;
prop.generatePropertyBlock = true;
prop.value.cubemap = cubemap;
Expand All @@ -77,7 +77,10 @@ public override void CopyValuesFrom(MaterialSlot foundSlot)
{
var slot = foundSlot as CubemapInputMaterialSlot;
if (slot != null)
{
m_Cubemap = slot.m_Cubemap;
m_BareResource = slot.m_BareResource;
}
}
}
}
17 changes: 17 additions & 0 deletions com.unity.shadergraph/Editor/Data/Graphs/CubemapMaterialSlot.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using UnityEditor.Graphing;
using UnityEngine;

namespace UnityEditor.ShaderGraph
{
Expand All @@ -19,6 +20,22 @@ public CubemapMaterialSlot(
: base(slotId, displayName, shaderOutputName, slotType, stageCapability, hidden)
{}

[SerializeField]
internal bool m_BareResource = false;
internal override bool bareResource
{
get { return m_BareResource; }
set { m_BareResource = value; }
}

public override string GetHLSLVariableType()
{
if (m_BareResource)
return "TextureCube";
else
return concreteValueType.ToShaderString();
}

public override SlotValueType valueType { get { return SlotValueType.Cubemap; } }
public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.Cubemap; } }
public override bool isDefaultValue => true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,15 @@ internal override void ForeachHLSLProperty(Action<HLSLProperty> action)

internal override string GetPropertyAsArgumentString()
{
return $"TEXTURECUBE_PARAM({referenceName}, sampler{referenceName})";
return "UnityTextureCube " + referenceName;
}

internal override string GetHLSLVariableName(bool isSubgraphProperty)
{
if (isSubgraphProperty)
return referenceName;
else
return $"UnityBuildTextureCubeStruct({referenceName})";
}

[SerializeField]
Expand Down
9 changes: 9 additions & 0 deletions com.unity.shadergraph/Editor/Data/Graphs/MaterialSlot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,11 @@ public virtual void GetPreviewProperties(List<PreviewProperty> properties, strin
properties.Add(default(PreviewProperty));
}

public virtual string GetHLSLVariableType()
{
return concreteValueType.ToShaderString();
}

public abstract void CopyValuesFrom(MaterialSlot foundSlot);

public bool Equals(MaterialSlot other)
Expand All @@ -314,6 +319,10 @@ public override int GetHashCode()
}
}

// this tracks old CustomFunctionNode slots that are expecting the old bare resource inputs
// rather than the new structure-based inputs
internal virtual bool bareResource { get { return false; } set { } }

public virtual void CopyDefaultValue(MaterialSlot other)
{
m_Id = other.m_Id;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using UnityEditor.Graphing;
using UnityEngine;

namespace UnityEditor.ShaderGraph
{
Expand All @@ -21,13 +22,29 @@ public SamplerStateMaterialSlot(
{
}

[SerializeField]
internal bool m_BareResource = false;
internal override bool bareResource
{
get { return m_BareResource; }
set { m_BareResource = value; }
}

public override string GetHLSLVariableType()
{
if (m_BareResource)
return "SamplerState";
else
return concreteValueType.ToShaderString();
}

public override string GetDefaultValue(GenerationMode generationMode)
{
var matOwner = owner as AbstractMaterialNode;
if (matOwner == null)
var nodeOwner = owner as AbstractMaterialNode;
if (nodeOwner == null)
throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode)));

return $"{matOwner.GetVariableNameForSlot(id)}_Linear_Repeat";
return "UnityBuildSamplerStateStruct(SamplerState_Linear_Repeat)";
}

public override SlotValueType valueType { get { return SlotValueType.SamplerState; } }
Expand All @@ -36,8 +53,8 @@ public override string GetDefaultValue(GenerationMode generationMode)

public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)
{
var matOwner = owner as AbstractMaterialNode;
if (matOwner == null)
var nodeOwner = owner as AbstractMaterialNode;
if (nodeOwner == null)
throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode)));

properties.AddShaderProperty(new SamplerStateShaderProperty()
Expand All @@ -47,7 +64,7 @@ public override void AddDefaultProperty(PropertyCollector properties, Generation
filter = TextureSamplerState.FilterMode.Linear,
wrap = TextureSamplerState.WrapMode.Repeat
},
overrideReferenceName = $"{matOwner.GetVariableNameForSlot(id)}_Linear_Repeat",
overrideReferenceName = "SamplerState_Linear_Repeat",
generatePropertyBlock = false,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public override TextureSamplerState value
get => base.value;
set
{
overrideReferenceName = $"{concreteShaderValueType.ToShaderString()}_{value.filter}_{value.wrap}";
overrideReferenceName = $"SamplerState_{value.filter}_{value.wrap}";
base.value = value;
}
}
Expand All @@ -38,7 +38,15 @@ internal override void ForeachHLSLProperty(Action<HLSLProperty> action)

internal override string GetPropertyAsArgumentString()
{
return $"SamplerState {referenceName}";
return $"UnitySamplerState {referenceName}";
}

internal override string GetHLSLVariableName(bool isSubgraphProperty)
{
if (isSubgraphProperty)
return referenceName;
else
return $"UnityBuildSamplerStateStruct({referenceName})";
}

internal override AbstractMaterialNode ToConcreteNode()
Expand Down
Loading