Commit 4c0ca847 authored by Julian Schakib's avatar Julian Schakib
Browse files

init campfire

parent f2e04fbb
Pipeline #13832 failed with stage
in 2 minutes and 24 seconds
GRIMM NIGHT
high res 1024^2 environment map
ships as TGA.
By Jockum Skoglund aka hipshot
hipshot@zfight.com
www.zfight.com
Stockholm, 2005 08 25
Modify however you like, just cred me for my work, maybe link to my page.
(Grimm is not a typo of Grim, some people understand the meaning)
\ No newline at end of file
cmake_minimum_required(VERSION 3.0)
project(Campfire)
file(GLOB_RECURSE SOURCES "*.cc" "*.hh" "*.*sh")
add_executable(${PROJECT_NAME} ${SOURCES})
target_link_libraries(${PROJECT_NAME} PUBLIC
glow
glow-extras
glfw
AntTweakBar)
target_compile_options(${PROJECT_NAME} PUBLIC ${GLOW_SAMPLES_DEF_OPTIONS})
set_property(TARGET ${PROJECT_NAME} PROPERTY FOLDER "Samples/Demo")
#include "Campfire.hh"
#include <glm/ext.hpp>
#include <glow/objects/Program.hh>
#include <glow/objects/Shader.hh>
#include <glow/objects/Texture2D.hh>
#include <glow/objects/TextureCubeMap.hh>
#include <glow/objects/VertexArray.hh>
#include <glow/data/ColorSpace.hh>
#include <glow/data/TextureData.hh>
#include <glow/common/scoped_gl.hh>
#include <glow/common/str_utils.hh>
#include <glow-extras/geometry/Cube.hh>
#include <glow-extras/geometry/Quad.hh>
#include <glow-extras/geometry/UVSphere.hh>
#include <AntTweakBar.h>
using namespace glow;
using namespace glow::camera;
void Campfire::init()
{
setGui(GlfwApp::Gui::AntTweakBar);
GlfwApp::init(); // call to base!
mShaderBG = Program::createFromFile(util::pathOf(__FILE__) + "/bg");
mShaderLight = Program::createFromFile(util::pathOf(__FILE__) + "/light");
mShader = Program::createFromFile(util::pathOf(__FILE__) + "/shader");
auto cube = geometry::Cube<>().generate();
mCube = VertexArray::create(cube->getAttributeBuffer("aPosition"), GL_PATCHES);
mCube->setVerticesPerPatch(4);
mQuad = geometry::Quad<>().generate();
mSphere = geometry::UVSphere<>().generate();
mTexAlbedo = Texture2D::createFromFile(util::pathOf(__FILE__) + "/TexturesCom_BareThreadplateFloor_1024_albedo.png", ColorSpace::sRGB);
mTexAO = Texture2D::createFromFile(util::pathOf(__FILE__) + "/TexturesCom_BareThreadplateFloor_1024_ao.png", ColorSpace::Linear);
mTexHeight = Texture2D::createFromFile(util::pathOf(__FILE__) + "/TexturesCom_BareThreadplateFloor_1024_height.png", ColorSpace::Linear);
mTexMetallic = Texture2D::createFromFile(util::pathOf(__FILE__) + "/TexturesCom_BareThreadplateFloor_1024_metallic.png", ColorSpace::Linear);
mTexNormal = Texture2D::createFromFile(util::pathOf(__FILE__) + "/TexturesCom_BareThreadplateFloor_1024_normal.png", ColorSpace::Linear);
mTexRoughness = Texture2D::createFromFile(util::pathOf(__FILE__) + "/TexturesCom_BareThreadplateFloor_1024_roughness.png", ColorSpace::Linear);
auto pbt = util::pathOf(__FILE__) + "/../../../data/cubemap/grimm-night";
mCubeMap = TextureCubeMap::createFromData(TextureData::createFromFileCube( //
pbt + "/posx.tga", //
pbt + "/negx.tga", //
pbt + "/posy.tga", //
pbt + "/negy.tga", //
pbt + "/posz.tga", //
pbt + "/negz.tga", //
ColorSpace::sRGB));
auto cam = getCamera();
cam->setLookAt({2, 2, 2}, {0, 0, 0});
cam->setNearPlane(0.001f);
mLightDir = normalize(glm::vec3(1.0f, 1.0f, -0.5f));
TwAddVarRW(tweakbar(), "Animate", TW_TYPE_BOOLCPP, &mAnimate, "");
TwAddVarRW(tweakbar(), "Light Dir", TW_TYPE_DIR3F, &mLightDir, "group=light ");
TwAddVarRW(tweakbar(), "Light Dis", TW_TYPE_FLOAT, &mLightDis, "group=light step=0.01 min=1.0 max=100.0");
TwAddVarRW(tweakbar(), "Light Radius", TW_TYPE_FLOAT, &mLightRadius, "group=light step=0.01 min=0.01 max=10.0");
TwAddVarRW(tweakbar(), "Use Albedo", TW_TYPE_BOOLCPP, &mUseAlbedo, "group=material ");
TwAddVarRW(tweakbar(), "Use AO", TW_TYPE_BOOLCPP, &mUseAO, "group=material ");
TwAddVarRW(tweakbar(), "Use Height", TW_TYPE_BOOLCPP, &mUseHeight, "group=material ");
TwAddVarRW(tweakbar(), "Use Normal", TW_TYPE_BOOLCPP, &mUseNormal, "group=material ");
TwAddVarRW(tweakbar(), "Use Metallic", TW_TYPE_BOOLCPP, &mUseMetallic, "group=material ");
TwAddVarRW(tweakbar(), "Use Roughness", TW_TYPE_BOOLCPP, &mUseRoughness, "group=material ");
TwAddVarRW(tweakbar(), "Use Reflection", TW_TYPE_BOOLCPP, &mUseReflection, "group=material ");
TwAddVarRW(tweakbar(), "Show Texture #", TW_TYPE_INT32, &mShowTexture, "group=debug min=-1 max=6 ");
TwDefine("Tweakbar size='300 400' valueswidth=140");
}
void Campfire::render(float elapsedSeconds)
{
if (mAnimate)
mRuntime += elapsedSeconds;
// mLightDir = normalize(glm::vec3(1.0f, 1.0f, -0.5f));
auto cam = getCamera();
GLOW_SCOPED(clearColor, 0.00f, 0.33f, 0.66f, 1);
GLOW_SCOPED(enable, GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
{ // bg
auto shader = mShaderBG->use();
GLOW_SCOPED(disable, GL_DEPTH_TEST);
GLOW_SCOPED(disable, GL_CULL_FACE);
shader.setUniform("uInvProj", inverse(cam->getProjectionMatrix()));
shader.setUniform("uInvView", inverse(cam->getViewMatrix()));
shader.setTexture("uTexture", mCubeMap);
mQuad->bind().draw();
}
{ // scene
GLOW_SCOPED(enable, GL_CULL_FACE);
auto shader = mShader->use();
shader.setUniform("uView", cam->getViewMatrix());
shader.setUniform("uProj", cam->getProjectionMatrix());
shader.setUniform("uModel", glm::mat4());
shader.setUniform("uCamPos", cam->getPosition());
// textures
shader.setTexture("uCubeMap", mCubeMap);
shader.setTexture("uTexAlbedo", mTexAlbedo);
shader.setTexture("uTexAO", mTexAO);
shader.setTexture("uTexHeight", mTexHeight);
shader.setTexture("uTexNormal", mTexNormal);
shader.setTexture("uTexRoughness", mTexRoughness);
shader.setTexture("uTexMetallic", mTexMetallic);
shader.setUniform("uShowTexture", mShowTexture);
// displacement mapping
shader.setUniform("uDisplacement", 0.05f);
shader.setUniform("uTessellationLevel", 64.0f);
// shading
shader.setUniform("uUseAlbedo", mUseAlbedo);
shader.setUniform("uUseAO", mUseAO);
shader.setUniform("uUseHeight", mUseHeight);
shader.setUniform("uUseNormal", mUseNormal);
shader.setUniform("uUseMetallic", mUseMetallic);
shader.setUniform("uUseRoughness", mUseRoughness);
shader.setUniform("uUseReflection", mUseReflection);
// lights
shader.setUniform("uLightRadius", mLightRadius);
shader.setUniform("uLightPos", mLightDis * normalize(mLightDir));
shader.setUniform("uModel", rotate(mRuntime, glm::vec3(0, 1, 0)) * translate(glm::vec3(0, 0, 0)));
mCube->bind().draw();
}
// light
{
auto shader = mShaderLight->use();
shader.setUniform("uView", cam->getViewMatrix());
shader.setUniform("uProj", cam->getProjectionMatrix());
shader.setUniform("uModel", translate(mLightDis * normalize(mLightDir)) * scale(glm::vec3(mLightRadius)));
mSphere->bind().draw();
}
}
#pragma once
#include <vector>
#include <glm/ext.hpp>
#include <glow/fwd.hh>
#include <glow/gl.hh>
#include <glow-extras/glfw/GlfwApp.hh>
class Campfire : public glow::glfw::GlfwApp
{
public:
Campfire() : GlfwApp(Gui::AntTweakBar) {}
private:
glow::SharedProgram mShader;
glow::SharedProgram mShaderBG;
glow::SharedProgram mShaderLight;
glow::SharedVertexArray mCube;
glow::SharedVertexArray mQuad;
glow::SharedVertexArray mSphere;
glow::SharedTextureCubeMap mCubeMap;
glow::SharedTexture2D mTexAlbedo;
glow::SharedTexture2D mTexAO;
glow::SharedTexture2D mTexHeight;
glow::SharedTexture2D mTexMetallic;
glow::SharedTexture2D mTexNormal;
glow::SharedTexture2D mTexRoughness;
float mRuntime = 0.0f;
bool mAnimate = false;
glm::vec3 mLightDir = glm::vec3(1, 0, 0);
float mLightDis = 3.0f;
float mLightRadius = 0.5f;
bool mUseAlbedo = true;
bool mUseAO = true;
bool mUseHeight = true;
bool mUseMetallic = true;
bool mUseNormal = true;
bool mUseRoughness = true;
bool mUseReflection = true;
int mShowTexture = -1;
protected:
void init() override;
void render(float elapsedSeconds) override;
};
in vec2 vPosition;
uniform samplerCube uTexture;
uniform mat4 uInvProj;
uniform mat4 uInvView;
out vec3 fColor;
void main() {
//float d = distance(vPosition, vec2(0.5, 0.5));
//d = d * d;
//fColor = mix(vec3(.45), vec3(.2), smoothstep(0.0, 0.4, d));
vec4 near = uInvProj * vec4(vPosition * 2 - 1, 0, 1);
vec4 far = uInvProj * vec4(vPosition * 2 - 1, 0.5, 1);
near /= near.w;
far /= far.w;
near = uInvView * near;
far = uInvView * far;
fColor = texture(uTexture, (far - near).xyz).rgb;
}
in vec2 aPosition;
out vec2 vPosition;
void main() {
vPosition = aPosition;
gl_Position = vec4(vPosition * 2 - 1, 0, 1);
}
out vec3 fColor;
void main()
{
fColor = vec3(1);
}
in vec3 aPosition;
uniform mat4 uView;
uniform mat4 uProj;
uniform mat4 uModel;
void main()
{
gl_Position = uProj * uView * uModel * vec4(aPosition, 1.0);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment