Skip to content

Commit

Permalink
feat: remake shaders using shader graph, add masked blend mode
Browse files Browse the repository at this point in the history
  • Loading branch information
GavrilovNI committed Feb 24, 2024
1 parent b1a89e2 commit ed4c5cf
Show file tree
Hide file tree
Showing 11 changed files with 361 additions and 141 deletions.
27 changes: 0 additions & 27 deletions materials/voxel_map.vmat

This file was deleted.

19 changes: 19 additions & 0 deletions materials/voxels_opaque.vmat
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// THIS FILE IS AUTO-GENERATED

Layer0
{
shader "shaders/voxels_opaque.shader"

//---- Texture Filtering ----
F_TEXTURE_FILTERING 3 // Point Sample

Texture "materials/lights/white_color.tga"

//---- Fog ----
g_bFogEnabled "1"

DynamicParams
{
Texture "color"
}
}
22 changes: 22 additions & 0 deletions materials/voxels_translucent.vmat
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// THIS FILE IS AUTO-GENERATED

Layer0
{
shader "shaders/voxels_translucent.shader"

//---- Texture Filtering ----
F_TEXTURE_FILTERING 3 // Point Sample

Texture "materials/default/default_color.tga"

//---- Fog ----
g_bFogEnabled "1"

//---- Translucent ----
g_flOpacityScale "1.000"

DynamicParams
{
Texture "color"
}
}
4 changes: 2 additions & 2 deletions prefabs/Chunk.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
"component_type": "ModelCollider"
},
"InteractionEnabled": true,
"OpaqueVoxelsMaterial": "materials/voxel_map.vmat",
"OpaqueVoxelsMaterial": "materials/voxels_opaque.vmat",
"PhysicsCollider": {
"_type": "component",
"go": "1ce9c04a-c4c3-4e7b-864d-39896d8ed47a",
"component_type": "ModelCollider"
},
"PhysicsEnabled": true,
"RenderingEnabled": true,
"TranslucentVoxelsMaterial": "materials/voxel_map.vmat"
"TranslucentVoxelsMaterial": "materials/voxels_translucent.vmat"
},
{
"__type": "ModelCollider",
Expand Down
4 changes: 2 additions & 2 deletions prefabs/VisualOnlyChunk.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
"component_type": "ModelCollider"
},
"InteractionEnabled": false,
"OpaqueVoxelsMaterial": "materials/voxel_map.vmat",
"OpaqueVoxelsMaterial": "materials/voxels_opaque.vmat",
"PhysicsCollider": {
"_type": "component",
"go": "faa05274-45f8-4747-b98a-6132ac09b0e5",
"component_type": "ModelCollider"
},
"PhysicsEnabled": false,
"RenderingEnabled": true,
"TranslucentVoxelsMaterial": "materials/voxel_map.vmat"
"TranslucentVoxelsMaterial": "materials/voxels_translucent.vmat"
},
{
"__type": "ModelCollider",
Expand Down
4 changes: 2 additions & 2 deletions scenes/main.scene
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@
"__type": "ModelRenderer",
"BodyGroups": 18446744073709551615,
"MaterialGroup": null,
"MaterialOverride": "materials/voxel_map.vmat",
"MaterialOverride": "materials/voxels_translucent.vmat",
"Model": "models/dev/plane.vmdl",
"RenderType": "On",
"Tint": "1,1,1,1"
Expand Down Expand Up @@ -610,6 +610,6 @@
},
"Title": "main",
"Description": "",
"LastSaved": "2024-02-24T02:12:52.7880785\u002B01:00",
"LastSaved": "2024-02-24T20:41:15.2700211\u002B01:00",
"__references": []
}
108 changes: 0 additions & 108 deletions shaders/voxels.shader

This file was deleted.

112 changes: 112 additions & 0 deletions shaders/voxels_opaque.shader
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@

HEADER
{
Description = "";
}

FEATURES
{
#include "common/features.hlsl"
}

MODES
{
VrForward();
Depth();
ToolsVis( S_MODE_TOOLS_VIS );
ToolsWireframe( "vr_tools_wireframe.shader" );
ToolsShadingComplexity( "tools_shading_complexity.shader" );
}

