Skip to content

[ShaderGraph] [bugfix 1283782] Fix for previews when selecting "None" as your texture property texture #2182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions com.unity.shadergraph/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed an issue where ShaderGraph would not prompt the user to save unsaved changes after an assembly reload
- Fixed an issue with Position Node not automatically upgrading
- Fixed an issue where failing SubGraphs would block saving graph files using them (recursion check would throw exceptions) [1283425]
- Fixed an issue where choosing "None" as the default texture for a texture property would not correctly preview the correct default color [1283782]

## [10.0.0] - 2019-06-10
### Added
Expand Down
33 changes: 32 additions & 1 deletion com.unity.shadergraph/Editor/Data/Graphs/PreviewProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct StructData

ClassData m_ClassData;
StructData m_StructData;
Texture2DShaderProperty.DefaultType m_texture2dDefaultType;

public Color colorValue
{
Expand Down Expand Up @@ -79,6 +80,22 @@ public Texture textureValue
}
}

public Texture2DShaderProperty.DefaultType texture2DDefaultType
{
get
{
if (propType != PropertyType.Texture2D)
throw new ArgumentException(string.Format(k_GetErrorMessage, "Texture2DShaderProperty.DefaultType", propType));
return m_texture2dDefaultType;
}
set
{
if (propType != PropertyType.Texture2D)
throw new ArgumentException(string.Format(k_GetErrorMessage, "Texture2DShaderProperty.DefaultType", propType));
m_texture2dDefaultType = value;
}
}

public Cubemap cubemapValue
{
get
Expand Down Expand Up @@ -205,7 +222,21 @@ public void SetValueOnMaterialPropertyBlock(MaterialPropertyBlock mat)
// and no way to delete the property either
// so instead we set the value to what we know the default will be
// (all textures in ShaderGraph default to white)
mat.SetTexture(name, Texture2D.whiteTexture);
switch (m_texture2dDefaultType)
{
case Texture2DShaderProperty.DefaultType.White:
mat.SetTexture(name, Texture2D.whiteTexture);
break;
case Texture2DShaderProperty.DefaultType.Black:
mat.SetTexture(name, Texture2D.blackTexture);
break;
case Texture2DShaderProperty.DefaultType.Grey:
mat.SetTexture(name, Texture2D.grayTexture);
break;
case Texture2DShaderProperty.DefaultType.Bump:
mat.SetTexture(name, Texture2D.normalTexture);
break;
}
}
else
mat.SetTexture(name, m_ClassData.textureValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public override void GetPreviewProperties(List<PreviewProperty> properties, stri
{
name = name,
textureValue = texture,
texture2DDefaultType = defaultType
};
properties.Add(pp);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ internal override PreviewProperty GetPreviewMaterialProperty()
return new PreviewProperty(propertyType)
{
name = referenceName,
textureValue = value.texture
textureValue = value.texture,
texture2DDefaultType = defaultType
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public override void CollectPreviewMaterialProperties(List<PreviewProperty> prop
properties.Add(new PreviewProperty(PropertyType.Texture2D)
{
name = GetVariableNameForSlot(OutputSlotId),
textureValue = texture
textureValue = texture,
texture2DDefaultType = Texture2DShaderProperty.DefaultType.White
});
}

Expand Down