Skip to content

Commit

Permalink
Merge pull request #139 from Algoryx/feature/cable-instanced-renderin…
Browse files Browse the repository at this point in the history
…g-update

Feature/cable instanced rendering update
  • Loading branch information
FilipAlg authored Dec 20, 2023
2 parents 5972e5c + 68e2d77 commit 07d97ef
Show file tree
Hide file tree
Showing 16 changed files with 908 additions and 345 deletions.
400 changes: 301 additions & 99 deletions AGXUnity/Rendering/CableRenderer.cs

Large diffs are not rendered by default.

227 changes: 0 additions & 227 deletions AGXUnity/Rendering/CableRendererFallback.cs

This file was deleted.

59 changes: 57 additions & 2 deletions AGXUnity/Utils/RenderingUtils.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Linq;
using UnityEngine;
using UnityEngine.Rendering;

Expand Down Expand Up @@ -32,6 +33,59 @@ public static PipelineType DetectPipeline()
return PipelineType.BuiltIn;
}

/// <summary>
/// Checks whether the material supports a given pipeline type.
/// Some assumptions are made here.
/// If we don't recognize the pipeline type we assume that the material does
/// not support the pipeline. Similarly we assume that all materials support
/// the built-in pipeline. This is done since it is not possible to easily tell
/// if a given material is supported and the chance of having a HDRP or URP material
/// being used is quite small since project conversions to the Built-in pipeline
/// is not supported by Unity.
///
/// This works by checking whether any subshader defines the RenderPipeline
/// tag and if so, compares the value to a set of supported identifiers:
/// For HDRP:
/// - HDRenderPipeline
/// - HighDefinitionRenderPipeline
/// For URP:
/// - UniversalRenderPipeline
/// </summary>
/// <param name="pipelineType">The pipeline to check for support against</param>
/// <returns>true if the specified pipeline is supported, false otherwise</returns>
public static bool SupportsPipeline( this Material mat, PipelineType pipelineType )
{
if ( mat.shader.name == "Hidden/InternalErrorShader" )
return false;
if ( pipelineType == PipelineType.Unsupported )
return false;
if ( pipelineType == PipelineType.BuiltIn )
return true;

string[] supportedTags = new string[0];
if ( pipelineType == PipelineType.HDRP ) {
supportedTags = new string[]
{
"HDRenderPipeline",
"HighDefinitionRenderPipeline"
};
}
if ( pipelineType == PipelineType.Universal ) {
supportedTags = new string[] {
"UniversalRenderPipeline",
"UniversalPipeline"
};
}

for ( int i = 0; i < mat.shader.subshaderCount; i++ ) {
var tagName = mat.shader.FindSubshaderTagValue( i, new ShaderTagId( "RenderPipeline" ) ).name;
if ( supportedTags.Contains( tagName ) )
return true;
}

return false;
}

/// <summary>
/// Check if the given camera should render at this point in time.
/// This should be used as an early-out in custom render callbacks to avoid rendering dynamic objects in
Expand All @@ -45,12 +99,13 @@ public static PipelineType DetectPipeline()
public static bool CameraShouldRender( Camera cam, GameObject allowedPrefabObject = null, bool includeInPreview = false )
{
// Only render preview if specified in flag
if ( cam.cameraType == CameraType.Preview)
if ( cam.cameraType == CameraType.Preview )
return includeInPreview;

// Render all except SceneView which require additional checks for prefab stage
if ( cam.cameraType != CameraType.SceneView )
return PrefabUtils.IsNonAssetInstance( allowedPrefabObject );
return ( !PrefabUtils.IsPrefabInstance( allowedPrefabObject ) && !PrefabUtils.IsPartOfEditingPrefab( allowedPrefabObject ) ) ||
PrefabUtils.IsNonAssetInstance( allowedPrefabObject );

// Only render in prefab stage if allowed object is present in it.
if ( PrefabUtils.IsEditingPrefab )
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Editor/AGXUnityEditor/IO/InputAGXFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Linq;
using UnityEditor;
using UnityEngine;
using AGXUnity.Utils;
using Node = AGXUnityEditor.IO.InputAGXFileTreeNode;
using Tree = AGXUnityEditor.IO.InputAGXFileTree;

Expand Down
Loading

0 comments on commit 07d97ef

Please sign in to comment.