Skip to content
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

Jesse/feature/transp emiss vertex attribs #28

Merged
merged 15 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/tools/voxel_synthesis_rule_baker/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,7 @@ BONSAI_API_MAIN_THREAD_INIT_CALLBACK()
ChunkData->Dim,
VoxOffset, VoxOffset+Global_TileDim,
&TileEntity->Model.Mesh,
&TileEntity->Model.TransparentMesh,
GetTranArena(),
VoxData->Palette );

Expand Down
6 changes: 3 additions & 3 deletions examples/turn_based/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,19 +254,19 @@ BONSAI_API_MAIN_THREAD_CALLBACK()

if (Input->R.Clicked)
{
DoSplotion(Resources, PickCP, 4.f, &Global_GameEntropy, GetTranArena());
DoSplotion(Resources, PickCP, 5.f, &Global_GameEntropy, GetTranArena());
/* DoIceBlock(Resources, &Pick, PickCP, 4.f, GetTranArena()); */
}

if (Input->T.Clicked)
{
DoSplotion(Resources, PickCP, 6.f, &Global_GameEntropy, GetTranArena());
DoSplotion(Resources, PickCP, 7.f, &Global_GameEntropy, GetTranArena());
/* DoIceBlock(Resources, &Pick, PickCP, 6.f, GetTranArena()); */
}

if (Input->Y.Clicked)
{
DoSplotion(Resources, PickCP, 8.f, &Global_GameEntropy,GetTranArena());
DoSplotion(Resources, PickCP, 9.f, &Global_GameEntropy,GetTranArena());
/* DoIceBlock(Resources, &Pick, PickCP, 8.f, GetTranArena()); */
}

Expand Down
2 changes: 1 addition & 1 deletion external/bonsai_stdlib
11 changes: 11 additions & 0 deletions generated/gen_constructor_vertex_material.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
link_internal vertex_material
VertexMaterial( v3 Color , f32 Transparency , f32 Emission )
{
vertex_material Reuslt = {
.Color = Color,
.Transparency = Transparency,
/* .Emission = Emission */
};
return Reuslt;
}

2 changes: 1 addition & 1 deletion jesse.make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
./make.sh $OPT \
BuildSingleExample examples/transparency \
BuildSingleExample examples/turn_based \
BuildSingleExample examples/the_wanderer \
BuildExecutables \
BuildDebugSystem \
# BuildSingleExample examples/blank_project \
# BuildSingleExample examples/the_wanderer \
# # BuildTests \
# # BuildSingleExample examples/turn_based2

Expand Down
15 changes: 9 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ Bonsai is a 3D voxel-based engine built with the intention of writing both
fast-paced arcade games and tile/turn-based RPGs

Bonsai, and nearly all it's dependencies, are written completely from scratch.
The one external dependency is the C runtime library for startup, and a small
One external dependency is the C runtime library for startup, and a small
handful of trig functions (sin, cos, atan2). I have a back-burner task to
remove the CRT entirely, though it's unclear when/if I'll get around to it.

The only requirements to build and run Bonsai are an OpenGL 3.3+ driver, C++
compiler, and a few appropriate system headers.


## Renderer Features

* Deferred Shading
Expand Down Expand Up @@ -41,6 +40,12 @@ compiler, and a few appropriate system headers.
* Context Switches (windows only)
* Physical Core (windows only)

# Getting Started

## Building

See the docs on the [build process](docs/01_build_process.md).

# Wishlist

-------------------------------------------------------------------------------
Expand All @@ -56,6 +61,8 @@ compiler, and a few appropriate system headers.

[ ] FXAA : http://blog.simonrodriguez.fr/articles/2016/07/implementing_fxaa.html

[ ] Water : https://www.youtube.com/watch?v=5yhDb9dzJ58

-------------------------------------------------------------------------------
## Terrain Generation

Expand All @@ -81,7 +88,3 @@ compiler, and a few appropriate system headers.
[ ] Octree ? https://graphics.tudelft.nl/Publications-new/2020/CBE20/ModifyingCompressedVoxels-main.pdf

[ ] Better floating-point rng : https://www.corsix.org/content/higher-quality-random-floats

# Building

See the docs on the [build process](docs/01_build_process.md).
32 changes: 22 additions & 10 deletions shaders/3DTransparency.fragmentshader
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@

