-
Notifications
You must be signed in to change notification settings - Fork 4
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
Joachims bug fixes #8
Open
JoachimBose
wants to merge
2
commits into
main
Choose a base branch
from
Joachims-bug-fixes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ Shader "Custom/BasicVoxelShader" | |
SubShader | ||
{ | ||
|
||
//Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline" "IgnoreProjector" = "True"} | ||
Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline" "IgnoreProjector" = "True"} | ||
Pass | ||
{ | ||
Name "Forward" | ||
|
@@ -21,17 +21,15 @@ Shader "Custom/BasicVoxelShader" | |
Cull[_Cull] | ||
AlphaToMask[_AlphaToMask]*/ | ||
|
||
CGPROGRAM | ||
#pragma target 3.5 | ||
HLSLPROGRAM | ||
#pragma target 4.5 | ||
// use "vert" function as the vertex shader | ||
#pragma vertex VoxelForwardVertex | ||
// use "frag" function as the pixel (fragment) shader | ||
#pragma fragment VoxelForwardFragment | ||
// texture arrays are not available everywhere, | ||
// only compile shader on platforms where they are | ||
#pragma require 2darray | ||
|
||
#include "UnityCG.cginc" | ||
|
||
/* GPU Instancing | ||
#pragma multi_compile_instancing | ||
|
@@ -41,20 +39,18 @@ Shader "Custom/BasicVoxelShader" | |
//#pragma multi_compile_instancing | ||
#pragma multi_compile_instancing | ||
#pragma multi_compile _ DOTS_INSTANCING_ON | ||
//#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl | ||
|
||
//#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Input.hlsl" | ||
|
||
//#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" | ||
|
||
//#include <HLSLSupport.cginc> | ||
//#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" | ||
|
||
//#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" | ||
//#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this be deleted? I prefer not to have commented code unless there is a good reason for it. This comment applies to all added lines with commented code. |
||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" | ||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderVariablesFunctions.hlsl" | ||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Input.hlsl" | ||
//uniform float _uvSizes[2 * 6]; // Needs to be set from C# | ||
|
||
|
||
struct Attributes | ||
{ | ||
int packedData : POSITION; | ||
UNITY_VERTEX_INPUT_INSTANCE_ID | ||
}; | ||
|
||
struct Varyings | ||
|
@@ -63,14 +59,28 @@ Shader "Custom/BasicVoxelShader" | |
//float3 positionWS : TEXCOORD1; | ||
half3 normalWS : TEXCOORD1; | ||
float4 positionHCS : SV_POSITION; | ||
UNITY_VERTEX_INPUT_INSTANCE_ID | ||
}; | ||
|
||
|
||
#ifdef DOTS_INSTANCING_ON | ||
UNITY_DOTS_INSTANCING_START(MaterialPropertyMetadata) | ||
UNITY_DOTS_INSTANCED_PROP(float4, _Color) | ||
UNITY_DOTS_INSTANCING_END(MaterialPropertyMetadata) | ||
#define _Color UNITY_ACCESS_DOTS_INSTANCED_PROP_WITH_DEFAULT(float4, _Color) | ||
#endif | ||
|
||
Varyings VoxelForwardVertex(Attributes input) | ||
{ | ||
|
||
Varyings output = (Varyings)0; | ||
|
||
|
||
UNITY_SETUP_INSTANCE_ID(input); | ||
UNITY_TRANSFER_INSTANCE_ID(input, output); | ||
|
||
//float3 positionOS = float3(float(input.packedData&(255)), float((input.packedData >> 8)&(255)), float((input.packedData >> 16)&(255))); | ||
float4 positionOS = float4(float(input.packedData&(255)), float((input.packedData >> 8)&(255)), float((input.packedData >> 16)&(255)), 1); | ||
int normal = int((input.packedData >> 29)&(7)); | ||
//float3 normalOS; | ||
float4 normalOS; | ||
|
||
if(normal == 0) | ||
|
@@ -115,21 +125,22 @@ Shader "Custom/BasicVoxelShader" | |
|
||
//output.uv = TRANSFORM_TEX(input.texcoord, _BaseMap); | ||
//output.positionWS.xyz = vertexInput.positionWS; | ||
output.positionHCS = UnityObjectToClipPos(positionOS.xyz); | ||
output.positionHCS = GetVertexPositionInputs(positionOS.xyz).positionCS; | ||
output.normalWS = normalOS; | ||
|
||
return output; | ||
} | ||
|
||
UNITY_DECLARE_TEX2DARRAY(_ColourTextures); | ||
//UNITY_DECLARE_TEX2DARRAY(_ColourTextures); | ||
|
||
half4 VoxelForwardFragment(Varyings input) : SV_Target0 | ||
{ | ||
return half4(UNITY_SAMPLE_TEX2DARRAY(_ColourTextures, input.uv).rgb, 1.0); | ||
UNITY_SETUP_INSTANCE_ID(input); | ||
return (1,1,1,1); | ||
} | ||
|
||
|
||
ENDCG | ||
ENDHLSL | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,243 @@ | ||
#ifndef UNIVERSAL_SIMPLE_LIT_PASS_INCLUDED | ||
#define UNIVERSAL_SIMPLE_LIT_PASS_INCLUDED | ||
|
||
//#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" | ||
#if defined(LOD_FADE_CROSSFADE) | ||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/LODCrossFade.hlsl" | ||
#endif | ||
|
||
struct Attributes | ||
{ | ||
int packedData : POSITION; | ||
//float3 normalOS : NORMAL; | ||
//float4 tangentOS : TANGENT; | ||
float2 texcoord : TEXCOORD0; | ||
float2 staticLightmapUV : TEXCOORD1; | ||
float2 dynamicLightmapUV : TEXCOORD2; | ||
UNITY_VERTEX_INPUT_INSTANCE_ID | ||
}; | ||
|
||
struct Varyings | ||
{ | ||
float3 uv : TEXCOORD0; | ||
|
||
float3 positionWS : TEXCOORD1; // xyz: posWS | ||
|
||
#ifdef _NORMALMAP | ||
half4 normalWS : TEXCOORD2; // xyz: normal, w: viewDir.x | ||
half4 tangentWS : TEXCOORD3; // xyz: tangent, w: viewDir.y | ||
half4 bitangentWS : TEXCOORD4; // xyz: bitangent, w: viewDir.z | ||
#else | ||
half3 normalWS : TEXCOORD2; | ||
#endif | ||
|
||
#ifdef _ADDITIONAL_LIGHTS_VERTEX | ||
half4 fogFactorAndVertexLight : TEXCOORD5; // x: fogFactor, yzw: vertex light | ||
#else | ||
half fogFactor : TEXCOORD5; | ||
#endif | ||
|
||
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) | ||
float4 shadowCoord : TEXCOORD6; | ||
#endif | ||
|
||
DECLARE_LIGHTMAP_OR_SH(staticLightmapUV, vertexSH, 7); | ||
|
||
#ifdef DYNAMICLIGHTMAP_ON | ||
float2 dynamicLightmapUV : TEXCOORD8; // Dynamic lightmap UVs | ||
#endif | ||
|
||
float4 positionCS : SV_POSITION; | ||
UNITY_VERTEX_INPUT_INSTANCE_ID | ||
UNITY_VERTEX_OUTPUT_STEREO | ||
}; | ||
|
||
void InitializeInputData(Varyings input, half3 normalTS, out InputData inputData) | ||
{ | ||
inputData = (InputData)0; | ||
|
||
inputData.positionWS = input.positionWS; | ||
|
||
#ifdef _NORMALMAP | ||
half3 viewDirWS = half3(input.normalWS.w, input.tangentWS.w, input.bitangentWS.w); | ||
inputData.tangentToWorld = half3x3(input.tangentWS.xyz, input.bitangentWS.xyz, input.normalWS.xyz); | ||
inputData.normalWS = TransformTangentToWorld(normalTS, inputData.tangentToWorld); | ||
#else | ||
half3 viewDirWS = GetWorldSpaceNormalizeViewDir(inputData.positionWS); | ||
inputData.normalWS = input.normalWS; | ||
#endif | ||
|
||
inputData.normalWS = NormalizeNormalPerPixel(inputData.normalWS); | ||
viewDirWS = SafeNormalize(viewDirWS); | ||
|
||
inputData.viewDirectionWS = viewDirWS; | ||
|
||
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) | ||
inputData.shadowCoord = input.shadowCoord; | ||
#elif defined(MAIN_LIGHT_CALCULATE_SHADOWS) | ||
inputData.shadowCoord = TransformWorldToShadowCoord(inputData.positionWS); | ||
#else | ||
inputData.shadowCoord = float4(0, 0, 0, 0); | ||
#endif | ||
|
||
#ifdef _ADDITIONAL_LIGHTS_VERTEX | ||
inputData.fogCoord = InitializeInputDataFog(float4(inputData.positionWS, 1.0), input.fogFactorAndVertexLight.x); | ||
inputData.vertexLighting = input.fogFactorAndVertexLight.yzw; | ||
#else | ||
inputData.fogCoord = InitializeInputDataFog(float4(inputData.positionWS, 1.0), input.fogFactor); | ||
inputData.vertexLighting = half3(0, 0, 0); | ||
#endif | ||
|
||
#if defined(DYNAMICLIGHTMAP_ON) | ||
inputData.bakedGI = SAMPLE_GI(input.staticLightmapUV, input.dynamicLightmapUV, input.vertexSH, inputData.normalWS); | ||
#else | ||
inputData.bakedGI = SAMPLE_GI(input.staticLightmapUV, input.vertexSH, inputData.normalWS); | ||
#endif | ||
|
||
inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(input.positionCS); | ||
inputData.shadowMask = SAMPLE_SHADOWMASK(input.staticLightmapUV); | ||
|
||
#if defined(DEBUG_DISPLAY) | ||
#if defined(DYNAMICLIGHTMAP_ON) | ||
inputData.dynamicLightmapUV = input.dynamicLightmapUV.xy; | ||
#endif | ||
#if defined(LIGHTMAP_ON) | ||
inputData.staticLightmapUV = input.staticLightmapUV; | ||
#else | ||
inputData.vertexSH = input.vertexSH; | ||
#endif | ||
#endif | ||
} | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
// Vertex and Fragment functions // | ||
/////////////////////////////////////////////////////////////////////////////// | ||
|
||
Varyings VoxelForwardVertex(Attributes input) | ||
{ | ||
Varyings output = (Varyings)0; | ||
|
||
UNITY_SETUP_INSTANCE_ID(input); | ||
UNITY_TRANSFER_INSTANCE_ID(input, output); | ||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); | ||
|
||
float3 positionOS = float3(float(input.packedData&(255)), float((input.packedData >> 8)&(255)), float((input.packedData >> 16)&(255))); | ||
int normal = int((input.packedData >> 29)&(7)); | ||
float3 normalOS; | ||
if(normal == 0) | ||
{ | ||
normalOS = float4(0,1,0,0); | ||
} | ||
else if(normal == 1) | ||
{ | ||
normalOS= float4(0,-1,0,0); | ||
} | ||
else if(normal == 2) | ||
{ | ||
normalOS = float4(1,0,0,0); | ||
} | ||
else if(normal == 3) | ||
{ | ||
normalOS = float4(-1,0,0,0); | ||
} | ||
else if(normal == 4) | ||
{ | ||
normalOS = float4(0,0,1,0); | ||
} | ||
else | ||
{ | ||
normalOS = float4(0,0,-1,0); | ||
} | ||
float4 tangentOS = float4(0,0,0,1); | ||
VertexPositionInputs vertexInput = GetVertexPositionInputs(positionOS); | ||
VertexNormalInputs normalInput = GetVertexNormalInputs(normalOS, tangentOS); | ||
|
||
// 5 bits for textureID | ||
output.uv.z = int((input.packedData >> 24)&(31)); | ||
if (normal < 2) | ||
{ | ||
output.uv.xy = positionOS.xz * float2(_uvSizes[output.uv.z], _uvSizes[output.uv.z+1]); | ||
} | ||
else | ||
{ | ||
output.uv.xy = (normal < 4 ? positionOS.zy : positionOS.xy) * float2(_uvSizes[output.uv.z], _uvSizes[output.uv.z+1]); | ||
} | ||
|
||
#if defined(_FOG_FRAGMENT) | ||
half fogFactor = 0; | ||
#else | ||
half fogFactor = ComputeFogFactor(vertexInput.positionCS.z); | ||
#endif | ||
|
||
//output.uv = TRANSFORM_TEX(input.texcoord, _BaseMap); | ||
output.positionWS.xyz = vertexInput.positionWS; | ||
output.positionCS = vertexInput.positionCS; | ||
|
||
#ifdef _NORMALMAP | ||
half3 viewDirWS = GetWorldSpaceViewDir(vertexInput.positionWS); | ||
output.normalWS = half4(normalInput.normalWS, viewDirWS.x); | ||
output.tangentWS = half4(normalInput.tangentWS, viewDirWS.y); | ||
output.bitangentWS = half4(normalInput.bitangentWS, viewDirWS.z); | ||
#else | ||
output.normalWS = NormalizeNormalPerVertex(normalInput.normalWS); | ||
#endif | ||
|
||
OUTPUT_LIGHTMAP_UV(input.staticLightmapUV, unity_LightmapST, output.staticLightmapUV); | ||
#ifdef DYNAMICLIGHTMAP_ON | ||
output.dynamicLightmapUV = input.dynamicLightmapUV.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw; | ||
#endif | ||
OUTPUT_SH(output.normalWS.xyz, output.vertexSH); | ||
|
||
#ifdef _ADDITIONAL_LIGHTS_VERTEX | ||
half3 vertexLight = VertexLighting(vertexInput.positionWS, normalInput.normalWS); | ||
output.fogFactorAndVertexLight = half4(fogFactor, vertexLight); | ||
#else | ||
output.fogFactor = fogFactor; | ||
#endif | ||
|
||
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) | ||
output.shadowCoord = GetShadowCoord(vertexInput); | ||
#endif | ||
|
||
return output; | ||
} | ||
|
||
void VoxelForwardFragment( | ||
Varyings input | ||
, out half4 outColor : SV_Target0 | ||
#ifdef _WRITE_RENDERING_LAYERS | ||
, out float4 outRenderingLayers : SV_Target1 | ||
#endif | ||
) | ||
{ | ||
UNITY_SETUP_INSTANCE_ID(input); | ||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input); | ||
|
||
SurfaceData surfaceData; | ||
InitializeSimpleLitSurfaceData(input.uv, surfaceData); | ||
|
||
#ifdef LOD_FADE_CROSSFADE | ||
LODFadeCrossFade(input.positionCS); | ||
#endif | ||
|
||
InputData inputData; | ||
InitializeInputData(input, surfaceData.normalTS, inputData); | ||
SETUP_DEBUG_TEXTURE_DATA(inputData, input.uv, _BaseMap); | ||
|
||
#ifdef _DBUFFER | ||
ApplyDecalToSurfaceData(input.positionCS, surfaceData, inputData); | ||
#endif | ||
|
||
half4 color = UniversalFragmentBlinnPhong(inputData, surfaceData); | ||
color.rgb = MixFog(color.rgb, inputData.fogCoord); | ||
color.a = OutputAlpha(color.a, IsSurfaceTypeTransparent(_Surface)); | ||
|
||
outColor = color; | ||
|
||
#ifdef _WRITE_RENDERING_LAYERS | ||
uint renderingLayers = GetMeshRenderingLayer(); | ||
outRenderingLayers = float4(EncodeMeshRenderingLayer(renderingLayers), 0, 0, 0); | ||
#endif | ||
} | ||
|
||
#endif |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does the shader need to be changed? What is the bug?