COMMON
{
#ifndef S_ALPHA_TEST
#define S_ALPHA_TEST 0
#endif
#ifndef S_TRANSLUCENT
#define S_TRANSLUCENT 0
#endif

#include "common/shared.hlsl"
#include "procedural.hlsl"

#define S_UV2 1
#define CUSTOM_MATERIAL_INPUTS
}

struct VertexInput
{
#include "common/vertexinput.hlsl"
float4 vColor : COLOR0 < Semantic( Color ); >;
};

struct PixelInput
{
#include "common/pixelinput.hlsl"
float3 vPositionOs : TEXCOORD14;
float3 vNormalOs : TEXCOORD15;
float4 vTangentUOs_flTangentVSign : TANGENT < Semantic( TangentU_SignV ); >;
float4 vColor : COLOR0;
};

VS
{
#include "common/vertex.hlsl"

PixelInput MainVs( VertexInput v )
{
PixelInput i = ProcessVertex( v );
i.vPositionOs = v.vPositionOs.xyz;
i.vColor = v.vColor;

VS_DecodeObjectSpaceNormalAndTangent( v, i.vNormalOs, i.vTangentUOs_flTangentVSign );

return FinalizeVertex( i );
}
}

PS
{
#include "common/pixel.hlsl"

SamplerState g_sSampler0 < Filter( POINT ); AddressU( CLAMP ); AddressV( CLAMP ); >;
CreateInputTexture2D( Texture, Srgb, 8, "None", "_color", ",0/,0/0", Default4( 1.00, 1.00, 1.00, 1.00 ) );
Texture2D g_tTexture < Channel( RGBA, Box( Texture ), Srgb ); OutputFormat( DXT5 ); SrgbRead( True ); >;

float4 MainPs( PixelInput i ) : SV_Target0
{
Material m = Material::Init();
m.Albedo = float3( 1, 1, 1 );
m.Normal = float3( 0, 0, 1 );
m.Roughness = 1;
m.Metalness = 0;
m.AmbientOcclusion = 1;
m.TintMask = 1;
m.Opacity = 1;
m.Emission = float3( 0, 0, 0 );
m.Transmission = 0;

float4 l_0 = Tex2DS( g_tTexture, g_sSampler0, i.vTextureCoords.xy );

m.Albedo = l_0.xyz;
m.Opacity = 1;
m.Roughness = 1;
m.Metalness = 0;
m.AmbientOcclusion = 1;

m.AmbientOcclusion = saturate( m.AmbientOcclusion );
m.Roughness = saturate( m.Roughness );
m.Metalness = saturate( m.Metalness );
m.Opacity = saturate( m.Opacity );

// Result node takes normal as tangent space, convert it to world space now
m.Normal = TransformNormal( m.Normal, i.vNormalWs, i.vTangentUWs, i.vTangentVWs );

// for some toolvis shit
m.WorldTangentU = i.vTangentUWs;
m.WorldTangentV = i.vTangentVWs;
m.TextureCoords = i.vTextureCoords.xy;

return ShadingModelStandard::Shade( i, m );
}
}
43 changes: 43 additions & 0 deletions shaders/voxels_opaque.shdrgrph
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"Model": "models/dev/plane.vmdl",
"Description": "",
"BlendMode": "Opaque",
"nodes": [
{
"_class": "Result",
"DefaultOpacity": 1,
"DefaultRoughness": 1,
"DefaultMetalness": 0,
"DefaultAmbientOcclusion": 1,
"Identifier": "0",
"Position": "592,-96",
"Albedo": {
"Identifier": "1",
"Output": "Result"
}
},
{
"_class": "TextureSampler",
"Image": "materials/lights/white_color.tga",
"Sampler": {
"Filter": "Point",
"AddressU": "Clamp",
"AddressV": "Clamp"
},
"UI": {
"Name": "Texture",
"Default": "1,1,1,1",
"SrgbRead": true,
"PrimaryGroup": {
"Name": ""
},
"SecondaryGroup": {
"Name": ""
},
"CreateInput": "CreateInputTexture2D"
},
"Identifier": "1",
"Position": "352,-96"
}
]
}
Loading

0 comments on commit ed4c5cf

Please sign in to comment.