public override void WriteToString(ref string nodeInfo, ref string connectionsInfo) { base.WriteToString(ref nodeInfo, ref connectionsInfo); IOUtils.AddFieldValueToString(ref nodeInfo, _selectedTextureVerticalDirection); IOUtils.AddFieldValueToString(ref nodeInfo, _negativeSpeedBehavior); }
public override void ReadAdditionalClipboardData(ref string[] nodeParams) { base.ReadAdditionalClipboardData(ref nodeParams); m_materialValue = IOUtils.StringToColor(GetCurrentParam(ref nodeParams)); }
public override void WriteToString(ref string nodeInfo, ref string connectionsInfo) { base.WriteToString(ref nodeInfo, ref connectionsInfo); IOUtils.AddFieldValueToString(ref nodeInfo, m_outputTypeInt); }
public void WriteToString(ref string nodeInfo) { IOUtils.AddFieldValueToString(ref nodeInfo, m_isBillboard); IOUtils.AddFieldValueToString(ref nodeInfo, m_billboardType); IOUtils.AddFieldValueToString(ref nodeInfo, m_rotationIndependent); }
public void WriteToString(ref string nodeInfo) { IOUtils.AddFieldValueToString(ref nodeInfo, m_fallbackShader); }
public override void WriteToString(ref string nodeInfo, ref string connectionsInfo) { base.WriteToString(ref nodeInfo, ref connectionsInfo); IOUtils.AddFieldValueToString(ref nodeInfo, m_textureCoordChannel); }
public override void WriteToString(ref string nodeInfo, ref string connectionsInfo) { base.WriteToString(ref nodeInfo, ref connectionsInfo); IOUtils.AddFieldValueToString(ref nodeInfo, m_lightCount); IOUtils.AddFieldValueToString(ref nodeInfo, m_enableSpotlight); }
public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar) { if (m_outputPorts[0].IsLocalValue) { return(m_outputPorts[0].LocalValue); } switch (m_type) { case NoiseGeneratorType.Simplex2D: { string float3Mod289Func = string.Empty; IOUtils.AddSingleLineFunction(ref float3Mod289Func, Simplex2DFloat3Mod289Func); dataCollector.AddFunction(Simplex2DFloat3Mod289Func, float3Mod289Func); string float2Mod289Func = string.Empty; IOUtils.AddSingleLineFunction(ref float2Mod289Func, Simplex2DFloat2Mod289Func); dataCollector.AddFunction(Simplex2DFloat2Mod289Func, float2Mod289Func); string permuteFunc = string.Empty; IOUtils.AddSingleLineFunction(ref permuteFunc, Simplex2DPermuteFunc); dataCollector.AddFunction(Simplex2DPermuteFunc, permuteFunc); string snoiseFunc = string.Empty; IOUtils.AddFunctionHeader(ref snoiseFunc, SimplexNoise2DHeader); for (int i = 0; i < SimplexNoise2DBody.Length; i++) { IOUtils.AddFunctionLine(ref snoiseFunc, SimplexNoise2DBody[i]); } IOUtils.CloseFunctionBody(ref snoiseFunc); dataCollector.AddFunction(SimplexNoise2DHeader, snoiseFunc); string size = m_inputPorts[0].GeneratePortInstructions(ref dataCollector); RegisterLocalVariable(0, string.Format(SimplexNoise2DFunc, size), ref dataCollector, ("simplePerlin2D" + m_uniqueId)); } break; case NoiseGeneratorType.Simplex3D: { string float3Mod289Func = string.Empty; IOUtils.AddSingleLineFunction(ref float3Mod289Func, Simplex3DFloat3Mod289); dataCollector.AddFunction(Simplex3DFloat3Mod289, float3Mod289Func); string float4Mod289Func = string.Empty; IOUtils.AddSingleLineFunction(ref float4Mod289Func, Simplex3DFloat4Mod289); dataCollector.AddFunction(Simplex3DFloat4Mod289, float4Mod289Func); string permuteFunc = string.Empty; IOUtils.AddSingleLineFunction(ref permuteFunc, Simplex3DFloat4Permute); dataCollector.AddFunction(Simplex3DFloat4Permute, permuteFunc); string taylorInvSqrtFunc = string.Empty; IOUtils.AddSingleLineFunction(ref taylorInvSqrtFunc, TaylorInvSqrtFunc); dataCollector.AddFunction(TaylorInvSqrtFunc, taylorInvSqrtFunc); string snoiseFunc = string.Empty; IOUtils.AddFunctionHeader(ref snoiseFunc, SimplexNoise3DHeader); for (int i = 0; i < SimplexNoise3DBody.Length; i++) { IOUtils.AddFunctionLine(ref snoiseFunc, SimplexNoise3DBody[i]); } IOUtils.CloseFunctionBody(ref snoiseFunc); dataCollector.AddFunction(SimplexNoise3DHeader, snoiseFunc); string size = m_inputPorts[0].GeneratePortInstructions(ref dataCollector); RegisterLocalVariable(0, string.Format(SimplexNoise3DFunc, size), ref dataCollector, ("simplePerlin3D" + m_uniqueId)); } break; } return(m_outputPorts[0].LocalValue); }
public override void WriteToString(ref string nodeInfo, ref string connectionsInfo) { base.WriteToString(ref nodeInfo, ref connectionsInfo); IOUtils.AddFieldValueToString(ref nodeInfo, IOUtils.Vector4ToString(m_defaultValue)); IOUtils.AddFieldValueToString(ref nodeInfo, IOUtils.Vector4ToString(m_materialValue)); }
public override void WriteToString(ref string nodeInfo, ref string connectionsInfo) { base.WriteToString(ref nodeInfo, ref connectionsInfo); IOUtils.AddFieldValueToString(ref nodeInfo, (m_currentSelected != null ? m_currentSelected.UniqueId : -1)); }
public override void ReadFromString(ref string[] nodeParams) { base.ReadFromString(ref nodeParams); m_defaultValue = IOUtils.StringToMatrix4x4(GetCurrentParam(ref nodeParams)); }
void LoadTemplateBody(string guid) { m_guid = guid; string datapath = AssetDatabase.GUIDToAssetPath(guid); string shaderBody = string.Empty; shaderBody = IOUtils.LoadTextFileFromDisk(datapath); shaderBody = shaderBody.Replace("\r\n", "\n"); m_shaderData = TemplateShaderInfoUtil.CreateShaderData(shaderBody); if (m_shaderData == null) { m_isValid = false; return; } m_templateIdManager = new TemplateIdManager(shaderBody); try { int nameBegin = shaderBody.IndexOf(TemplatesManager.TemplateShaderNameBeginTag); if (nameBegin < 0) { // Not a template return; } int nameEnd = shaderBody.IndexOf(TemplatesManager.TemplateFullEndTag, nameBegin); if (nameEnd < 0) { return; } m_shaderBody = shaderBody; int defaultBegin = nameBegin + TemplatesManager.TemplateShaderNameBeginTag.Length; int defaultLength = nameEnd - defaultBegin; m_defaultShaderName = shaderBody.Substring(defaultBegin, defaultLength); int[] nameIdx = m_defaultShaderName.AllIndexesOf("\""); nameIdx[0] += 1; // Ignore the " character from the string m_defaultShaderName = m_defaultShaderName.Substring(nameIdx[0], nameIdx[1] - nameIdx[0]); m_shaderNameId = shaderBody.Substring(nameBegin, nameEnd + TemplatesManager.TemplateFullEndTag.Length - nameBegin); m_templateProperties.AddId(shaderBody, m_shaderNameId, false); m_templateIdManager.RegisterId(nameBegin, m_shaderNameId, m_shaderNameId); shaderBody = shaderBody.Substring(nameEnd + TemplatesManager.TemplateFullEndTag.Length); } catch (Exception e) { Debug.LogException(e); m_isValid = false; } TemplateHelperFunctions.FetchDependencies(m_dependenciesContainer, ref m_shaderBody); if (m_dependenciesContainer.IsValid) { int index = m_dependenciesContainer.Id.IndexOf(TemplatesManager.TemplateDependenciesListTag); m_templateProperties.AddId(new TemplateProperty(m_dependenciesContainer.Id, m_dependenciesContainer.Id.Substring(0, index), true)); m_templateIdManager.RegisterId(m_dependenciesContainer.Index, m_dependenciesContainer.Id, m_dependenciesContainer.Id); } TemplateHelperFunctions.FetchCustomInspector(m_customInspectorContainer, ref m_shaderBody); if (m_customInspectorContainer.IsValid) { int index = m_customInspectorContainer.Id.IndexOf("CustomEditor"); m_templateProperties.AddId(new TemplateProperty(m_customInspectorContainer.Id, m_customInspectorContainer.Id.Substring(0, index), true)); m_templateIdManager.RegisterId(m_customInspectorContainer.Index, m_customInspectorContainer.Id, m_customInspectorContainer.Id); } TemplateHelperFunctions.FetchFallback(m_fallbackContainer, ref m_shaderBody); if (m_fallbackContainer.IsValid) { int index = m_fallbackContainer.Id.IndexOf("Fallback"); m_templateProperties.AddId(new TemplateProperty(m_fallbackContainer.Id, m_fallbackContainer.Id.Substring(0, index), true)); m_templateIdManager.RegisterId(m_fallbackContainer.Index, m_fallbackContainer.Id, m_fallbackContainer.Id); } // Shader body may have been changed to inject inexisting tags like fallback m_templateIdManager.ShaderBody = m_shaderBody; m_propertyTag = new TemplateTagData(m_shaderData.PropertyStartIdx, TemplatesManager.TemplatePropertyTag, true); m_templateIdManager.RegisterId(m_shaderData.PropertyStartIdx, TemplatesManager.TemplatePropertyTag, TemplatesManager.TemplatePropertyTag); m_templateProperties.AddId(shaderBody, TemplatesManager.TemplatePropertyTag, true); Dictionary <string, TemplateShaderPropertyData> duplicatesHelper = new Dictionary <string, TemplateShaderPropertyData>(); TemplateHelperFunctions.CreateShaderPropertiesList(m_shaderData.Properties, ref m_availableShaderProperties, ref duplicatesHelper); int subShaderCount = m_shaderData.SubShaders.Count; int mainSubShaderIdx = -1; int mainPassIdx = -1; int firstVisibleSubShaderId = -1; int firstVisiblePassId = -1; bool foundMainPass = false; bool foundFirstVisible = false; for (int i = 0; i < subShaderCount; i++) { TemplateSubShader subShader = new TemplateSubShader(i, m_templateIdManager, "SubShader" + i, m_shaderData.SubShaders[i], ref duplicatesHelper); if (subShader.FoundMainPass) { if (!foundMainPass) { foundMainPass = true; mainSubShaderIdx = i; mainPassIdx = subShader.MainPass; } } else if (subShader.MainPass > -1) { if (!foundFirstVisible) { foundFirstVisible = true; firstVisibleSubShaderId = i; firstVisiblePassId = subShader.MainPass; } } m_subShaders.Add(subShader); m_masterNodesRequired += subShader.Passes.Count; } if (!foundMainPass && foundFirstVisible) { mainSubShaderIdx = firstVisibleSubShaderId; mainPassIdx = firstVisiblePassId; } for (int subShaderIdx = 0; subShaderIdx < subShaderCount; subShaderIdx++) { int passCount = m_subShaders[subShaderIdx].Passes.Count; for (int passIdx = 0; passIdx < passCount; passIdx++) { m_subShaders[subShaderIdx].Passes[passIdx].IsMainPass = (mainSubShaderIdx == subShaderIdx && mainPassIdx == passIdx); } } duplicatesHelper.Clear(); duplicatesHelper = null; m_isSinglePass = (m_subShaders.Count == 1 && m_subShaders[0].PassAmount == 1); }
public override void WriteToString(ref string nodeInfo, ref string connectionsInfo) { base.WriteToString(ref nodeInfo, ref connectionsInfo); IOUtils.AddFieldValueToString(ref nodeInfo, m_shaderName); IOUtils.AddFieldValueToString(ref nodeInfo, (m_currentTemplate != null) ? m_currentTemplate.GUID : string.Empty); }
public override void WriteToString(ref string nodeInfo, ref string connectionsInfo) { base.WriteToString(ref nodeInfo, ref connectionsInfo); IOUtils.AddFieldValueToString(ref nodeInfo, m_source); IOUtils.AddFieldValueToString(ref nodeInfo, m_destination); }
public override void WriteToString(ref string nodeInfo, ref string connectionsInfo) { base.WriteToString(ref nodeInfo, ref connectionsInfo); IOUtils.AddFieldValueToString(ref nodeInfo, m_currentSelectedInput); }
public override void WriteToString( ref string nodeInfo, ref string connectionsInfo ) { base.WriteToString( ref nodeInfo, ref connectionsInfo ): IOUtils.AddFieldValueToString( ref nodeInfo, m_dataName ): }
public override void WriteToString(ref string nodeInfo, ref string connectionsInfo) { base.WriteToString(ref nodeInfo, ref connectionsInfo); IOUtils.AddFieldValueToString(ref nodeInfo, m_normalSpace); }
public void WriteToString( ref string nodeInfo ) { IOUtils.AddFieldValueToString( ref nodeInfo, m_enable ): }
private void GeneratePOMfunction() { m_functionBody = string.Empty; IOUtils.AddFunctionHeader(ref m_functionBody, "inline float2 POM( sampler2D heightMap, float2 uvs, float2 dx, float2 dy, float3 normalWorld, float3 viewWorld, float3 viewDirTan, int minSamples, int maxSamples, float parallax, float refPlane, float2 tilling, float2 curv )"); IOUtils.AddFunctionLine(ref m_functionBody, "float3 result = 0;"); IOUtils.AddFunctionLine(ref m_functionBody, "int stepIndex = 0;"); //IOUtils.AddFunctionLine( ref m_functionBody, "int numSteps = ( int )( minSamples + dot( viewWorld, normalWorld ) * ( maxSamples - minSamples ) );" ); //IOUtils.AddFunctionLine( ref m_functionBody, "int numSteps = ( int )lerp( maxSamples, minSamples, length( fwidth( uvs ) ) * 10 );" ); IOUtils.AddFunctionLine(ref m_functionBody, "int numSteps = ( int )lerp( maxSamples, minSamples, dot( normalWorld, viewWorld ) );"); IOUtils.AddFunctionLine(ref m_functionBody, "float layerHeight = 1.0 / numSteps;"); IOUtils.AddFunctionLine(ref m_functionBody, "float2 plane = parallax * ( viewDirTan.xy / viewDirTan.z );"); IOUtils.AddFunctionLine(ref m_functionBody, "uvs += refPlane * plane;"); IOUtils.AddFunctionLine(ref m_functionBody, "float2 deltaTex = -plane * layerHeight;"); IOUtils.AddFunctionLine(ref m_functionBody, "float2 prevTexOffset = 0;"); IOUtils.AddFunctionLine(ref m_functionBody, "float prevRayZ = 1.0f;"); IOUtils.AddFunctionLine(ref m_functionBody, "float prevHeight = 0.0f;"); IOUtils.AddFunctionLine(ref m_functionBody, "float2 currTexOffset = deltaTex;"); IOUtils.AddFunctionLine(ref m_functionBody, "float currRayZ = 1.0f - layerHeight;"); IOUtils.AddFunctionLine(ref m_functionBody, "float currHeight = 0.0f;"); IOUtils.AddFunctionLine(ref m_functionBody, "float intersection = 0;"); IOUtils.AddFunctionLine(ref m_functionBody, "float2 finalTexOffset = 0;"); IOUtils.AddFunctionLine(ref m_functionBody, "while ( stepIndex < numSteps + 1 )"); IOUtils.AddFunctionLine(ref m_functionBody, "{"); if (m_useCurvature) { IOUtils.AddFunctionLine(ref m_functionBody, " result.z = dot( curv, currTexOffset * currTexOffset );"); IOUtils.AddFunctionLine(ref m_functionBody, " currHeight = tex2Dgrad( heightMap, uvs + currTexOffset, dx, dy )."+ m_channelTypeVal[m_selectedChannelInt] + " * ( 1 - result.z );"); } else { IOUtils.AddFunctionLine(ref m_functionBody, " currHeight = tex2Dgrad( heightMap, uvs + currTexOffset, dx, dy )."+ m_channelTypeVal[m_selectedChannelInt] + ";"); } IOUtils.AddFunctionLine(ref m_functionBody, " if ( currHeight > currRayZ )"); IOUtils.AddFunctionLine(ref m_functionBody, " {"); IOUtils.AddFunctionLine(ref m_functionBody, " stepIndex = numSteps + 1;"); IOUtils.AddFunctionLine(ref m_functionBody, " }"); IOUtils.AddFunctionLine(ref m_functionBody, " else"); IOUtils.AddFunctionLine(ref m_functionBody, " {"); IOUtils.AddFunctionLine(ref m_functionBody, " stepIndex++;"); IOUtils.AddFunctionLine(ref m_functionBody, " prevTexOffset = currTexOffset;"); IOUtils.AddFunctionLine(ref m_functionBody, " prevRayZ = currRayZ;"); IOUtils.AddFunctionLine(ref m_functionBody, " prevHeight = currHeight;"); IOUtils.AddFunctionLine(ref m_functionBody, " currTexOffset += deltaTex;"); if (m_useCurvature) { IOUtils.AddFunctionLine(ref m_functionBody, " currRayZ -= layerHeight * ( 1 - result.z ) * (1+_CurvFix);"); } else { IOUtils.AddFunctionLine(ref m_functionBody, " currRayZ -= layerHeight;"); } IOUtils.AddFunctionLine(ref m_functionBody, " }"); IOUtils.AddFunctionLine(ref m_functionBody, "}"); if (m_sidewallSteps > 0) { IOUtils.AddFunctionLine(ref m_functionBody, "int sectionSteps = " + m_sidewallSteps + ";"); IOUtils.AddFunctionLine(ref m_functionBody, "int sectionIndex = 0;"); IOUtils.AddFunctionLine(ref m_functionBody, "float newZ = 0;"); IOUtils.AddFunctionLine(ref m_functionBody, "float newHeight = 0;"); IOUtils.AddFunctionLine(ref m_functionBody, "while ( sectionIndex < sectionSteps )"); IOUtils.AddFunctionLine(ref m_functionBody, "{"); IOUtils.AddFunctionLine(ref m_functionBody, " intersection = ( prevHeight - prevRayZ ) / ( prevHeight - currHeight + currRayZ - prevRayZ );"); IOUtils.AddFunctionLine(ref m_functionBody, " finalTexOffset = prevTexOffset + intersection * deltaTex;"); IOUtils.AddFunctionLine(ref m_functionBody, " newZ = prevRayZ - intersection * layerHeight;"); IOUtils.AddFunctionLine(ref m_functionBody, " newHeight = tex2Dgrad( heightMap, uvs + finalTexOffset, dx, dy )."+ m_channelTypeVal[m_selectedChannelInt] + ";"); IOUtils.AddFunctionLine(ref m_functionBody, " if ( newHeight > newZ )"); IOUtils.AddFunctionLine(ref m_functionBody, " {"); IOUtils.AddFunctionLine(ref m_functionBody, " currTexOffset = finalTexOffset;"); IOUtils.AddFunctionLine(ref m_functionBody, " currHeight = newHeight;"); IOUtils.AddFunctionLine(ref m_functionBody, " currRayZ = newZ;"); IOUtils.AddFunctionLine(ref m_functionBody, " deltaTex = intersection * deltaTex;"); IOUtils.AddFunctionLine(ref m_functionBody, " layerHeight = intersection * layerHeight;"); IOUtils.AddFunctionLine(ref m_functionBody, " }"); IOUtils.AddFunctionLine(ref m_functionBody, " else"); IOUtils.AddFunctionLine(ref m_functionBody, " {"); IOUtils.AddFunctionLine(ref m_functionBody, " prevTexOffset = finalTexOffset;"); IOUtils.AddFunctionLine(ref m_functionBody, " prevHeight = newHeight;"); IOUtils.AddFunctionLine(ref m_functionBody, " prevRayZ = newZ;"); IOUtils.AddFunctionLine(ref m_functionBody, " deltaTex = ( 1 - intersection ) * deltaTex;"); IOUtils.AddFunctionLine(ref m_functionBody, " layerHeight = ( 1 - intersection ) * layerHeight;"); IOUtils.AddFunctionLine(ref m_functionBody, " }"); IOUtils.AddFunctionLine(ref m_functionBody, " sectionIndex++;"); IOUtils.AddFunctionLine(ref m_functionBody, "}"); } else { IOUtils.AddFunctionLine(ref m_functionBody, "finalTexOffset = currTexOffset;"); } if (m_useCurvature) { IOUtils.AddFunctionLine(ref m_functionBody, "#ifdef UNITY_PASS_SHADOWCASTER"); IOUtils.AddFunctionLine(ref m_functionBody, "if ( unity_LightShadowBias.z == 0.0 )"); IOUtils.AddFunctionLine(ref m_functionBody, "{"); IOUtils.AddFunctionLine(ref m_functionBody, "#endif"); IOUtils.AddFunctionLine(ref m_functionBody, " if ( result.z > 1 )"); IOUtils.AddFunctionLine(ref m_functionBody, " clip( -1 );"); IOUtils.AddFunctionLine(ref m_functionBody, "#ifdef UNITY_PASS_SHADOWCASTER"); IOUtils.AddFunctionLine(ref m_functionBody, "}"); IOUtils.AddFunctionLine(ref m_functionBody, "#endif"); } if (m_clipEnds) { IOUtils.AddFunctionLine(ref m_functionBody, "result.xy = uvs + finalTexOffset;"); IOUtils.AddFunctionLine(ref m_functionBody, "#ifdef UNITY_PASS_SHADOWCASTER"); IOUtils.AddFunctionLine(ref m_functionBody, "if ( unity_LightShadowBias.z == 0.0 )"); IOUtils.AddFunctionLine(ref m_functionBody, "{"); IOUtils.AddFunctionLine(ref m_functionBody, "#endif"); IOUtils.AddFunctionLine(ref m_functionBody, " if ( result.x < 0 )"); IOUtils.AddFunctionLine(ref m_functionBody, " clip( -1 );"); IOUtils.AddFunctionLine(ref m_functionBody, " if ( result.x > tilling.x )"); IOUtils.AddFunctionLine(ref m_functionBody, " clip( -1 );"); IOUtils.AddFunctionLine(ref m_functionBody, " if ( result.y < 0 )"); IOUtils.AddFunctionLine(ref m_functionBody, " clip( -1 );"); IOUtils.AddFunctionLine(ref m_functionBody, " if ( result.y > tilling.y )"); IOUtils.AddFunctionLine(ref m_functionBody, " clip( -1 );"); IOUtils.AddFunctionLine(ref m_functionBody, "#ifdef UNITY_PASS_SHADOWCASTER"); IOUtils.AddFunctionLine(ref m_functionBody, "}"); IOUtils.AddFunctionLine(ref m_functionBody, "#endif"); IOUtils.AddFunctionLine(ref m_functionBody, "return result.xy;"); } else { IOUtils.AddFunctionLine(ref m_functionBody, "return uvs + finalTexOffset;"); } IOUtils.CloseFunctionBody(ref m_functionBody); }
public override void WriteToString(ref string nodeInfo, ref string connectionsInfo) { base.WriteToString(ref nodeInfo, ref connectionsInfo); IOUtils.AddFieldValueToString(ref nodeInfo, m_referenceType); IOUtils.AddFieldValueToString(ref nodeInfo, ((m_referenceNode != null) ? m_referenceNode.UniqueId : -1)); }
public override void WriteToString(ref string nodeInfo, ref string connectionsInfo) { base.WriteToString(ref nodeInfo, ref connectionsInfo); IOUtils.AddFieldValueToString(ref nodeInfo, m_viewSpaceInt); IOUtils.AddFieldValueToString(ref nodeInfo, m_convertToLinear); }
private void GeneratePOMfunction() { m_functionBody = string.Empty; switch (m_pomTexType) { default: case POMTexTypes.Texture2D: IOUtils.AddFunctionHeader(ref m_functionBody, "inline float2 POM( sampler2D heightMap, float2 uvs, float2 dx, float2 dy, float3 normalWorld, float3 viewWorld, float3 viewDirTan, int minSamples, int maxSamples, float parallax, float refPlane, float2 tilling, float2 curv, int index )"); break; case POMTexTypes.Texture3D: IOUtils.AddFunctionHeader(ref m_functionBody, "inline float2 POM( sampler3D heightMap, float3 uvs, float3 dx, float3 dy, float3 normalWorld, float3 viewWorld, float3 viewDirTan, int minSamples, int maxSamples, float parallax, float refPlane, float2 tilling, float2 curv, int index )"); break; case POMTexTypes.TextureArray: if (UIUtils.CurrentWindow.OutsideGraph.IsSRP) { IOUtils.AddFunctionHeader(ref m_functionBody, "inline float2 POM( TEXTURE2D_ARRAY_ARGS(heightMap,sampler##heightMap), float2 uvs, float2 dx, float2 dy, float3 normalWorld, float3 viewWorld, float3 viewDirTan, int minSamples, int maxSamples, float parallax, float refPlane, float2 tilling, float2 curv, int index )"); } else { IOUtils.AddFunctionHeader(ref m_functionBody, "inline float2 POM( UNITY_ARGS_TEX2DARRAY(heightMap), float2 uvs, float2 dx, float2 dy, float3 normalWorld, float3 viewWorld, float3 viewDirTan, int minSamples, int maxSamples, float parallax, float refPlane, float2 tilling, float2 curv, int index )"); } break; } IOUtils.AddFunctionLine(ref m_functionBody, "float3 result = 0;"); IOUtils.AddFunctionLine(ref m_functionBody, "int stepIndex = 0;"); //IOUtils.AddFunctionLine( ref m_functionBody, "int numSteps = ( int )( minSamples + dot( viewWorld, normalWorld ) * ( maxSamples - minSamples ) );" ); //IOUtils.AddFunctionLine( ref m_functionBody, "int numSteps = ( int )lerp( maxSamples, minSamples, length( fwidth( uvs ) ) * 10 );" ); IOUtils.AddFunctionLine(ref m_functionBody, "int numSteps = ( int )lerp( (float)maxSamples, (float)minSamples, saturate( dot( normalWorld, viewWorld ) ) );"); IOUtils.AddFunctionLine(ref m_functionBody, "float layerHeight = 1.0 / numSteps;"); IOUtils.AddFunctionLine(ref m_functionBody, "float2 plane = parallax * ( viewDirTan.xy / viewDirTan.z );"); switch (m_pomTexType) { default: case POMTexTypes.Texture2D: IOUtils.AddFunctionLine(ref m_functionBody, "uvs += refPlane * plane;"); break; case POMTexTypes.Texture3D: IOUtils.AddFunctionLine(ref m_functionBody, "uvs.xy += refPlane * plane;"); break; case POMTexTypes.TextureArray: IOUtils.AddFunctionLine(ref m_functionBody, "uvs += refPlane * plane;"); break; } IOUtils.AddFunctionLine(ref m_functionBody, "float2 deltaTex = -plane * layerHeight;"); IOUtils.AddFunctionLine(ref m_functionBody, "float2 prevTexOffset = 0;"); IOUtils.AddFunctionLine(ref m_functionBody, "float prevRayZ = 1.0f;"); IOUtils.AddFunctionLine(ref m_functionBody, "float prevHeight = 0.0f;"); IOUtils.AddFunctionLine(ref m_functionBody, "float2 currTexOffset = deltaTex;"); IOUtils.AddFunctionLine(ref m_functionBody, "float currRayZ = 1.0f - layerHeight;"); IOUtils.AddFunctionLine(ref m_functionBody, "float currHeight = 0.0f;"); IOUtils.AddFunctionLine(ref m_functionBody, "float intersection = 0;"); IOUtils.AddFunctionLine(ref m_functionBody, "float2 finalTexOffset = 0;"); IOUtils.AddFunctionLine(ref m_functionBody, "while ( stepIndex < numSteps + 1 )"); IOUtils.AddFunctionLine(ref m_functionBody, "{"); if (m_useCurvature) { IOUtils.AddFunctionLine(ref m_functionBody, " result.z = dot( curv, currTexOffset * currTexOffset );"); switch (m_pomTexType) { default: case POMTexTypes.Texture2D: IOUtils.AddFunctionLine(ref m_functionBody, " currHeight = tex2Dgrad( heightMap, uvs + currTexOffset, dx, dy )."+ m_channelTypeVal[m_selectedChannelInt] + " * ( 1 - result.z );"); break; case POMTexTypes.Texture3D: IOUtils.AddFunctionLine(ref m_functionBody, " currHeight = tex3Dgrad( heightMap, uvs + float3(currTexOffset,0), dx, dy )."+ m_channelTypeVal[m_selectedChannelInt] + " * ( 1 - result.z );"); break; case POMTexTypes.TextureArray: if (UIUtils.CurrentWindow.OutsideGraph.IsSRP) { IOUtils.AddFunctionLine(ref m_functionBody, " currHeight = SAMPLE_TEXTURE2D_ARRAY_GRAD( heightMap,sampler##heightMap, uvs + currTexOffset,index, dx, dy )."+ m_channelTypeVal[m_selectedChannelInt] + " * ( 1 - result.z );"); } else { IOUtils.AddFunctionLine(ref m_functionBody, " currHeight = ASE_SAMPLE_TEX2DARRAY_GRAD( heightMap, float3(uvs + currTexOffset,index), dx, dy )."+ m_channelTypeVal[m_selectedChannelInt] + " * ( 1 - result.z );"); } break; } } else { switch (m_pomTexType) { default: case POMTexTypes.Texture2D: IOUtils.AddFunctionLine(ref m_functionBody, " currHeight = tex2Dgrad( heightMap, uvs + currTexOffset, dx, dy )."+ m_channelTypeVal[m_selectedChannelInt] + ";"); break; case POMTexTypes.Texture3D: IOUtils.AddFunctionLine(ref m_functionBody, " currHeight = tex3Dgrad( heightMap, uvs + float3(currTexOffset,0), dx, dy )."+ m_channelTypeVal[m_selectedChannelInt] + ";"); break; case POMTexTypes.TextureArray: if (UIUtils.CurrentWindow.OutsideGraph.IsSRP) { IOUtils.AddFunctionLine(ref m_functionBody, " currHeight = SAMPLE_TEXTURE2D_ARRAY_GRAD( heightMap, sampler##heightMap, uvs + currTexOffset,index, dx, dy )."+ m_channelTypeVal[m_selectedChannelInt] + ";"); } else { IOUtils.AddFunctionLine(ref m_functionBody, " currHeight = ASE_SAMPLE_TEX2DARRAY_GRAD( heightMap, float3(uvs + currTexOffset,index), dx, dy )."+ m_channelTypeVal[m_selectedChannelInt] + ";"); } break; } } IOUtils.AddFunctionLine(ref m_functionBody, " if ( currHeight > currRayZ )"); IOUtils.AddFunctionLine(ref m_functionBody, " {"); IOUtils.AddFunctionLine(ref m_functionBody, " stepIndex = numSteps + 1;"); IOUtils.AddFunctionLine(ref m_functionBody, " }"); IOUtils.AddFunctionLine(ref m_functionBody, " else"); IOUtils.AddFunctionLine(ref m_functionBody, " {"); IOUtils.AddFunctionLine(ref m_functionBody, " stepIndex++;"); IOUtils.AddFunctionLine(ref m_functionBody, " prevTexOffset = currTexOffset;"); IOUtils.AddFunctionLine(ref m_functionBody, " prevRayZ = currRayZ;"); IOUtils.AddFunctionLine(ref m_functionBody, " prevHeight = currHeight;"); IOUtils.AddFunctionLine(ref m_functionBody, " currTexOffset += deltaTex;"); if (m_useCurvature) { IOUtils.AddFunctionLine(ref m_functionBody, " currRayZ -= layerHeight * ( 1 - result.z ) * (1+_CurvFix);"); } else { IOUtils.AddFunctionLine(ref m_functionBody, " currRayZ -= layerHeight;"); } IOUtils.AddFunctionLine(ref m_functionBody, " }"); IOUtils.AddFunctionLine(ref m_functionBody, "}"); if (m_sidewallSteps > 0) { IOUtils.AddFunctionLine(ref m_functionBody, "int sectionSteps = " + m_sidewallSteps + ";"); IOUtils.AddFunctionLine(ref m_functionBody, "int sectionIndex = 0;"); IOUtils.AddFunctionLine(ref m_functionBody, "float newZ = 0;"); IOUtils.AddFunctionLine(ref m_functionBody, "float newHeight = 0;"); IOUtils.AddFunctionLine(ref m_functionBody, "while ( sectionIndex < sectionSteps )"); IOUtils.AddFunctionLine(ref m_functionBody, "{"); IOUtils.AddFunctionLine(ref m_functionBody, " intersection = ( prevHeight - prevRayZ ) / ( prevHeight - currHeight + currRayZ - prevRayZ );"); IOUtils.AddFunctionLine(ref m_functionBody, " finalTexOffset = prevTexOffset + intersection * deltaTex;"); IOUtils.AddFunctionLine(ref m_functionBody, " newZ = prevRayZ - intersection * layerHeight;"); switch (m_pomTexType) { default: case POMTexTypes.Texture2D: IOUtils.AddFunctionLine(ref m_functionBody, " newHeight = tex2Dgrad( heightMap, uvs + finalTexOffset, dx, dy )."+ m_channelTypeVal[m_selectedChannelInt] + ";"); break; case POMTexTypes.Texture3D: IOUtils.AddFunctionLine(ref m_functionBody, " newHeight = tex3Dgrad( heightMap, uvs + float3(finalTexOffset,0), dx, dy )."+ m_channelTypeVal[m_selectedChannelInt] + ";"); break; case POMTexTypes.TextureArray: if (UIUtils.CurrentWindow.OutsideGraph.IsSRP) { IOUtils.AddFunctionLine(ref m_functionBody, " newHeight = SAMPLE_TEXTURE2D_ARRAY_GRAD( heightMap, sampler##heightMap, uvs + finalTexOffset,index, dx, dy )."+ m_channelTypeVal[m_selectedChannelInt] + ";"); } else { IOUtils.AddFunctionLine(ref m_functionBody, " newHeight = ASE_SAMPLE_TEX2DARRAY_GRAD( heightMap, float3(uvs + finalTexOffset,index), dx, dy )."+ m_channelTypeVal[m_selectedChannelInt] + ";"); } break; } IOUtils.AddFunctionLine(ref m_functionBody, " if ( newHeight > newZ )"); IOUtils.AddFunctionLine(ref m_functionBody, " {"); IOUtils.AddFunctionLine(ref m_functionBody, " currTexOffset = finalTexOffset;"); IOUtils.AddFunctionLine(ref m_functionBody, " currHeight = newHeight;"); IOUtils.AddFunctionLine(ref m_functionBody, " currRayZ = newZ;"); IOUtils.AddFunctionLine(ref m_functionBody, " deltaTex = intersection * deltaTex;"); IOUtils.AddFunctionLine(ref m_functionBody, " layerHeight = intersection * layerHeight;"); IOUtils.AddFunctionLine(ref m_functionBody, " }"); IOUtils.AddFunctionLine(ref m_functionBody, " else"); IOUtils.AddFunctionLine(ref m_functionBody, " {"); IOUtils.AddFunctionLine(ref m_functionBody, " prevTexOffset = finalTexOffset;"); IOUtils.AddFunctionLine(ref m_functionBody, " prevHeight = newHeight;"); IOUtils.AddFunctionLine(ref m_functionBody, " prevRayZ = newZ;"); IOUtils.AddFunctionLine(ref m_functionBody, " deltaTex = ( 1 - intersection ) * deltaTex;"); IOUtils.AddFunctionLine(ref m_functionBody, " layerHeight = ( 1 - intersection ) * layerHeight;"); IOUtils.AddFunctionLine(ref m_functionBody, " }"); IOUtils.AddFunctionLine(ref m_functionBody, " sectionIndex++;"); IOUtils.AddFunctionLine(ref m_functionBody, "}"); } else { IOUtils.AddFunctionLine(ref m_functionBody, "finalTexOffset = currTexOffset;"); } if (m_useCurvature) { IOUtils.AddFunctionLine(ref m_functionBody, "#ifdef UNITY_PASS_SHADOWCASTER"); IOUtils.AddFunctionLine(ref m_functionBody, "if ( unity_LightShadowBias.z == 0.0 )"); IOUtils.AddFunctionLine(ref m_functionBody, "{"); IOUtils.AddFunctionLine(ref m_functionBody, "#endif"); IOUtils.AddFunctionLine(ref m_functionBody, " if ( result.z > 1 )"); IOUtils.AddFunctionLine(ref m_functionBody, " clip( -1 );"); IOUtils.AddFunctionLine(ref m_functionBody, "#ifdef UNITY_PASS_SHADOWCASTER"); IOUtils.AddFunctionLine(ref m_functionBody, "}"); IOUtils.AddFunctionLine(ref m_functionBody, "#endif"); } if (m_clipEnds) { IOUtils.AddFunctionLine(ref m_functionBody, "result.xy = uvs + finalTexOffset;"); IOUtils.AddFunctionLine(ref m_functionBody, "#ifdef UNITY_PASS_SHADOWCASTER"); IOUtils.AddFunctionLine(ref m_functionBody, "if ( unity_LightShadowBias.z == 0.0 )"); IOUtils.AddFunctionLine(ref m_functionBody, "{"); IOUtils.AddFunctionLine(ref m_functionBody, "#endif"); IOUtils.AddFunctionLine(ref m_functionBody, " if ( result.x < 0 )"); IOUtils.AddFunctionLine(ref m_functionBody, " clip( -1 );"); IOUtils.AddFunctionLine(ref m_functionBody, " if ( result.x > tilling.x )"); IOUtils.AddFunctionLine(ref m_functionBody, " clip( -1 );"); IOUtils.AddFunctionLine(ref m_functionBody, " if ( result.y < 0 )"); IOUtils.AddFunctionLine(ref m_functionBody, " clip( -1 );"); IOUtils.AddFunctionLine(ref m_functionBody, " if ( result.y > tilling.y )"); IOUtils.AddFunctionLine(ref m_functionBody, " clip( -1 );"); IOUtils.AddFunctionLine(ref m_functionBody, "#ifdef UNITY_PASS_SHADOWCASTER"); IOUtils.AddFunctionLine(ref m_functionBody, "}"); IOUtils.AddFunctionLine(ref m_functionBody, "#endif"); IOUtils.AddFunctionLine(ref m_functionBody, "return result.xy;"); } else { IOUtils.AddFunctionLine(ref m_functionBody, "return uvs + finalTexOffset;"); } IOUtils.CloseFunctionBody(ref m_functionBody); }
public override void WriteAdditionalClipboardData(ref string nodeInfo) { base.WriteAdditionalClipboardData(ref nodeInfo); IOUtils.AddFieldValueToString(ref nodeInfo, (m_materialValue != null) ? AssetDatabase.GetAssetPath(m_materialValue) : Constants.NoStringValue); }
public override void WriteToString(ref string nodeInfo, ref string connectionsInfo) { base.WriteToString(ref nodeInfo, ref connectionsInfo); IOUtils.AddFieldValueToString(ref nodeInfo, m_useUnityBranch); }
public override void WriteToString(ref string nodeInfo, ref string connectionsInfo) { base.WriteToString(ref nodeInfo, ref connectionsInfo); IOUtils.AddFieldValueToString(ref nodeInfo, m_defaultValue.r.ToString() + IOUtils.VECTOR_SEPARATOR + m_defaultValue.g.ToString() + IOUtils.VECTOR_SEPARATOR + m_defaultValue.b.ToString() + IOUtils.VECTOR_SEPARATOR + m_defaultValue.a.ToString()); }
public void WriteToString(ref string nodeInfo) { IOUtils.AddFieldValueToString(ref nodeInfo, m_value); IOUtils.AddFieldValueToString(ref nodeInfo, m_active); IOUtils.AddFieldValueToString(ref nodeInfo, m_nodeId); }
public override void WriteAdditionalClipboardData(ref string nodeInfo) { base.WriteAdditionalClipboardData(ref nodeInfo); IOUtils.AddFieldValueToString(ref nodeInfo, IOUtils.ColorToString(m_materialValue)); }
public override void WriteToString(ref string nodeInfo, ref string connectionsInfo) { base.WriteToString(ref nodeInfo, ref connectionsInfo); IOUtils.AddFieldValueToString(ref nodeInfo, m_currentBlendOp); IOUtils.AddFieldValueToString(ref nodeInfo, m_saturate); }
public override void WriteToString(ref string nodeInfo, ref string connectionsInfo) { base.WriteToString(ref nodeInfo, ref connectionsInfo); IOUtils.AddFieldValueToString(ref nodeInfo, m_referenceNodeId); }
public override void WriteToString(ref string nodeInfo, ref string connectionsInfo) { base.WriteToString(ref nodeInfo, ref connectionsInfo); IOUtils.AddFieldValueToString(ref nodeInfo, m_selectedPatternInt); }