浏览代码

scatter

/main
MingWai 8 年前
当前提交
d82bb008
共有 5 个文件被更改,包括 1151 次插入11 次删除
  1. 67
      MaterialGraphProject/Assets/_MingWai/ScatterNode.cs
  2. 1001
      MaterialGraphProject/Assets/TestAssets/ColorTransparent.tif
  3. 84
      MaterialGraphProject/Assets/TestAssets/ColorTransparent.tif.meta
  4. 1
      MaterialGraphProject/Assets/_MingWai/Scatter.ShaderGraph
  5. 9
      MaterialGraphProject/Assets/_MingWai/Scatter.ShaderGraph.meta

67
MaterialGraphProject/Assets/_MingWai/ScatterNode.cs


public ScatterNode()
{
name = "Scatter";
AddSlot("Texture", "inputTex", Graphing.SlotType.Input, SlotValueType.Texture2D, Vector4.zero);
AddSlot("TextureAsset", "inputTex", Graphing.SlotType.Input, SlotValueType.Texture2D, Vector4.zero);
AddSlot("SamplerState", "inputSampler", Graphing.SlotType.Input, SlotValueType.SamplerState, Vector4.zero);
AddSlot("UV", "inputUV", Graphing.SlotType.Input, SlotValueType.Vector2, Vector2.one);
AddSlot("Seed", "seed", Graphing.SlotType.Input, SlotValueType.Vector2, Vector2.one);
AddSlot("PositionRange", "p_range", Graphing.SlotType.Input, SlotValueType.Vector2, Vector2.zero);

get { return true; }
}
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)
{
//Sampler input slot
base.GeneratePropertyUsages(visitor, generationMode);
var samplerSlot = FindInputSlot<MaterialSlot>(2);
if (samplerSlot != null)
{
var samplerName = GetSamplerInput(2);
visitor.AddShaderChunk("#ifdef UNITY_COMPILER_HLSL", false);
visitor.AddShaderChunk("SamplerState " + samplerName + ";", true);
visitor.AddShaderChunk("#endif", false);
}
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
{
var outputString = new ShaderGenerator();

outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("float randomno = frac(sin(dot(randomseed, float2(12.9898, 78.233)))*43758.5453);", false);
outputString.AddShaderChunk("return floor(randomno * (max - min + 1)) + min;", false);
outputString.AddShaderChunk("return lerp(min,max,abs(frac(randomno)));", false);
//outputString.AddShaderChunk("return floor(randomno * (max - min + 1)) + min;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);

outputString.Indent();
outputString.AddShaderChunk("finalColor = float4(0,0,0,0);", false);
outputString.AddShaderChunk("float2 newuv = inputUV;", false);
outputString.AddShaderChunk("float4 tex = tex2D(inputTex,newuv);", false);
outputString.AddShaderChunk("float2 newuv;", false);
outputString.AddShaderChunk("float4 tex = finalColor;", false);
outputString.AddShaderChunk("float scale;", false);
outputString.AddShaderChunk("float rotation;", false);
outputString.AddShaderChunk("float2 position;", false);
outputString.AddShaderChunk("float j;", false);
outputString.AddShaderChunk("newuv *= randomrange(seed,s_range.x,s_range.y);", false); //Scale
outputString.AddShaderChunk("newuv = rotateUV(newuv,randomrange(seed,r_range.x,r_range.y));", false); //Rotate
outputString.AddShaderChunk("newuv += randomrange(seed,p_range.x,p_range.y));", false); //Position
outputString.AddShaderChunk("newuv = inputUV;", false);
outputString.AddShaderChunk("j = "+i+"+0.001f;", false);
//seamless
outputString.AddShaderChunk("scale = randomrange(seed+j,s_range.x,s_range.y);", false); //Random Scale
outputString.AddShaderChunk("newuv *= scale;", false); //Scale
outputString.AddShaderChunk("newuv -= (scale-1)*0.5f;", false); //Move to Center After Scale
outputString.AddShaderChunk("rotation = randomrange(seed+j,r_range.x,r_range.y);", false); //Random rotation
outputString.AddShaderChunk("newuv = rotateUV(newuv,rotation);", false); //Rotate
outputString.AddShaderChunk("position.x = randomrange(seed.x+j,p_range.x,p_range.y);", false); //Random position
outputString.AddShaderChunk("position.y = randomrange(seed.y+j,p_range.x,p_range.y);", false); //Random position
outputString.AddShaderChunk("newuv += position*scale;", false); //Position
outputString.AddShaderChunk("tex = tex2D(inputTex,newuv);", false);
outputString.AddShaderChunk("#ifdef UNITY_COMPILER_HLSL", false);
outputString.AddShaderChunk("tex = inputTex.Sample(inputSampler, newuv);", false);
outputString.AddShaderChunk("#endif",false);
outputString.AddShaderChunk("finalColor += tex/"+m_num+";", false);
outputString.AddShaderChunk("finalColor = lerp(finalColor,tex, tex.a);", false);
//seamless
outputString.AddShaderChunk("newuv = 1-newuv;", false);
outputString.AddShaderChunk("#ifdef UNITY_COMPILER_HLSL", false);
outputString.AddShaderChunk("tex = inputTex.Sample(inputSampler, newuv);", false);
outputString.AddShaderChunk("#endif", false);
//blend seamless
outputString.AddShaderChunk("finalColor = lerp(finalColor,tex, tex.a);", false);
}
outputString.Deindent();

1001
MaterialGraphProject/Assets/TestAssets/ColorTransparent.tif
文件差异内容过多而无法显示
查看文件

84
MaterialGraphProject/Assets/TestAssets/ColorTransparent.tif.meta


fileFormatVersion: 2
guid: 75446046af0bacb4eac0858374f720b5
timeCreated: 1490800222
licenseType: Pro
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 4
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 0
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -1
wrapU: -1
wrapV: -1
wrapW: -1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaUsage: 2
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
- buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant:

1
MaterialGraphProject/Assets/_MingWai/Scatter.ShaderGraph
文件差异内容过多而无法显示
查看文件

9
MaterialGraphProject/Assets/_MingWai/Scatter.ShaderGraph.meta


fileFormatVersion: 2
guid: 0e5edf7e3bc2bbc47bdb6b74107cc104
timeCreated: 1495479560
licenseType: Pro
NativeFormatImporter:
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存