浏览代码

Added Texel Size Node (#1527)

* adding texel size node
* updated changelog
/main
Matt Dean 6 年前
当前提交
e5de9e5a
共有 5 个文件被更改,包括 75 次插入1 次删除
  1. 8
      com.unity.shadergraph/CHANGELOG.md
  2. 2
      com.unity.shadergraph/Editor/Data/Graphs/TextureShaderProperty.cs
  3. 3
      com.unity.shadergraph/.data/texel_size_node.PNG
  4. 52
      com.unity.shadergraph/Editor/Data/Nodes/Input/Texture/TexelSizeNode.cs
  5. 11
      com.unity.shadergraph/Editor/Data/Nodes/Input/Texture/TexelSizeNode.cs.meta

8
com.unity.shadergraph/CHANGELOG.md


This adds a new node for LOD functionality on a Texture 2D Sample. Sample Texture 2D LOD uses the exact same input and output slots as Sample Texture 2D, but also includes an input for level of detail adjustments via a Vector1 slot.
### Texel Size Node
![](.data/texel_size_node.png)
With this node, you can get the special texture properties of a Texture 2D Asset via the `{texturename}_TexelSize` variable. Based on input from the Texture 2D Asset, the node outputs the width and height of the texel size in Vector1 format.
**Note:** Do not use the default input to reference your texture Asset. It makes your graph perform worse. Connect this node to a separate Texture 2D Asset node per image example.
### Show generated code
![](.data/show_generated_code.gif)

2
com.unity.shadergraph/Editor/Data/Graphs/TextureShaderProperty.cs


public override string GetPropertyDeclarationString(string delimiter = ";")
{
return string.Format("TEXTURE2D({0}){1} SAMPLER(sampler{0}){1}", referenceName, delimiter);
return string.Format("TEXTURE2D({0}){1} SAMPLER(sampler{0}); float4 {0}_TexelSize{1}", referenceName, delimiter);
}
public override string GetPropertyAsArgumentString()

3
com.unity.shadergraph/.data/texel_size_node.PNG


version https://git-lfs.github.com/spec/v1
oid sha256:7502c3fdf5b201b4460a317b577d4e0490e500a6926ba35c53e236afa15ab76a
size 82906

52
com.unity.shadergraph/Editor/Data/Nodes/Input/Texture/TexelSizeNode.cs


using System.Linq;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Controls;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Texture", "Texel Size")]
public class Texture2DPropertiesNode : AbstractMaterialNode, IGeneratesBodyCode, IMayRequireMeshUV
{
public const int OutputSlotWId = 0;
public const int OutputSlotHId = 2;
public const int TextureInputId = 1;
const string kOutputSlotWName = "Width";
const string kOutputSlotHName = "Height";
const string kTextureInputName = "Texture";
public override bool hasPreview { get { return false; } }
public Texture2DPropertiesNode()
{
name = "Texel Size";
UpdateNodeAfterDeserialization();
}
public override string documentationURL
{
get { return "https://github.com/Unity-Technologies/ShaderGraph/wiki/Texel-Size-Node"; }
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Vector1MaterialSlot(OutputSlotWId, kOutputSlotWName, kOutputSlotWName, SlotType.Output, 0, ShaderStageCapability.Fragment));
AddSlot(new Vector1MaterialSlot(OutputSlotHId, kOutputSlotHName, kOutputSlotHName, SlotType.Output, 0, ShaderStageCapability.Fragment));
AddSlot(new Texture2DInputMaterialSlot(TextureInputId, kTextureInputName, kTextureInputName));
RemoveSlotsNameNotMatching(new[] { OutputSlotWId, OutputSlotHId, TextureInputId });
}
// Node generations
public virtual void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
visitor.AddShaderChunk(string.Format("{0}2 {1} = {2}_TexelSize.z;", precision, GetVariableNameForSlot(OutputSlotWId), GetSlotValue(TextureInputId, generationMode)), true);
visitor.AddShaderChunk(string.Format("{0}2 {1} = {2}_TexelSize.w;", precision, GetVariableNameForSlot(OutputSlotHId), GetSlotValue(TextureInputId, generationMode)), true);
}
public bool RequiresMeshUV(UVChannel channel, ShaderStageCapability stageCapability)
{
return true;
}
}
}

11
com.unity.shadergraph/Editor/Data/Nodes/Input/Texture/TexelSizeNode.cs.meta


fileFormatVersion: 2
guid: ab454fbbbc9f31d4083c178cf885c672
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存