Skip to content

Commit

Permalink
Adds initial project files.
Browse files Browse the repository at this point in the history
  • Loading branch information
lettier committed Aug 29, 2021
0 parents commit 2970085
Show file tree
Hide file tree
Showing 166 changed files with 19,871 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
images/**
blends/**
*.kra~
*.png~
*main.o*
*3d-game-shaders-for-beginners.o*
*3d-game-shaders-for-beginners*
!blends/*
!blends/mill-scene/mill-scene-low-poly-backup.blend
76 changes: 76 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<p align="center">
<img src="https://i.imgur.com/x8rtGr4.gif" alt="3D Game Shaders For Beginners" title="3D Game Shaders For Beginners">
</p>

# 3D Game Shaders For Beginners

Interested in adding
textures,
lighting,
shadows,
normal maps,
glowing objects,
ambient occlusion,
reflections,
refractions,
and more to your 3D game?
Great!
Below is a collection of shading techniques that will take your game visuals to new heights.
I've explained each technique in such a way that you can take what you learn here and apply/port it to
whatever stack you use—be it Godot, Unity, Unreal, or something else.
For the glue in between the shaders,
I've chosen the fabulous Panda3D game engine and the OpenGL Shading Language (GLSL).
So if that is your stack, then you'll also get the benefit of learning how to use these
shading techniques with Panda3D and OpenGL specifically.

## Table Of Contents

- [Setup](sections/setup.md)
- [Building The Demo](sections/building-the-demo.md)
- [Running The Demo](sections/running-the-demo.md)
- [Reference Frames](sections/reference-frames.md)
- [GLSL](sections/glsl.md)
- [Render To Texture](sections/render-to-texture.md)
- [Texturing](sections/texturing.md)
- [Lighting](sections/lighting.md)
- [Blinn-Phong](sections/blinn-phong.md)
- [Fresnel Factor](sections/fresnel-factor.md)
- [Rim Lighting](sections/rim-lighting.md)
- [Cel Shading](sections/cel-shading.md)
- [Normal Mapping](sections/normal-mapping.md)
- [Deferred Rendering](sections/deferred-rendering.md)
- [Fog](sections/fog.md)
- [Blur](sections/blur.md)
- [Bloom](sections/bloom.md)
- [SSAO](sections/ssao.md)
- [Motion Blur](sections/motion-blur.md)
- [Chromatic Aberration](sections/chromatic-aberration.md)
- [Screen Space Reflection](sections/screen-space-reflection.md)
- [Screen Space Refraction](sections/screen-space-refraction.md)
- [Foam](sections/foam.md)
- [Flow Mapping](sections/flow-mapping.md)
- [Outlining](sections/outlining.md)
- [Depth Of Field](sections/depth-of-field.md)
- [Posterization](sections/posterization.md)
- [Pixelization](sections/pixelization.md)
- [Sharpen](sections/sharpen.md)
- [Dilation](sections/dilation.md)
- [Film Grain](sections/film-grain.md)
- [Lookup Table (LUT)](sections/lookup-table.md)
- [Gamma Correction](sections/gamma-correction.md)

## License

The included license applies only to the software portion of 3D Game Shaders For Beginners—
specifically the `.cxx`, `.vert`, and `.frag` source code files.
No other portion of 3D Game Shaders For Beginners has been licensed for use.

## Attributions

- [Kiwi Soda Font](https://fontenddev.com/fonts/kiwi-soda/)

## Copyright

(C) 2019 David Lettier
<br>
[lettier.com](https://www.lettier.com)
25 changes: 25 additions & 0 deletions demonstration/build-for-linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash

SCRIPT_PATH="$(cd "$(dirname "$0")"; pwd -P)"

g++ \
-Wfatal-errors \
-c $SCRIPT_PATH/src/main.cxx \
-o $SCRIPT_PATH/3d-game-shaders-for-beginners.o \
-std=gnu++11 \
-O3 \
-I/usr/include/python3.9/ \
-I$P3D_INCLUDE_PATH

g++ \
$SCRIPT_PATH/3d-game-shaders-for-beginners.o \
-o $SCRIPT_PATH/3d-game-shaders-for-beginners \
-L$P3D_LIB_PATH \
-lp3framework \
-lpanda \
-lpandafx \
-lpandaexpress \
-lpandaphysics \
-lp3dtoolconfig \
-lp3dtool \
-lpthread
Binary file added demonstration/eggs/mill-scene/banner.bam
Binary file not shown.
Binary file added demonstration/eggs/mill-scene/mill-scene.bam
Binary file not shown.
Binary file added demonstration/eggs/mill-scene/shutters.bam
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added demonstration/eggs/mill-scene/tex/blank.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added demonstration/eggs/mill-scene/tex/low-specular.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added demonstration/eggs/mill-scene/tex/no-specular.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added demonstration/eggs/mill-scene/tex/normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added demonstration/eggs/mill-scene/tex/rock-diffuse.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added demonstration/eggs/mill-scene/tex/water-specular.png
Binary file added demonstration/eggs/mill-scene/weather-vane.bam
Binary file not shown.
Binary file added demonstration/fonts/font.ttf
Binary file not shown.
Binary file added demonstration/images/blank.png
Binary file added demonstration/images/color-noise.png
Binary file added demonstration/images/foam-pattern.png
Binary file added demonstration/images/lookup-table-0.png
Binary file added demonstration/images/lookup-table-1.png
Binary file added demonstration/images/lookup-table-neutral.png
Binary file added demonstration/images/smoke.png
Binary file added demonstration/images/still-flow.png
Binary file added demonstration/images/up-flow.png
48 changes: 48 additions & 0 deletions demonstration/panda3d-prc-file.prc
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
load-display pandagl

audio-library-name p3openal_audio

win-origin -2 -2
win-size 1200 900

fullscreen #f

framebuffer-hardware #t
framebuffer-software #f

framebuffer-srgb #f

depth-bits 1
color-bits 1 1 1
alpha-bits 0
stencil-bits 0
multisamples 0

notify-level warning
default-directnotify-level warning

model-path $MAIN_DIR

want-directtools #f
want-tk #f

want-pstats #f
show-frame-rate-meter #f

use-movietexture #t

hardware-animated-vertices #f

model-cache-dir $XDG_CACHE_HOME/panda3d
model-cache-textures #f

basic-shaders-only #f

gl-coordinate-system default
gl-version 3 2

textures-auto-power-2 1
textures-power-2 down

sync-flip #f
sync-video #f
29 changes: 29 additions & 0 deletions demonstration/shaders/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BSD 3-Clause License

Copyright (c) 2019, David Lettier
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 changes: 31 additions & 0 deletions demonstration/shaders/fragment/base-combine.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
(C) 2019 David Lettier
lettier.com
*/

#version 150

uniform sampler2D baseTexture;
uniform sampler2D refractionTexture;
uniform sampler2D foamTexture;
uniform sampler2D reflectionTexture;
uniform sampler2D specularTexture;

out vec4 fragColor;

void main() {
vec2 texSize = textureSize(baseTexture, 0).xy;
vec2 texCoord = gl_FragCoord.xy / texSize;

vec4 base = texture(baseTexture, texCoord);
vec4 refraction = texture(refractionTexture, texCoord);
vec4 foam = texture(foamTexture, texCoord);
vec4 reflection = texture(reflectionTexture, texCoord);
vec4 specular = texture(specularTexture, texCoord);

fragColor = base;
fragColor.rgb = mix(fragColor.rgb, refraction.rgb, clamp(refraction.a, 0.0, 1.0));
fragColor.rgb = mix(fragColor.rgb, reflection.rgb, clamp(reflection.a, 0.0, 1.0));
fragColor.rgb = mix(fragColor.rgb, foam.rgb, clamp(foam.a, 0.0, 1.0));
fragColor.rgb += (specular.rgb * clamp(specular.a, 0.0, 1.0));
}
Loading

0 comments on commit 2970085

Please sign in to comment.