in vec3 vertexP_worldspace;
in vec3 vertexN_worldspace;
in vec4 MaterialColor;
in vec3 WorldP;
in vec3 Normal;
in vec3 MaterialColor;
in vec2 TransEmiss;

uniform sampler2D gBufferDepthTexture;

uniform bool BravoilMyersOIT;
uniform bool BravoilMcGuireOIT;

layout (location = 0) out vec4 ColorAccumulation;
layout (location = 1) out vec4 Count;
layout (location = 1) out vec2 Count;


float Far = 5000.f;
Expand Down Expand Up @@ -68,18 +69,25 @@ void main()
float gBufferDepth = texture(gBufferDepthTexture, UV).r;
float FragDepth = gl_FragCoord.z;

float Alpha = TransEmiss.x;
float Emission = TransEmiss.y;
/* ColorAccumulation = v4(Alpha, Emission, 0.f, 1.f); */
/* ColorAccumulation = v4(WorldP, 1.f); */
/* ColorAccumulation = v4(Normal, 1.f); */
/* ColorAccumulation = v4(MaterialColor, 1.f); */
/* Count = V4(Alpha); */
/* return; */

if (FragDepth < gBufferDepth)
{
if (BravoilMyersOIT)
{
ColorAccumulation = MaterialColor * MaterialColor.a;
Count = V4(1);
ColorAccumulation = v4(MaterialColor * Alpha, Alpha);
Count = V2(1.f);
}

if (BravoilMcGuireOIT)
{
r32 Alpha = MaterialColor.a;

/* ColorAccumulation = MaterialColor * Eq7(Linearize(FragDepth, 500.f, 0.1f), Alpha); */
/* ColorAccumulation = MaterialColor * Eq7(FragDepth, Alpha); */
/* ColorAccumulation.rgb = MaterialColor.rgb * Linearize(FragDepth, 800.f, 0.1f); */
Expand All @@ -90,15 +98,19 @@ void main()

float AttenuatedAlpha = Alpha * DepthAtten;

ColorAccumulation.rgb = MaterialColor.rgb * Alpha;
ColorAccumulation.rgb = MaterialColor * Alpha;
/* ColorAccumulation.rgb = MaterialColor.rgb * AttenuatedAlpha; */
ColorAccumulation.a = AttenuatedAlpha;

/* ColorAccumulation = MaterialColor * FragDepth; */
/* ColorAccumulation = MaterialColor * Eq10(FragDepth, Alpha); */

/* Count = -v4(1.f-Alpha); */
Count = V4(Alpha);
/* Count = V4(0.f, 0.f, 0.f, Alpha); */
/* Count = V4(0.f, 0.f, 0.f, Alpha); */
Count.r = Alpha;
Count.g = Emission * Alpha;
/* Count = V4(Alpha, Emission, 0.f 0.f); */
/* Count = -V4(ColorAccumulation.a); */
/* Count = -V4(1.f-(Alpha*DepthAtten)); */
}
Expand Down
37 changes: 24 additions & 13 deletions shaders/Lighting.fragmentshader
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ void main()
ivec2 texelCoord = ivec2(gBufferUV*gBufferTextureDim);
vec4 FragPosition = texelFetch(gPosition, texelCoord, 0);

vec4 AccumTex = texture(TransparencyAccum, gBufferUV);
float AccumCountTex = texture(TransparencyCount, gBufferUV).r;
vec4 TransAccum = texture(TransparencyAccum, gBufferUV);
float TransAccumCount = texture(TransparencyCount, gBufferUV).r;
float TransAccumEmission = texture(TransparencyCount, gBufferUV).g;

vec3 AmbientLightContrib = SunColor*0.06f;
vec3 KeyLightContrib = V3(0.f);
Expand All @@ -99,7 +100,7 @@ void main()
vec4 gColorTexel = texelFetch(gColor, texelCoord, 0);

vec3 Diffuse = gColorTexel.rgb;
float Emission = gColorTexel.a;
/* float Emission = gColorTexel.a; */

/* Diffuse *= Emission; */

Expand Down Expand Up @@ -304,14 +305,14 @@ void main()

if (BravoilMyersOIT)
{
/* TransparencyContrib = BravoilMyersWeightedAverage(AccumTex, AccumCountTex); */
/* TransparencyContrib = BravoilMyersWeightedAverage(TransAccum, TransAccumCount); */

float Count = max(1.f, AccumCountTex);
float Count = max(1.f, TransAccumCount);

// Have to clamp because this is > 1.f for emissive surfaces, which breaks the following equation
float Alpha = clamp(AccumTex.a, 0.f, 1.f);
float Alpha = clamp(TransAccum.a, 0.f, 1.f);

v3 ColorResult = AccumTex.rgb/max(AccumTex.a, 0.00001f);
v3 ColorResult = TransAccum.rgb/max(TransAccum.a, 0.00001f);
float AlphaResult = pow(max(0.0, 1.0-(Alpha/Count)), Count);

TransparencyContrib = v3(ColorResult * AlphaResult);
Expand All @@ -321,13 +322,22 @@ void main()

if (BravoilMcGuireOIT)
{
float Revealage = clamp(AccumCountTex, 0.f, 1.f);
float Coverage = 1.f-Revealage;
TransparencyContrib = (AccumTex.rgb / clamp(AccumTex.a, 1e-4, 5e4)) * Coverage;
float Coverage = clamp(TransAccumCount, 0.f, 1.f);
/* float Coverage = Revealage; */
TransparencyContrib = (TransAccum.rgb / clamp(TransAccum.a, 1e-4, 5e4));
/* TransparencyContrib = (TransAccum.rgb / clamp(TransAccum.a, 1e-4, 5e4)) * Coverage; */

float LightTransmission = length(KeyLightContrib + BackLightContrib + PointLightsContrib + AmbientLightContrib);
float LightEmission = TransAccumEmission;

TransparencyContrib *= LightTransmission;
/* out_LightColor = V4(TransAccumEmission, 0.f, 0.f, 1.f); */
/* out_LightColor = V4(LightTransmission, 0.f, 0.f, 1.f); */
/* out_LightColor = V4(LightEmission, 0.f, 0.f, 1.f); */
/* out_LightColor = V4(max(LightTransmission, LightEmission), 0.f, 0.f, 1.f); */
/* return; */

TransparencyContrib *= max(LightTransmission, LightEmission);
/* TransparencyContrib *= LightEmission; */

/* out_LightColor = vec4( TotalLight + TransparencyContrib*LightTransmission, 1.f); */
/* out_LightColor = vec4(Revealage, 0.f, 0.f, 1.f); */
Expand All @@ -336,10 +346,11 @@ void main()
}

out_LightColor = V4(TotalLight + TransparencyContrib, 1.f);
/* out_LightColor = V4(Emission, 0.f, 0.f, 1.f); */
/* return; */



if (UseLightingBloom) { BloomColor = TotalLight + (Emission*Diffuse) + TransparencyContrib.rgb; }
if (UseLightingBloom) { BloomColor = TotalLight + TransparencyContrib.rgb; }

/* else { BloomColor = vec3(0.0f, 0.0f, 0.0f); } */

Expand Down
9 changes: 5 additions & 4 deletions shaders/gBuffer.fragmentshader
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

in vec3 vertexP_worldspace;
in vec3 vertexN_worldspace;
in vec4 MaterialColor;
in v3 vertexP_worldspace;
in v3 vertexN_worldspace;
in v3 MaterialColor;
in v2 TransEmiss;

layout (location = 0) out vec4 gColor;
layout (location = 1) out vec3 gNormal;
Expand Down Expand Up @@ -71,7 +72,7 @@ void main()
gPosition.w = Linearize(gl_FragCoord.z); // Depth
gNormal = vertexN_worldspace;

vec4 FinalColor = MaterialColor;
vec4 FinalColor = vec4(MaterialColor, 1.f);

#if 0
{
Expand Down
7 changes: 5 additions & 2 deletions shaders/gBuffer.vertexshader
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
layout(location = 0) in vec3 vertexPosition_modelspace;
layout(location = 1) in vec3 vertexNormal_modelspace;
layout(location = 2) in vec4 vertexColor;
layout(location = 2) in vec3 vertexColor;
layout(location = 3) in vec2 in_TransEmiss;

out vec3 vertexP_worldspace;
out vec3 vertexN_worldspace;
out vec4 MaterialColor;
out vec3 MaterialColor;
out vec2 TransEmiss;

uniform mat4 ViewProjection;
uniform mat4 Model;

void main()
{
MaterialColor = vertexColor;
TransEmiss = in_TransEmiss;

vertexP_worldspace = vec4(Model * vec4(vertexPosition_modelspace, 1)).xyz;
vertexN_worldspace = vec4(Model * vec4(vertexNormal_modelspace, 1)).xyz;
Expand Down
Loading