浏览代码

Fixing Height to Normal

/main
Eduardo Chaves 7 年前
当前提交
2cc38eba
共有 6 个文件被更改,包括 107 次插入117 次删除
  1. 2
      MaterialGraphProject/Assets/Eduardo/EduardoTestGraph.ShaderGraph
  2. 24
      MaterialGraphProject/Assets/Eduardo/HeightToNormalNode.cs
  3. 8
      MaterialGraphProject/Assets/Florent/GeneratedTexture.meta
  4. 182
      MaterialGraphProject/Assets/GeneratedShader.shader
  5. 2
      MaterialGraphProject/Assets/NewNodes/WIP/POMNode.cs
  6. 6
      MaterialGraphProject/Assets/POM_Graph.ShaderGraph.meta

2
MaterialGraphProject/Assets/Eduardo/EduardoTestGraph.ShaderGraph
文件差异内容过多而无法显示
查看文件

24
MaterialGraphProject/Assets/Eduardo/HeightToNormalNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("Utility/Heightmap To Normalmap")]
public class HeightToNormalNode : FunctionNInNOut, IGeneratesFunction
public class HeightToNormalNode : FunctionNInNOut, IGeneratesFunction, IGenerateProperties
{
public HeightToNormalNode()

get { return true; }
}
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
base.GeneratePropertyUsages(visitor, generationMode);
visitor.AddShaderChunk("#ifdef UNITY_COMPILER_HLSL", false);
visitor.AddShaderChunk("SamplerState my_linear_repeat_sampler;", false);
visitor.AddShaderChunk("#endif", false);
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
{
var outputString = new ShaderGenerator();

outputString.AddShaderChunk("float2 offsetV = float2(texCoord.x, texCoord.y + texOffset);", false);
outputString.AddShaderChunk("float normalSample = heightmap.Sample(my_linear_repeat_sampler, texCoord).r;", false);
outputString.AddShaderChunk("float uSample = heightmap.Sample(my_linear_repeat_sampler, offsetU).r;", false);
outputString.AddShaderChunk("float vSample = heightmap.Sample(my_linear_repeat_sampler, offsetV).r;", false);
outputString.AddShaderChunk("float normalSample = 0;", false);
outputString.AddShaderChunk("float uSample = 0;", false);
outputString.AddShaderChunk("float vSample = 0;", false);
visitor.AddShaderChunk("#ifdef UNITY_COMPILER_HLSL", false);
outputString.AddShaderChunk("normalSample = heightmap.Sample(my_linear_repeat_sampler, texCoord).r;", false);
outputString.AddShaderChunk("uSample = heightmap.Sample(my_linear_repeat_sampler, offsetU).r;", false);
outputString.AddShaderChunk("vSample = heightmap.Sample(my_linear_repeat_sampler, offsetV).r;", false);
visitor.AddShaderChunk("#endif", false);
outputString.AddShaderChunk("float uMinusNormal = uSample - normalSample;", false);
outputString.AddShaderChunk("float vMinusNormal = vSample - normalSample;", false);

8
MaterialGraphProject/Assets/Florent/GeneratedTexture.meta


fileFormatVersion: 2
folderAsset: yes
timeCreated: 1495654193
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

182
MaterialGraphProject/Assets/GeneratedShader.shader


Shader "Generated.ExportTextureMasterNode3bf8de92-956b-458c-bbd4-470b91d6bd57"
Shader "Graph/Generated.MetallicMasterNode554b91b5-7a00-4f5f-b71a-f7729fcbdee8"
[NonModifiableTextureData] TextureAsset_a266f89a_2f3e_47a6_a8c0_5f05a62b6679_Uniform("TextureAsset", 2D) = "white" {}
[NonModifiableTextureData] TextureAsset_8f4a8771_6c8f_4107_9c0b_83da34d57a9b_Uniform("TextureAsset", 2D) = "white" {}
SubShader
{
Tags { "Queue"="Geometry" "IgnoreProjector"="True" "RenderType"="Opaque" }
SubShader
{
Tags
{
"RenderType"="Opaque"
"Queue"="Geometry"
}
ZWrite Off
Pass
{
CGPROGRAM
#include "UnityCustomRenderTexture.cginc"
#pragma vertex CustomRenderTextureVertexShader_Preview
#pragma fragment frag
#pragma target 4.0
v2f_customrendertexture CustomRenderTextureVertexShader_Preview(appdata_base IN)
{
v2f_customrendertexture OUT;
OUT.vertex = UnityObjectToClipPos(IN.vertex);
OUT.primitiveID = 0;//TODO
OUT.localTexcoord = IN.texcoord;
OUT.globalTexcoord = IN.texcoord;
OUT.direction = CustomRenderTextureComputeCubeDirection(OUT.globalTexcoord.xy);
return OUT;
}
sampler2D TextureAsset_a266f89a_2f3e_47a6_a8c0_5f05a62b6679_Uniform;
float4 TextureAsset_a266f89a_2f3e_47a6_a8c0_5f05a62b6679_Uniform_TexelSize;
float4 convolutionFilter0_da4b8ee3_365e_467c_8166_39db9bd7c370;
float4 convolutionFilter1_da4b8ee3_365e_467c_8166_39db9bd7c370;
float4 convolutionFilter2_da4b8ee3_365e_467c_8166_39db9bd7c370;
float4 convolutionFilter3_da4b8ee3_365e_467c_8166_39db9bd7c370;
float4 convolutionFilter4_da4b8ee3_365e_467c_8166_39db9bd7c370;
float4 convolutionFilter5_da4b8ee3_365e_467c_8166_39db9bd7c370;
float4 convolutionFilter6_da4b8ee3_365e_467c_8166_39db9bd7c370;
Cull Back
ZTest LEqual
inline float4 unity_convolution_float (sampler2D textSampler, float2 baseUv, float4 weights0,float4 weights1,float4 weights2,float4 weights3,float4 weights4,float4 weights5,float4 weights6, float2 texelSize)
{
fixed4 fetches = fixed4(0,0,0,0);
fixed weight = 1;
weight = weights0.x;
fetches += weight * tex2D(textSampler, baseUv + texelSize * fixed2(-2,-2));
weight = weights0.y;
fetches += weight * tex2D(textSampler, baseUv + texelSize * fixed2(-1,-2));
weight = weights0.z;
fetches += weight * tex2D(textSampler, baseUv + texelSize * fixed2(0,-2));
weight = weights0.w;
fetches += weight * tex2D(textSampler, baseUv + texelSize * fixed2(1,-2));
weight = weights1.x;
fetches += weight * tex2D(textSampler, baseUv + texelSize * fixed2(2,-2));
weight = weights1.y;
fetches += weight * tex2D(textSampler, baseUv + texelSize * fixed2(-2,-1));
weight = weights1.z;
fetches += weight * tex2D(textSampler, baseUv + texelSize * fixed2(-1,-1));
weight = weights1.w;
fetches += weight * tex2D(textSampler, baseUv + texelSize * fixed2(0,-1));
weight = weights2.x;
fetches += weight * tex2D(textSampler, baseUv + texelSize * fixed2(1,-1));
weight = weights2.y;
fetches += weight * tex2D(textSampler, baseUv + texelSize * fixed2(2,-1));
weight = weights2.z;
fetches += weight * tex2D(textSampler, baseUv + texelSize * fixed2(-2,0));
weight = weights2.w;
fetches += weight * tex2D(textSampler, baseUv + texelSize * fixed2(-1,0));
weight = weights3.x;
fetches += weight * tex2D(textSampler, baseUv + texelSize * fixed2(0,0));
weight = weights3.y;
fetches += weight * tex2D(textSampler, baseUv + texelSize * fixed2(1,0));
weight = weights3.z;
fetches += weight * tex2D(textSampler, baseUv + texelSize * fixed2(2,0));
weight = weights3.w;
fetches += weight * tex2D(textSampler, baseUv + texelSize * fixed2(-2,1));
weight = weights4.x;
fetches += weight * tex2D(textSampler, baseUv + texelSize * fixed2(-1,1));
weight = weights4.y;
fetches += weight * tex2D(textSampler, baseUv + texelSize * fixed2(0,1));
weight = weights4.z;
fetches += weight * tex2D(textSampler, baseUv + texelSize * fixed2(1,1));
weight = weights4.w;
fetches += weight * tex2D(textSampler, baseUv + texelSize * fixed2(2,1));
weight = weights5.x;
fetches += weight * tex2D(textSampler, baseUv + texelSize * fixed2(-2,2));
weight = weights5.y;
fetches += weight * tex2D(textSampler, baseUv + texelSize * fixed2(-1,2));
weight = weights5.z;
fetches += weight * tex2D(textSampler, baseUv + texelSize * fixed2(0,2));
weight = weights5.w;
fetches += weight * tex2D(textSampler, baseUv + texelSize * fixed2(1,2));
weight = weights6.x;
fetches += weight * tex2D(textSampler, baseUv + texelSize * fixed2(2,2));
fetches /= weights6.w;
return fetches;
}
ZWrite On
float4 frag(v2f_customrendertexture IN) : COLOR
{
half4 uv0 = float4(IN.localTexcoord.xyz,1.0);
float4 Convolution_da4b8ee3_365e_467c_8166_39db9bd7c370_Output = unity_convolution_float (TextureAsset_a266f89a_2f3e_47a6_a8c0_5f05a62b6679_Uniform, uv0.xy, convolutionFilter0_da4b8ee3_365e_467c_8166_39db9bd7c370, convolutionFilter1_da4b8ee3_365e_467c_8166_39db9bd7c370, convolutionFilter2_da4b8ee3_365e_467c_8166_39db9bd7c370, convolutionFilter3_da4b8ee3_365e_467c_8166_39db9bd7c370, convolutionFilter4_da4b8ee3_365e_467c_8166_39db9bd7c370, convolutionFilter5_da4b8ee3_365e_467c_8166_39db9bd7c370, convolutionFilter6_da4b8ee3_365e_467c_8166_39db9bd7c370, TextureAsset_a266f89a_2f3e_47a6_a8c0_5f05a62b6679_Uniform_TexelSize.xy);
return Convolution_da4b8ee3_365e_467c_8166_39db9bd7c370_Output;
LOD 200
CGPROGRAM
#pragma target 3.0
#pragma surface surf Standard vertex:vert
#pragma glsl
#pragma debug
}
ENDCG
#ifdef UNITY_COMPILER_HLSL
Texture2D TextureAsset_8f4a8771_6c8f_4107_9c0b_83da34d57a9b_Uniform;
#endif
float HeightToNormal_81cdd9a9_500d_41e2_9771_df274a2363bd_texOffset;
float HeightToNormal_81cdd9a9_500d_41e2_9771_df274a2363bd_strength;
#ifdef UNITY_COMPILER_HLSL
SamplerState my_linear_repeat_sampler;
#endif
#ifdef UNITY_COMPILER_HLSL
#endif
inline void unity_HeightToNormal (Texture2D heightmap, float2 texCoord, float texOffset, float strength, out float3 normalRes)
{
float2 offsetU = float2(texCoord.x + texOffset, texCoord.y);
float2 offsetV = float2(texCoord.x, texCoord.y + texOffset);
float normalSample = 0;
float uSample = 0;
float vSample = 0;
normalSample = heightmap.Sample(my_linear_repeat_sampler, texCoord).r;
uSample = heightmap.Sample(my_linear_repeat_sampler, offsetU).r;
vSample = heightmap.Sample(my_linear_repeat_sampler, offsetV).r;
float uMinusNormal = uSample - normalSample;
float vMinusNormal = vSample - normalSample;
uMinusNormal = uMinusNormal * strength;
vMinusNormal = vMinusNormal * strength;
float3 va = float3(1, 0, uMinusNormal);
float3 vb = float3(0, 1, vMinusNormal);
normalRes = cross(va, vb);
struct Input
{
float4 color : COLOR;
half4 meshUV0;
};
void vert (inout appdata_full v, out Input o)
{
UNITY_INITIALIZE_OUTPUT(Input,o);
o.meshUV0 = v.texcoord;
Fallback Off
}
void surf (Input IN, inout SurfaceOutputStandard o)
{
half4 uv0 = IN.meshUV0;
float4 UV_de8d7b89_7b50_499d_aa73_0f2a725356e6_UV = uv0;
float3 HeightToNormal_81cdd9a9_500d_41e2_9771_df274a2363bd_normalRes;
#ifdef UNITY_COMPILER_HLSL
unity_HeightToNormal (TextureAsset_8f4a8771_6c8f_4107_9c0b_83da34d57a9b_Uniform, UV_de8d7b89_7b50_499d_aa73_0f2a725356e6_UV, HeightToNormal_81cdd9a9_500d_41e2_9771_df274a2363bd_texOffset, HeightToNormal_81cdd9a9_500d_41e2_9771_df274a2363bd_strength, HeightToNormal_81cdd9a9_500d_41e2_9771_df274a2363bd_normalRes);
#endif
o.Normal = HeightToNormal_81cdd9a9_500d_41e2_9771_df274a2363bd_normalRes;
o.Normal += 1e-6;
}
ENDCG
}
FallBack "Diffuse"
CustomEditor "LegacyIlluminShaderGUI"
}

2
MaterialGraphProject/Assets/NewNodes/WIP/POMNode.cs


}
protected virtual MaterialSlot GetTextureSlot()
{
return new MaterialSlot(TextureSlotId, GetTextureSlotName(), kTextureSlotShaderName, SlotType.Input, SlotValueType.sampler2D, Vector4.zero);
return new MaterialSlot(TextureSlotId, GetTextureSlotName(), kTextureSlotShaderName, SlotType.Input, SlotValueType.Texture2D, Vector4.zero);
}
protected virtual MaterialSlot GetOutputSlot()

6
MaterialGraphProject/Assets/POM_Graph.ShaderGraph.meta


fileFormatVersion: 2
guid: 0e5edf7e3bc2bbc47bdb6b74107cc104
guid: 96bf971901c0d7c468d21e8511ced163
NativeFormatImporter:
mainObjectFileID: 0
ScriptedImporter:
script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3}
正在加载...
取消
保存