diff --git a/Working/Game/xleres/Objects/Example/ConvToPBR.tech b/Working/Game/xleres/Objects/Example/ConvToPBR.tech new file mode 100644 index 0000000000..80a0bb9a10 --- /dev/null +++ b/Working/Game/xleres/Objects/Example/ConvToPBR.tech @@ -0,0 +1,997 @@ +// CompoundDocument:1 +#include "game/xleres/System/Prefix.h" + +#include "game/xleres/Nodes/Output.sh" +#include "game/xleres/Nodes/Texture.sh" +#include "game/xleres/Nodes/Basic.sh" +#include "game/xleres/ToolsHelper/DecodeParametersTexture_ColoredSpecular.sh" +#include "game/xleres/Surface.h" +#include "game/xleres/Colour.h" + + +Texture2D SpecularColorTexture; +cbuffer BasicMaterialConstants +{ + float3 MaterialDiffuse; + float MetalMin; + float MetalMax; + float RoughnessMin; + float RoughnessMax; + float SpecularMin; + float SpecularMax; + float Opacity; + float AlphaThreshold; +} +void ConvToPBR(VSOutput geo, out GBufferValues Out) +{ + float3 Output_10_rgb; + float Output_10_alpha; + SampleTextureDiffuse( geo, Output_10_rgb, Output_10_alpha ); + + float Output_13_result; + Output_13_result = MaybeDoAlphaTest( Output_10_alpha, AlphaThreshold ); + + float Output_18_result; + Output_18_result = GetVertexOpacityMultiplier( geo ); + + float Output_14_result; + Output_14_result = Multiply1( Output_13_result, Output_18_result ); + + float Output_8_result; + Output_8_result = Multiply1( Output_14_result, Opacity ); + + float3 Output_15_result; + Output_15_result = GetNormal( geo ); + + float3 Output_11_result; + Output_11_result = MaybeMakeDoubleSided( geo, Output_15_result ); + + float2 Output_16_result; + Output_16_result = GetTexCoord( geo ); + + float4 Output_9_result; + Output_9_result = SampleAnisotropic( SpecularColorTexture, Output_16_result ); + + float2 Output_21_result; + Combine2( SpecularMin, SpecularMax, Output_21_result ); + + float2 Output_22_result; + Combine2( RoughnessMin, RoughnessMax, Output_22_result ); + + float2 Output_23_result; + Combine2( MetalMin, MetalMax, Output_23_result ); + + float3 Output_12_finalDiffuseSample; + CommonMaterialParam Output_12_materialParam; + DecodeParametersTexture_ColoredSpecular( Output_23_result, Output_22_result, Output_21_result, Output_10_rgb, Cast_float4_to_float3(Output_9_result), Output_12_finalDiffuseSample, Output_12_materialParam ); + + float Output_24_result; + Output_24_result = SampleTextureAO( geo ); + + float Output_25_result; + Output_25_result = GetVertexAOMultiplier( geo ); + + float Output_17_result; + Output_17_result = Multiply1( Output_25_result, Output_24_result ); + + float3 Output_19_result; + Output_19_result = SRGBToLinear( MaterialDiffuse ); + + float3 Output_20_result; + Output_20_result = Multiply3( Output_19_result, Output_12_finalDiffuseSample ); + + GBufferValues Output_7_result; + Output_7_result = Output_PerPixel( Output_20_result, Output_11_result, Output_12_materialParam, Output_8_result, 1.0f, Output_17_result, Output_25_result, float3(0,0,0) ); + + Out = Output_7_result; + +} +/* <>--( + + + + + 7 + normalMapAccuracy + 1.0f + + + 7 + transmission + float3(0,0,0) + + + + + 19 + input + {1.f, 1.f, 1.f}c + MaterialDiffuse + + auto + 2 + + + 23 + r + 0.f + MetalMin + + auto + 3 + + + 23 + g + 1.f + MetalMax + + auto + 3 + + + 22 + r + 0.5f + RoughnessMin + + auto + 3 + + + 22 + g + 1.f + RoughnessMax + + auto + 3 + + + 21 + r + 0.1f + SpecularMin + + auto + 3 + + + 21 + g + 1.f + SpecularMax + + auto + 3 + + + 9 + inputTexture + + SpecularColorTexture + + auto + 4 + + + 8 + rhs + 1.f + Opacity + + auto + 5 + + + 13 + alphaThreshold + .33f + AlphaThreshold + + auto + 5 + + + + + 7 + cookedLightOcclusion + 25 + result + float + float + + + + 17 + lhs + 25 + result + float + float + + + + 7 + blendingAlpha + 8 + result + float + float + + + + 12 + specColorSample + 9 + result + float4 + float3 + + + + 13 + alpha + 10 + alpha + float + float + + + + 12 + diffuseSample + 10 + rgb + float3 + float3 + + + + 7 + worldSpaceNormal + 11 + result + float3 + float3 + + + + 7 + material + 12 + materialParam + CommonMaterialParam + CommonMaterialParam + + + + 20 + rhs + 12 + finalDiffuseSample + float3 + float3 + + + + 14 + lhs + 13 + result + float + float + + + + 8 + lhs + 14 + result + float + float + + + + 11 + normal + 15 + result + float3 + float3 + + + + 9 + texCoord + 16 + result + float2 + float2 + + + + 7 + cookedAmbientOcclusion + 17 + result + float + float + + + + 14 + rhs + 18 + result + float + float + + + + 20 + lhs + 19 + result + float3 + float3 + + + + 7 + diffuseAlbedo + 20 + result + float3 + float3 + + + + 12 + specularRange + 21 + result + float2 + float2 + + + + 12 + roughnessRange + 22 + result + float2 + float2 + + + + 12 + metalRange + 23 + result + float2 + float2 + + + + 17 + rhs + 24 + result + float + float + + + + + + game/xleres/Nodes\Output.sh:Output_PerPixel + 7 + Procedure + 0 + + + game/xleres/Nodes\Texture.sh:GetVertexAOMultiplier + 25 + Procedure + 6 + + + game/xleres/Nodes\Basic.sh:Multiply1 + 8 + Procedure + 7 + + + game/xleres/Nodes\Texture.sh:SampleAnisotropic + 9 + Procedure + 8 + + + game/xleres/Nodes\Texture.sh:SampleTextureDiffuse + 10 + Procedure + 9 + + + game/xleres/Nodes\Texture.sh:MaybeMakeDoubleSided + 11 + Procedure + 10 + + + game/xleres/ToolsHelper\DecodeParametersTexture_ColoredSpecular.sh:DecodeParametersTexture_ColoredSpecular + 12 + Procedure + 11 + + + game/xleres/Nodes\Texture.sh:MaybeDoAlphaTest + 13 + Procedure + 12 + + + game/xleres/Nodes\Basic.sh:Multiply1 + 14 + Procedure + 13 + + + game/xleres/Surface.h:GetNormal + 15 + Procedure + 14 + + + game/xleres/Surface.h:GetTexCoord + 16 + Procedure + 15 + + + game/xleres/Nodes\Basic.sh:Multiply1 + 17 + Procedure + 16 + + + game/xleres/Nodes\Texture.sh:GetVertexOpacityMultiplier + 18 + Procedure + 17 + + + game/xleres/Colour.h:SRGBToLinear + 19 + Procedure + 18 + + + game/xleres/Nodes\Basic.sh:Multiply3 + 20 + Procedure + 19 + + + game/xleres/Nodes\Basic.sh:Combine2 + 21 + Procedure + 20 + + + game/xleres/Nodes\Basic.sh:Combine2 + 22 + Procedure + 21 + + + game/xleres/Nodes\Basic.sh:Combine2 + 23 + Procedure + 22 + + + game/xleres/Nodes\Texture.sh:SampleTextureAO + 24 + Procedure + 23 + + + + + 7 + result + Out + + auto + 1 + + + + + Model + result.diffuseAlbedo + 0 + + + Plane2D + + 6 + + + Plane2D + + 7 + + + Plane2D + + 8 + + + Plane2D + + 9 + + + Plane2D + + 10 + + + Plane2D + result2.roughness + 11 + + + Plane2D + + 12 + + + Plane2D + + 13 + + + Plane2D + + 14 + + + Plane2D + + 15 + + + Plane2D + + 16 + + + Plane2D + + 17 + + + Plane2D + + 18 + + + Plane2D + + 19 + + + Plane2D + + 20 + + + Plane2D + + 21 + + + Plane2D + + 22 + + + Plane2D + + 23 + + + + + + 1660 + 207 + + Normal + + + + 2134.90186 + 246.917114 + + Normal + + + + 237 + -201 + + Normal + + + + -614 + -428 + + Normal + + + + -985 + -91 + + Normal + + + + -496 + 643 + + Normal + + + + 773 + 621 + + Collapsed + + + + 377 + 561 + + Collapsed + + + + -476 + -93 + + Normal + + + + -476 + 211 + + Normal + + + + 817 + 180 + + Collapsed + + + + 262 + -31 + + Normal + + + + -74 + 343 + + Collapsed + + + + 188 + 483 + + Collapsed + + + + 656 + 182 + + Collapsed + + + + -862 + 6 + + Collapsed + + + + 1059 + 664 + + Collapsed + + + + -117 + 540 + + Collapsed + + + + 590 + -143 + + Collapsed + + + + 771 + -109 + + Collapsed + + + + -174 + -229 + + Collapsed + + + + -175 + -285 + + Collapsed + + + + -181 + -344 + + Collapsed + + + + 788 + 691 + + Collapsed + + + +)-- */ +/* <>--( + + + true + + + +)-- */ + + + +#include "TextureAlgorithm.h" // for SystemInputs +#include "Lighting/Forward.h" + +#if !((OUTPUT_TEXCOORD==1) && (MAT_ALPHA_TEST==1)) + [earlydepthstencil] +#endif +float4 forward_main(VSOutput geo, SystemInputs sys) : SV_Target0 +{ + // If we're doing to do the alpha threshold test, we + // should try to do as early in the shader as we can! + // Unfortunately, there's no real easy way to do that with + // a node graph here...Unless we create some special #define + // somehow... + + // DoAlphaTest(geo, GetAlphaThreshold()); + + GBufferValues sample; + ConvToPBR(geo, sample); + + float3 directionToEye = 0.0.xxx; + #if (OUTPUT_WORLD_VIEW_VECTOR==1) + directionToEye = normalize(geo.worldViewVector); + #endif + + float4 result = float4( + ResolveLitColor( + sample, directionToEye, GetWorldPosition(geo), + LightScreenDest_Create(int2(geo.position.xy), GetSampleIndex(sys))), 1.f); + + #if OUTPUT_FOG_COLOR == 1 + result.rgb = lerp(geo.fogColor.rgb, result.rgb, geo.fogColor.a); + #endif + + result.a = sample.blendingAlpha; + + #if (OUTPUT_COLOUR>=1) && (MAT_VCOLOR_IS_ANIM_PARAM==0) + result.rgb *= geo.colour.rgb; + #endif + + #if MAT_SKIP_LIGHTING_SCALE==0 + result.rgb *= LightingScale; // (note -- should we scale by this here? when using this shader with a basic lighting pipeline [eg, for material preview], the scale is unwanted) + #endif + return result; +} + + + +#if !((OUTPUT_TEXCOORD==1) && (MAT_ALPHA_TEST==1)) + [earlydepthstencil] +#endif +GBufferEncoded deferred_main(VSOutput geo) +{ + // If we're doing to do the alpha threshold test, we + // should try to do as early in the shader as we can! + // Unfortunately, there's no real easy way to do that with + // a node graph here...Unless we create some special #define + // somehow... + // DoAlphaTest(geo, GetAlphaThreshold()); + GBufferValues result; + ConvToPBR(geo, result); + return Encode(result); +} + + + +#include "game/xleres/Forward/Transparency/util.h" + +float4 io_main(VSOutput geo, SystemInputs sys) : SV_Target0 +{ + float destinationDepth = DuplicateOfDepthBuffer[uint2(geo.position.xy)]; + float ndcComparison = geo.position.z; // / geo.position.w; + if (ndcComparison > destinationDepth) + discard; + + GBufferValues sample; + ConvToPBR(geo, sample); + + // note -- At alpha threshold, we just consider + // it opaque. It's a useful optimisation + // that goes hand in hand with the pre-depth pass. + const float minAlpha = 1.f / 255.f; + const float maxAlpha = 0.95f; // 254.f / 255.f; // AlphaThreshold; + if (sample.blendingAlpha < minAlpha) { + discard; + } + + float4 result = LightSample(sample, geo, sys); + + if (result.a >= maxAlpha) { + return float4(LightingScale * result.rgb, 1.f); // result.a); + } else { + #if !MAT_PREMULTIPLIED_ALPHA + result.rgb *= result.a; + #endif + + OutputFragmentNode(uint2(geo.position.xy), result, ndcComparison); + discard; + return 0.0.xxxx; + } +} + + + +[earlydepthstencil] +float4 stochastic_main(VSOutput geo, + #if (STOCHASTIC_TRANS_PRIMITIVEID==1) + uint primitiveID : SV_PrimitiveID, + #endif + SystemInputs sys) : SV_Target +{ + float occlusion; + uint type = CalculateStochasticPixelType(geo.position, occlusion); + [branch] if (type > 0) { + if (type == 2) return float4(0.0.xxx, 1); // discard; + + // Only need to calculate the "alpha" value for this step... + GBufferValues sample; + ConvToPBR(geo, sample); + return float4(0.0.xxx, sample.blendingAlpha); + } + + GBufferValues sample; + ConvToPBR(geo, sample); + + float4 litValue = LightSample(sample, geo, sys); + return float4((LightingScale * (1.f - occlusion) * litValue.a) * litValue.rgb, litValue.a); +} + + + +#include "Forward/Transparency/depthonlyutil.h" + +#if (STOCHASTIC_TRANS) + + void depthonly_main( + VSOutput geo, uint primitiveID : SV_PrimitiveID, + out uint oCoverage : SV_Coverage + #if (STOCHASTIC_TRANS_PRIMITIVEID==1) + , out uint oPrimId : SV_Target0 + #if (STOCHASTIC_TRANS_OPACITY==1) + , out float oOpacity : SV_Target1 + #endif + #elif (STOCHASTIC_TRANS_OPACITY==1) + , out float oOpacity : SV_Target0 + #endif + + ) + { + GBufferValues sample; + ConvToPBR(geo, sample); + float alpha = sample.blendingAlpha; + + oCoverage = StochasticTransMask(uint2(geo.position.xy), alpha, primitiveID); + #if (STOCHASTIC_TRANS_PRIMITIVEID==1) + oPrimId = primitiveID; + #endif + #if (STOCHASTIC_TRANS_OPACITY==1) + oOpacity = alpha; + #endif + } + +#else + + #if !((OUTPUT_TEXCOORD==1) && ((MAT_ALPHA_TEST==1)||(MAT_ALPHA_TEST_PREDEPTH==1))) + [earlydepthstencil] + #endif + void depthonly_main(VSOutput geo) + { + #if !((OUTPUT_TEXCOORD==1) && ((MAT_ALPHA_TEST==1)||(MAT_ALPHA_TEST_PREDEPTH==1))) + // execute sampling only for discard() events + GBufferValues sample; + ConvToPBR(geo, sample); + #endif + } + +#endif + + +/* <>--( +~Inherit; game/xleres/techniques/illum.tech +~Forward + PixelShader=<.>:forward_main +~Deferred + PixelShader=<.>:deferred_main +~OrderIndependentTransparency + PixelShader=<.>:oi_main +~StochasticTransparency + PixelShader=<.>:stochastic_main +~DepthOnly + PixelShader=<.>:depthonly_main +)--*/ + +/* <>--( +float3 MaterialDiffuse = {1.f, 1.f, 1.f}c; +float MetalMin = 0.f; +float MetalMax = 1.f; +float RoughnessMin = 0.5f; +float RoughnessMax = 1.f; +float SpecularMin = 0.1f; +float SpecularMax = 1.f; +float Opacity = 1.f; +float AlphaThreshold = .33f; + +)--*/ +