Skip to content

Commit

Permalink
Merge pull request #9 from wutipong/feature/sample-scene
Browse files Browse the repository at this point in the history
Feature/sample scene
  • Loading branch information
wutipong authored Apr 29, 2024
2 parents 685b741 + 2f3037a commit 836afb4
Show file tree
Hide file tree
Showing 14 changed files with 664 additions and 265 deletions.
20 changes: 18 additions & 2 deletions shaders/FSL/ShaderList.fsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@
#include "basic.frag.fsl"
#end

#vert VR_MULTIVIEW basic.vert
#include "basic.vert.fsl"
#frag shadow.frag
#include "shadow.frag.fsl"
#end

#vert VR_MULTIVIEW sphere.vert
#include "sphere.vert.fsl"
#end

#vert VR_MULTIVIEW quad.vert
#include "quad.vert.fsl"
#end

#vert VR_MULTIVIEW sphere_shadow.vert
#include "sphere_shadow.vert.fsl"
#end

#vert VR_MULTIVIEW quad_shadow.vert
#include "quad_shadow.vert.fsl"
#end
43 changes: 16 additions & 27 deletions shaders/FSL/basic.frag.fsl
Original file line number Diff line number Diff line change
@@ -1,38 +1,27 @@
/*
* Copyright (c) 2017-2022 The Forge Interactive Inc.
*
* This file is part of The-Forge
* (see https://github.com/ConfettiFX/The-Forge).
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

// Shader for simple shading with a point light
// for planets in Unit Test 12 - Transformations
RES(Tex2D(float), lightMap, UPDATE_FREQ_NONE, t0, binding = 0);
RES(SamplerState, uSampler, UPDATE_FREQ_NONE, s0, binding = 1);

STRUCT(VSOutput)
{
DATA(float4, Position, SV_Position);
DATA(float4, Color, COLOR);
DATA(float2, LightmapPos, TEXCOORD0);
DATA(float, LightmapHeight, TEXCOORD1);
};

float4 PS_MAIN( VSOutput In )
float4 PS_MAIN(VSOutput In)
{
INIT_MAIN;

float2 coord = (In.LightmapPos + float2(1, 1)) / float2(2, 2);
coord.y = 1 - coord.y;

float4 litDepth = SampleTex2D(Get(lightMap), Get(uSampler), coord);

if (litDepth.x > In.LightmapHeight + 0.05)
{
In.Color -= float4(0.8, 0.8, 0.8, 0.0);
}

RETURN(In.Color);
}
75 changes: 0 additions & 75 deletions shaders/FSL/basic.vert.fsl

This file was deleted.

23 changes: 23 additions & 0 deletions shaders/FSL/quad.vert.fsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "quad_resource.fsl"

VSOutput VS_MAIN(VSInput In, SV_InstanceID(uint) InstanceID)
{
INIT_MAIN;
VSOutput Out;

#if VR_MULTIVIEW_ENABLED
float4x4 wvp = mul(Get(mvp)[VR_VIEW_ID], Get(toWorld));
#else
float4x4 wvp = mul(Get(mvp), Get(toWorld));
#endif
Out.Position = mul(wvp, float4(In.Position.xyz, 1.0f));
Out.Color = Get(color);

float4x4 lightWVP = mul(Get(lightProjView), Get(toWorld));
float4 lightSpacePos = mul(lightWVP, float4(In.Position.xyz, 1.0f));

Out.LightmapPos = lightSpacePos.xy;
Out.LightmapHeight = lightSpacePos.z;

RETURN(Out);
}
30 changes: 30 additions & 0 deletions shaders/FSL/quad_resource.fsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef QUAD_RESOURCE
#define QUAD_RESOURCE

CBUFFER(uniformBlock, UPDATE_FREQ_PER_FRAME, b0, binding = 0)
{
#if VR_MULTIVIEW_ENABLED
DATA(float4x4, mvp[VR_MULTIVIEW_COUNT], None);
#else
DATA(float4x4, mvp, None);
#endif
DATA(float4x4, lightProjView, None);
DATA(float4x4, toWorld, None);
DATA(float4, color, None);
};

STRUCT(VSInput)
{
DATA(float3, Position, POSITION);
DATA(float3, Normal, NORMAL);
};

STRUCT(VSOutput)
{
DATA(float4, Position, SV_Position);
DATA(float4, Color, COLOR);
DATA(float2, LightmapPos, TEXCOORD0);
DATA(float, LightmapHeight, TEXCOORD1);
};

#endif
14 changes: 14 additions & 0 deletions shaders/FSL/quad_shadow.vert.fsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "quad_resource.fsl"

VSOutput VS_MAIN(VSInput In, SV_InstanceID(uint) InstanceID)
{
INIT_MAIN;
VSOutput Out;

float4x4 tempMat = mul(Get(lightProjView), Get(toWorld));

Out.Position = mul(tempMat, float4(In.Position.xyz, 1.0f));
Out.Color = Get(color);

RETURN(Out);
}
56 changes: 0 additions & 56 deletions shaders/FSL/resources.h.fsl

This file was deleted.

5 changes: 5 additions & 0 deletions shaders/FSL/shadow.frag.fsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
void PS_MAIN()
{
INIT_MAIN;
RETURN();
}
23 changes: 23 additions & 0 deletions shaders/FSL/sphere.vert.fsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "sphere_resource.fsl"

VSOutput VS_MAIN(VSInput In, SV_InstanceID(uint) InstanceID)
{
INIT_MAIN;
VSOutput Out;

#if VR_MULTIVIEW_ENABLED
float4x4 wvp = mul(Get(mvp)[VR_VIEW_ID], Get(toWorld)[InstanceID]);
#else
float4x4 wvp = mul(Get(mvp), Get(toWorld)[InstanceID]);
#endif
Out.Position = mul(wvp, float4(In.Position.xyz, 1.0f));
Out.Color = Get(color)[InstanceID];

float4x4 lightWVP = mul(Get(lightProjView), Get(toWorld)[InstanceID]);
float4 lightSpacePos = mul(lightWVP, float4(In.Position.xyz, 1.0f));

Out.LightmapPos = lightSpacePos.xy;
Out.LightmapHeight = lightSpacePos.z;

RETURN(Out);
}
35 changes: 35 additions & 0 deletions shaders/FSL/sphere_resource.fsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#ifndef SPHERE_RESOURCE
#define SPHERE_RESOURCE

#ifndef MAX_PLANETS
#define MAX_PLANETS 768
#endif

CBUFFER(uniformBlock, UPDATE_FREQ_PER_FRAME, b0, binding = 0)
{
#if VR_MULTIVIEW_ENABLED
DATA(float4x4, mvp[VR_MULTIVIEW_COUNT], None);
#else
DATA(float4x4, mvp, None);
#endif
DATA(float4x4, lightProjView, None);

DATA(float4x4, toWorld[MAX_PLANETS], None);
DATA(float4, color[MAX_PLANETS], None);
};

STRUCT(VSInput)
{
DATA(float3, Position, POSITION);
DATA(float3, Normal, NORMAL);
};

STRUCT(VSOutput)
{
DATA(float4, Position, SV_Position);
DATA(float4, Color, COLOR);
DATA(float2, LightmapPos, TEXCOORD0);
DATA(float, LightmapHeight, TEXCOORD1);
};

#endif
13 changes: 13 additions & 0 deletions shaders/FSL/sphere_shadow.vert.fsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "sphere_resource.fsl"

VSOutput VS_MAIN(VSInput In, SV_InstanceID(uint) InstanceID)
{
INIT_MAIN;
VSOutput Out;

float4x4 tempMat = mul(Get(lightProjView), Get(toWorld)[InstanceID]);
Out.Position = mul(tempMat, float4(In.Position.xyz, 1.0f));
Out.Color = Get(color)[InstanceID];

RETURN(Out);
}
Loading

0 comments on commit 836afb4

Please sign in to comment.