poprawki - dodanie opcji przesuniecia bąbla

This commit is contained in:
XsedoX 2023-02-10 21:01:44 +01:00
parent a2b4475590
commit 8bfb2f8823
35 changed files with 422 additions and 44 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -2,7 +2,7 @@
<Project> <Project>
<ProjectOutputs> <ProjectOutputs>
<ProjectOutput> <ProjectOutput>
<FullPath>C:\Users\Anna Niczyporuk\source\repos\GRK_Project\Debug\grk-cw9.exe</FullPath> <FullPath>C:\Users\sjule\source\repos\GRK_Project\Debug\grk-cw9.exe</FullPath>
</ProjectOutput> </ProjectOutput>
</ProjectOutputs> </ProjectOutputs>
<ContentFiles /> <ContentFiles />

View File

@ -1,47 +1,48 @@
 main.cpp  main.cpp
C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\shared\minwindef.h(130,1): warning C4005: 'APIENTRY': macro redefinition C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\shared\minwindef.h(130,1): warning C4005: 'APIENTRY': macro redefinition
C:\Users\Anna Niczyporuk\source\repos\GRK_Project\dependencies\glfw-3.3.8.bin.WIN32\include\GLFW\glfw3.h(123): message : see previous definition of 'APIENTRY' C:\Users\sjule\source\repos\GRK_Project\dependencies\glfw-3.3.8.bin.WIN32\include\GLFW\glfw3.h(123,1): message : see previous definition of 'APIENTRY'
C:\Users\Anna Niczyporuk\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(96,30): warning C4305: 'initializing': truncation from 'double' to 'float' C:\Users\sjule\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(108,30): warning C4305: 'initializing': truncation from 'double' to 'float'
C:\Users\Anna Niczyporuk\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(110,17): warning C4101: 'data': unreferenced local variable C:\Users\sjule\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(122,17): warning C4101: 'data': unreferenced local variable
C:\Users\Anna Niczyporuk\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(135,38): warning C4305: '=': truncation from 'double' to 'float' C:\Users\sjule\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(147,38): warning C4305: '=': truncation from 'double' to 'float'
C:\Users\Anna Niczyporuk\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(164,16): warning C4305: 'initializing': truncation from 'double' to 'float' C:\Users\sjule\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(176,16): warning C4305: 'initializing': truncation from 'double' to 'float'
C:\Users\Anna Niczyporuk\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(224,13): warning C4244: 'initializing': conversion from 'double' to 'float', possible loss of data C:\Users\sjule\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(235,13): warning C4244: 'initializing': conversion from 'double' to 'float', possible loss of data
C:\Users\Anna Niczyporuk\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(240,98): warning C4305: 'argument': truncation from 'double' to 'T' C:\Users\sjule\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(243,73): warning C4244: 'argument': conversion from 'int' to 'GLfloat', possible loss of data
C:\Users\sjule\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(243,66): warning C4244: 'argument': conversion from 'int' to 'GLfloat', possible loss of data
C:\Users\sjule\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(258,13): warning C4244: 'initializing': conversion from 'double' to 'float', possible loss of data
C:\Users\sjule\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(274,98): warning C4305: 'argument': truncation from 'double' to 'T'
with with
[ [
T=float T=float
] ]
C:\Users\Anna Niczyporuk\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(243,68): warning C4305: 'argument': truncation from 'double' to 'T' C:\Users\sjule\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(277,68): warning C4305: 'argument': truncation from 'double' to 'T'
with with
[ [
T=float T=float
] ]
C:\Users\Anna Niczyporuk\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(303,13): warning C4244: 'initializing': conversion from 'double' to 'float', possible loss of data C:\Users\sjule\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(337,13): warning C4244: 'initializing': conversion from 'double' to 'float', possible loss of data
C:\Users\Anna Niczyporuk\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(311,108): warning C4305: 'argument': truncation from 'double' to 'T' C:\Users\sjule\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(346,108): warning C4305: 'argument': truncation from 'double' to 'T'
with with
[ [
T=float T=float
] ]
C:\Users\Anna Niczyporuk\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(319,87): warning C4305: 'argument': truncation from 'double' to 'T' C:\Users\sjule\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(353,92): warning C4305: 'argument': truncation from 'double' to 'T'
with with
[ [
T=float T=float
] ]
C:\Users\Anna Niczyporuk\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(319,223): warning C4305: 'argument': truncation from 'double' to 'float' C:\Users\sjule\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(354,92): warning C4305: 'argument': truncation from 'double' to 'T'
C:\Users\Anna Niczyporuk\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(322,59): warning C4305: 'argument': truncation from 'double' to 'T'
with with
[ [
T=float T=float
] ]
C:\Users\Anna Niczyporuk\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(323,37): warning C4305: 'argument': truncation from 'double' to 'float' C:\Users\sjule\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(395,2): warning C4305: 'argument': truncation from 'double' to 'float'
C:\Users\Anna Niczyporuk\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(355,2): warning C4305: 'argument': truncation from 'double' to 'float' C:\Users\sjule\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(442,108): warning C4305: 'argument': truncation from 'double' to 'T'
C:\Users\Anna Niczyporuk\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(403,108): warning C4305: 'argument': truncation from 'double' to 'T'
with with
[ [
T=float T=float
] ]
C:\Users\Anna Niczyporuk\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(479,21): warning C4305: '-=': truncation from 'double' to 'float' C:\Users\sjule\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(521,21): warning C4305: '-=': truncation from 'double' to 'float'
C:\Users\Anna Niczyporuk\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(481,21): warning C4305: '+=': truncation from 'double' to 'float' C:\Users\sjule\source\repos\GRK_Project\cw 9\src\ex_9_1.hpp(523,21): warning C4305: '+=': truncation from 'double' to 'float'
Box.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/INCREMENTAL:NO' specification Box.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/INCREMENTAL:NO' specification
LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
grk-cw9.vcxproj -> C:\Users\Anna Niczyporuk\source\repos\GRK_Project\Debug\grk-cw9.exe grk-cw9.vcxproj -> C:\Users\sjule\source\repos\GRK_Project\Debug\grk-cw9.exe

View File

@ -1,2 +1,2 @@
PlatformToolSet=v143:VCToolArchitecture=Native32Bit:VCToolsVersion=14.33.31629:TargetPlatformVersion=10.0.19041.0: PlatformToolSet=v143:VCToolArchitecture=Native32Bit:VCToolsVersion=14.34.31933:TargetPlatformVersion=10.0.22621.0:
Debug|Win32|C:\Users\Anna Niczyporuk\source\repos\GRK_Project\| Debug|Win32|C:\Users\sjule\source\repos\GRK_Project\|

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
cw 9/grk-cw9.rc Normal file

Binary file not shown.

View File

@ -43,6 +43,8 @@
<None Include="shaders\shader_9_1.vert" /> <None Include="shaders\shader_9_1.vert" />
<None Include="shaders\shader_8_sun.frag" /> <None Include="shaders\shader_8_sun.frag" />
<None Include="shaders\shader_8_sun.vert" /> <None Include="shaders\shader_8_sun.vert" />
<None Include="shaders\shader_bubble.frag" />
<None Include="shaders\shader_bubble.vert" />
<None Include="shaders\shader_shadowap_sun.frag" /> <None Include="shaders\shader_shadowap_sun.frag" />
<None Include="shaders\shader_shadowap_sun.vert" /> <None Include="shaders\shader_shadowap_sun.vert" />
<None Include="shaders\shader_skybox.frag" /> <None Include="shaders\shader_skybox.frag" />

View File

@ -133,5 +133,11 @@
<None Include="shaders\shader_water.vert"> <None Include="shaders\shader_water.vert">
<Filter>Shader Files</Filter> <Filter>Shader Files</Filter>
</None> </None>
<None Include="shaders\shader_bubble.frag">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\shader_bubble.vert">
<Filter>Shader Files</Filter>
</None>
</ItemGroup> </ItemGroup>
</Project> </Project>

14
cw 9/resource.h Normal file
View File

@ -0,0 +1,14 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by grk-cw9.rc
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

View File

@ -0,0 +1,301 @@
#version 430 core
uniform vec3 iResolution;
//uniform vec3 cameraPos;
//uniform vec3 cameraDir;
uniform mat3 camMat;
uniform sampler2D iChannel1;
uniform samplerCube iChannel0;
uniform float time;
in vec4 bubblePosition;
out vec4 fragColor;
/*
Fast Thin-Film Interference
This is a performance-optimized version of my previous
thin-film interference shader here: https://www.shadertoy.com/view/XddXRj
This version also fixes a platform-specific bug and has
a few other tweaks as well.
Thin-film interference and chromatic dispersion are simulated at
six different wavelengths and then downsampled to RGB.
*/
// To see just the reflection (no refraction/transmission) uncomment this next line:
//#define REFLECTANCE_ONLY
// performance and raymarching options
#define INTERSECTION_PRECISION 0.01 // raymarcher intersection precision
#define ITERATIONS 20 // max number of iterations
#define AA_SAMPLES 1 // anti aliasing samples
#define BOUND 6.0 // cube bounds check
#define DIST_SCALE 0.9 // scaling factor for raymarching position update
// optical properties
#define DISPERSION 0.05 // dispersion amount
#define IOR 0.9 // base IOR value specified as a ratio
#define THICKNESS_SCALE 32.0 // film thickness scaling factor
#define THICKNESS_CUBEMAP_SCALE 0.1 // film thickness cubemap scaling factor
#define REFLECTANCE_SCALE 3.0 // reflectance scaling factor
#define REFLECTANCE_GAMMA_SCALE 2.0 // reflectance gamma scaling factor
#define FRESNEL_RATIO 0.7 // fresnel weight for reflectance
#define SIGMOID_CONTRAST 8.0 // contrast enhancement
#define TWO_PI 6.28318530718
#define WAVELENGTHS 6 // number of wavelengths, not a free parameter
// iq's cubemap function
vec3 fancyCube( sampler2D sam, in vec3 d, in float s, in float b )
{
vec3 colx = textureLod( sam, 0.5 + s*d.yz/d.x, b ).xyz;
vec3 coly = textureLod( sam, 0.5 + s*d.zx/d.y, b ).xyz;
vec3 colz = textureLod( sam, 0.5 + s*d.xy/d.z, b ).xyz;
vec3 n = d*d;
return (colx*n.x + coly*n.y + colz*n.z)/(n.x+n.y+n.z);
}
// iq's 3D noise function
float hash( float n ){
return fract(sin(n)*43758.5453);
}
float noise( in vec3 x ) {
vec3 p = floor(x);
vec3 f = fract(x);
f = f*f*(3.0-2.0*f);
float n = p.x + p.y*57.0 + 113.0*p.z;
return mix(mix(mix( hash(n+ 0.0), hash(n+ 1.0),f.x),
mix( hash(n+ 57.0), hash(n+ 58.0),f.x),f.y),
mix(mix( hash(n+113.0), hash(n+114.0),f.x),
mix( hash(n+170.0), hash(n+171.0),f.x),f.y),f.z);
}
vec3 noise3(vec3 x) {
return vec3( noise(x+vec3(123.456,.567,.37)),
noise(x+vec3(.11,47.43,19.17)),
noise(x) );
}
// a sphere with a little bit of warp
float sdf( vec3 p ) {
vec3 n = vec3(sin(time * 0.5), sin(time * 0.3), cos(time * 0.2));
vec3 q = 0.1 * (noise3(p + n) - 0.5);
return length(q + p) - 3.5;
}
vec3 fresnel( vec3 rd, vec3 norm, vec3 n2 ) {
vec3 r0 = pow((1.0-n2)/(1.0+n2), vec3(2));
return r0 + (1. - r0)*pow(clamp(1. + dot(rd, norm), 0.0, 1.0), 5.);
}
vec3 calcNormal( in vec3 pos ) {
const float eps = INTERSECTION_PRECISION;
const vec3 v1 = vec3( 1.0,-1.0,-1.0);
const vec3 v2 = vec3(-1.0,-1.0, 1.0);
const vec3 v3 = vec3(-1.0, 1.0,-1.0);
const vec3 v4 = vec3( 1.0, 1.0, 1.0);
return normalize( v1*sdf( pos + v1*eps ) +
v2*sdf( pos + v2*eps ) +
v3*sdf( pos + v3*eps ) +
v4*sdf( pos + v4*eps ) );
}
#define GAMMA_CURVE 50.0
#define GAMMA_SCALE 4.5
vec3 filmic_gamma(vec3 x) {
return log(GAMMA_CURVE * x + 1.0) / GAMMA_SCALE;
}
vec3 filmic_gamma_inverse(vec3 y) {
return (1.0 / GAMMA_CURVE) * (exp(GAMMA_SCALE * y) - 1.0);
}
// sample weights for the cubemap given a wavelength i
// room for improvement in this function
#define GREEN_WEIGHT 2.8
vec3 texCubeSampleWeights(float i) {
vec3 w = vec3((1.0 - i) * (1.0 - i), GREEN_WEIGHT * i * (1.0 - i), i * i);
return w / dot(w, vec3(1.0));
}
vec3 sampleCubeMap(vec3 i, vec3 rd) {
vec3 col = textureLod(iChannel0, rd * vec3(1.0,-1.0,1.0), 0.0).xyz;
return vec3(
dot(texCubeSampleWeights(i.x), col),
dot(texCubeSampleWeights(i.y), col),
dot(texCubeSampleWeights(i.z), col)
);
}
vec3 sampleCubeMap(vec3 i, vec3 rd0, vec3 rd1, vec3 rd2) {
vec3 col0 = textureLod(iChannel0, rd0 * vec3(1.0,-1.0,1.0), 0.0).xyz;
vec3 col1 = textureLod(iChannel0, rd1 * vec3(1.0,-1.0,1.0), 0.0).xyz;
vec3 col2 = textureLod(iChannel0, rd2 * vec3(1.0,-1.0,1.0), 0.0).xyz;
return vec3(
dot(texCubeSampleWeights(i.x), col0),
dot(texCubeSampleWeights(i.y), col1),
dot(texCubeSampleWeights(i.z), col2)
);
}
vec3 sampleWeights(float i) {
return vec3((1.0 - i) * (1.0 - i), GREEN_WEIGHT * i * (1.0 - i), i * i);
}
vec3 resample(vec3 wl0, vec3 wl1, vec3 i0, vec3 i1) {
vec3 w0 = sampleWeights(wl0.x);
vec3 w1 = sampleWeights(wl0.y);
vec3 w2 = sampleWeights(wl0.z);
vec3 w3 = sampleWeights(wl1.x);
vec3 w4 = sampleWeights(wl1.y);
vec3 w5 = sampleWeights(wl1.z);
return i0.x * w0 + i0.y * w1 + i0.z * w2
+ i1.x * w3 + i1.y * w4 + i1.z * w5;
}
// downsample to RGB
vec3 resampleColor(vec3[WAVELENGTHS] rds, vec3 refl0, vec3 refl1, vec3 wl0, vec3 wl1) {
#ifdef REFLECTANCE_ONLY
vec3 intensity0 = refl0;
vec3 intensity1 = refl1;
#else
vec3 cube0 = sampleCubeMap(wl0, rds[0], rds[1], rds[2]);
vec3 cube1 = sampleCubeMap(wl1, rds[3], rds[4], rds[5]);
vec3 intensity0 = filmic_gamma_inverse(cube0) + refl0;
vec3 intensity1 = filmic_gamma_inverse(cube1) + refl1;
#endif
vec3 col = resample(wl0, wl1, intensity0, intensity1);
return 1.4 * filmic_gamma(col / float(WAVELENGTHS));
}
vec3 resampleColorSimple(vec3 rd, vec3 wl0, vec3 wl1) {
vec3 cube0 = sampleCubeMap(wl0, rd);
vec3 cube1 = sampleCubeMap(wl1, rd);
vec3 intensity0 = filmic_gamma_inverse(cube0);
vec3 intensity1 = filmic_gamma_inverse(cube1);
vec3 col = resample(wl0, wl1, intensity0, intensity1);
return 1.4 * filmic_gamma(col / float(WAVELENGTHS));
}
// compute the wavelength/IOR curve values.
vec3 iorCurve(vec3 x) {
return x;
}
vec3 attenuation(float filmThickness, vec3 wavelengths, vec3 normal, vec3 rd) {
return 0.5 + 0.5 * cos(((THICKNESS_SCALE * filmThickness)/(wavelengths + 1.0)) * dot(normal, rd));
}
vec3 contrast(vec3 x) {
return 1.0 / (1.0 + exp(-SIGMOID_CONTRAST * (x - 0.5)));
}
void doCamera( out vec3 camPos, out vec3 camTar, in float time, in vec4 m ) {
camTar = vec3(0.0,0.0,0.0);
if (max(m.z, m.w) <= 0.0) {
float an = 1.5 + sin(time * 0.05) * 4.0;
camPos = vec3(6.5*sin(an), 0.0 ,6.5*cos(an));
} else {
float an = 10.0 * m.x - 5.0;
camPos = vec3(6.5*sin(an),10.0 * m.y - 5.0,6.5*cos(an));
}
}
mat3 calcLookAtMatrix( in vec3 ro, in vec3 ta, in float roll )
{
vec3 ww = normalize( ta - ro );
vec3 uu = normalize( cross(ww,vec3(sin(roll),cos(roll),0.0) ) );
vec3 vv = normalize( cross(uu,ww));
return mat3( uu, vv, ww );
}
void main()
{
vec2 p = (-iResolution.xy + 2.0*gl_FragCoord.xy)/iResolution.y;
//vec4 m = vec4(iMouse.xy/iResolution.xy, iMouse.zw);
// camera movement
//vec3 ro, ta;
//doCamera( ro, ta, iTime, m );
//mat3 camMat = calcLookAtMatrix( cameraPos, cameraDir, 0.0 );
float dh = (0.666 / iResolution.y);
const float rads = TWO_PI / float(AA_SAMPLES);
vec3 col = vec3(0.0);
vec3 wavelengths0 = vec3(1.0, 0.8, 0.6);
vec3 wavelengths1 = vec3(0.4, 0.2, 0.0);
vec3 iors0 = IOR + iorCurve(wavelengths0) * DISPERSION;
vec3 iors1 = IOR + iorCurve(wavelengths1) * DISPERSION;
vec3 rds[WAVELENGTHS];
for (int samp = 0; samp < AA_SAMPLES; samp++) {
vec2 dxy = dh * vec2(cos(float(samp) * rads), sin(float(samp) * rads));
vec3 rd = normalize(vec3(p.xy + dxy, 1.5)); // 1.5 is the lens length
vec3 pos = bubblePosition.xyz;
bool hit = false;
for (int j = 0; j < ITERATIONS; j++) {
float t = DIST_SCALE * sdf(pos);
pos += t * rd;
hit = t < INTERSECTION_PRECISION;
if ( clamp(pos, -BOUND, BOUND) != pos || hit ) {
break;
}
}
if (hit) {
vec3 normal = calcNormal(pos);
float filmThickness = fancyCube( iChannel1, normal, THICKNESS_CUBEMAP_SCALE, 0.0 ).x + 0.1;
vec3 att0 = attenuation(filmThickness, wavelengths0, normal, rd);
vec3 att1 = attenuation(filmThickness, wavelengths1, normal, rd);
vec3 f0 = (1.0 - FRESNEL_RATIO) + FRESNEL_RATIO * fresnel(rd, normal, 1.0 / iors0);
vec3 f1 = (1.0 - FRESNEL_RATIO) + FRESNEL_RATIO * fresnel(rd, normal, 1.0 / iors1);
vec3 rrd = reflect(rd, normal);
vec3 cube0 = REFLECTANCE_GAMMA_SCALE * att0 * sampleCubeMap(wavelengths0, rrd);
vec3 cube1 = REFLECTANCE_GAMMA_SCALE * att1 * sampleCubeMap(wavelengths1, rrd);
vec3 refl0 = REFLECTANCE_SCALE * filmic_gamma_inverse(mix(vec3(0), cube0, f0));
vec3 refl1 = REFLECTANCE_SCALE * filmic_gamma_inverse(mix(vec3(0), cube1, f1));
rds[0] = refract(rd, normal, iors0.x);
rds[1] = refract(rd, normal, iors0.y);
rds[2] = refract(rd, normal, iors0.z);
rds[3] = refract(rd, normal, iors1.x);
rds[4] = refract(rd, normal, iors1.y);
rds[5] = refract(rd, normal, iors1.z);
col += resampleColor(rds, refl0, refl1, wavelengths0, wavelengths1);
} else {
col += resampleColorSimple(rd, wavelengths0, wavelengths1);
}
}
col /= float(AA_SAMPLES);
fragColor = vec4( contrast(col), 1.0 );
}

View File

@ -0,0 +1,17 @@
#version 430 core
layout(location = 0) in vec3 vertexPosition;
layout(location = 1) in vec3 vertexNormal;
layout(location = 2) in vec2 vertexTexCoord;
uniform mat4 transformation;
out vec4 bubblePosition;
void main()
{
bubblePosition = transformation * vec4(vertexPosition, 1.0);
gl_Position = transformation * vec4(vertexPosition, 1.0);
//gl_Position = vec4(vertexPosition, 1.0);
}

View File

@ -4,6 +4,7 @@
#include "ext.hpp" #include "ext.hpp"
#include <iostream> #include <iostream>
#include <cmath> #include <cmath>
#include <chrono>
#include "Shader_Loader.h" #include "Shader_Loader.h"
#include "Render_Utils.h" #include "Render_Utils.h"
@ -48,6 +49,15 @@ std::vector<std::string> faces = {
"textures/skybox_2/back.jpg", "textures/skybox_2/back.jpg",
}; };
std::vector<std::string> facesBubble = {
"textures/bubbleSkybox/right.jpg",
"textures/bubbleSkybox/left.jpg",
"textures/bubbleSkybox/top.jpg",
"textures/bubbleSkybox/bottom.jpg",
"textures/bubbleSkybox/front.jpg",
"textures/bubbleSkybox/back.jpg",
};
namespace texture { namespace texture {
GLuint water; GLuint water;
} }
@ -63,6 +73,8 @@ GLuint programDepth;
GLuint programSkybox; GLuint programSkybox;
GLuint programWater; GLuint programWater;
GLuint skyboxTexture; GLuint skyboxTexture;
GLuint bubbleTexture0, bubbleTexture1;
GLuint programBubble;
Core::Shader_Loader shaderLoader; Core::Shader_Loader shaderLoader;
@ -100,7 +112,7 @@ glm::vec3 lightPos = glm::vec3(-8, 4, 2);
float lastTime = -1.f; float lastTime = -1.f;
float deltaTime = 0.f; float deltaTime = 0.f;
unsigned int loadSkybox(std::vector<std::string> faces) unsigned int loadSkybox(std::vector<std::string> faces1)
{ {
unsigned int textureID; unsigned int textureID;
glGenTextures(1, &textureID); glGenTextures(1, &textureID);
@ -110,7 +122,7 @@ unsigned int loadSkybox(std::vector<std::string> faces)
unsigned char* data; unsigned char* data;
for (unsigned int i = 0; i < 6; i++) for (unsigned int i = 0; i < 6; i++)
{ {
unsigned char* data = SOIL_load_image(faces[i].c_str(), &w, &h, 0, SOIL_LOAD_RGBA); unsigned char* data = SOIL_load_image(faces1[i].c_str(), &w, &h, 0, SOIL_LOAD_RGBA);
glTexImage2D( glTexImage2D(
GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, data 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, data
@ -153,8 +165,8 @@ glm::mat4 createCameraMatrix()
void drawSkybox(Core::RenderContext& context, glm::mat4 transformation, GLuint textureID) { void drawSkybox(Core::RenderContext& context, glm::mat4 transformation, GLuint textureID) {
glUseProgram(programSkybox); glUseProgram(programSkybox);
glUniformMatrix4fv(glGetUniformLocation(programSkybox, "transformation"), 1, GL_FALSE, (float*)&transformation); glUniformMatrix4fv(glGetUniformLocation(programSkybox, "transformation"), 1, GL_FALSE, (float*)&transformation);
glBindTexture(GL_TEXTURE_CUBE_MAP, textureID);
Core::SetActiveTexture(textureID, "colorTexture", programSkybox, 0); Core::SetActiveTexture(textureID, "colorTexture", programSkybox, 0);
glBindTexture(GL_TEXTURE_CUBE_MAP, textureID);
Core::DrawContext(context); Core::DrawContext(context);
} }
glm::mat4 createPerspectiveMatrix() glm::mat4 createPerspectiveMatrix()
@ -219,6 +231,28 @@ void drawObjectDepth(Core::RenderContext context, glm::mat4 viewProjectionMatrix
Core::DrawContext(context); Core::DrawContext(context);
} }
void drawBubble(glm::mat4 transformSphere) {
float time = glfwGetTime();
glUseProgram(programBubble);
glm::mat4 cameraMatrix = createCameraMatrix();
glm::mat4 perspectiveMatrix = createPerspectiveMatrix();
glm::mat4 viewProjectionMatrix = perspectiveMatrix * cameraMatrix;
//glm::mat4 transformation = viewProjectionMatrix * glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1));
glm::mat4 bubbleSkyboxViewMatrix = perspectiveMatrix * glm::mat4(glm::mat3(cameraMatrix));
glUniformMatrix4fv(glGetUniformLocation(programBubble, "transformation"), 1, GL_FALSE, (float*)&transformSphere);
glUniform3f(glGetUniformLocation(programBubble, "iResolution"), WIDTH, HEIGHT, 1.0);
glUniform1f(glGetUniformLocation(programBubble, "time"), time);
//glUniform3f(glGetUniformLocation(programBubble, "cameraPos"), cameraPos.x, cameraPos.y, cameraPos.z);
//glUniform3f(glGetUniformLocation(programBubble, "cameraDir"), cameraDir.x, cameraDir.y, cameraDir.z);
glUniformMatrix3fv(glGetUniformLocation(programBubble, "camMat"), 1, GL_FALSE, (float*)&glm::mat3(viewProjectionMatrix));
Core::SetActiveTexture(bubbleTexture0, "iChannel0", programBubble, 1);
glBindTexture(GL_TEXTURE_CUBE_MAP, bubbleTexture0);
Core::SetActiveTexture(bubbleTexture1, "iChannel1", programBubble, 0);
glBindTexture(GL_TEXTURE_2D, bubbleTexture1);
Core::DrawContext(sphereContext);
}
void renderShadowapSun() { void renderShadowapSun() {
float time = glfwGetTime(); float time = glfwGetTime();
@ -303,24 +337,25 @@ void renderScene(GLFWwindow* window)
float time = glfwGetTime(); float time = glfwGetTime();
updateDeltaTime(time); updateDeltaTime(time);
renderShadowapSun(); renderShadowapSun();
//space lamp //space lamp
glUseProgram(programSun); //glUseProgram(programSun);
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix(); glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
glm::mat4 transformation = viewProjectionMatrix * glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1)); glm::mat4 transformation = viewProjectionMatrix * glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1));
glUniformMatrix4fv(glGetUniformLocation(programSun, "transformation"), 1, GL_FALSE, (float*)&transformation); /*glUniformMatrix4fv(glGetUniformLocation(programSun, "transformation"), 1, GL_FALSE, (float*)&transformation);
glUniform3f(glGetUniformLocation(programSun, "color"), sunColor.x / 2, sunColor.y / 2, sunColor.z / 2); glUniform3f(glGetUniformLocation(programSun, "color"), sunColor.x / 2, sunColor.y / 2, sunColor.z / 2);
glUniform1f(glGetUniformLocation(programSun, "exposition"), exposition); glUniform1f(glGetUniformLocation(programSun, "exposition"), exposition);
Core::DrawContext(sphereContext); Core::DrawContext(sphereContext);*/
drawSkybox(models::cubeContext, createPerspectiveMatrix() * glm::mat4(glm::mat3(createCameraMatrix())), skyboxTexture); drawSkybox(models::cubeContext, createPerspectiveMatrix() * glm::mat4(glm::mat3(createCameraMatrix())), skyboxTexture);
glUseProgram(program); glUseProgram(program);
//drawObjectPBR(sphereContext, glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::scale(glm::vec3(0.3f)), glm::vec3(0.2, 0.7, 0.3), 0.3, 0.0);
drawObjectPBR(sphereContext, glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::scale(glm::vec3(0.3f)), glm::vec3(0.2, 0.7, 0.3), 0.3, 0.0); /*drawObjectPBR(sphereContext,
drawObjectPBR(sphereContext,
glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::eulerAngleY(time) * glm::translate(glm::vec3(1.f, 0, 0)) * glm::scale(glm::vec3(0.1f)), glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::eulerAngleY(time) * glm::translate(glm::vec3(1.f, 0, 0)) * glm::scale(glm::vec3(0.1f)),
glm::vec3(0.5, 0.5, 0.5), 0.7, 0.0); glm::vec3(0.5, 0.5, 0.5), 0.7, 0.0);*/
drawObjectPBR(models::bedContext, glm::mat4(), glm::vec3(0.03f, 0.03f, 0.03f), 0.2f, 0.0f); drawObjectPBR(models::bedContext, glm::mat4(), glm::vec3(0.03f, 0.03f, 0.03f), 0.2f, 0.0f);
drawObjectPBR(models::chairContext, glm::mat4(), glm::vec3(0.195239f, 0.37728f, 0.8f), 0.4f, 0.0f); drawObjectPBR(models::chairContext, glm::mat4(), glm::vec3(0.195239f, 0.37728f, 0.8f), 0.4f, 0.0f);
@ -344,10 +379,10 @@ void renderScene(GLFWwindow* window)
}); });
//drawObjectColor(shipContext, /*drawObjectColor(shipContext,
// glm::translate(cameraPos + 1.5 * cameraDir + cameraUp * -0.5f) * inveseCameraRotrationMatrix * glm::eulerAngleY(glm::pi<float>()), glm::translate(cameraPos + 1.5 * cameraDir + cameraUp * -0.5f) * inveseCameraRotrationMatrix * glm::eulerAngleY(glm::pi<float>()),
// glm::vec3(0.3, 0.3, 0.5) glm::vec3(0.3, 0.3, 0.5)
// ); );*/
drawObjectPBR(shipContext, drawObjectPBR(shipContext,
glm::translate(spaceshipPos) * specshipCameraRotrationMatrix * glm::eulerAngleY(glm::pi<float>()) * glm::scale(glm::vec3(0.03f)), glm::translate(spaceshipPos) * specshipCameraRotrationMatrix * glm::eulerAngleY(glm::pi<float>()) * glm::scale(glm::vec3(0.03f)),
glm::vec3(0.3, 0.3, 0.5), glm::vec3(0.3, 0.3, 0.5),
@ -362,7 +397,6 @@ void renderScene(GLFWwindow* window)
drawObjectColorWater(waterContext, glm::translate(glm::mat4(1.0), glm::vec3(0.0f, -1.7f, 0.0f)), glm::vec4(0.1, 0.1, 0.95, 0.5), time, texture::water); drawObjectColorWater(waterContext, glm::translate(glm::mat4(1.0), glm::vec3(0.0f, -1.7f, 0.0f)), glm::vec4(0.1, 0.1, 0.95, 0.5), time, texture::water);
//test depth buffer //test depth buffer
/*glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /*glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgram(programTest); glUseProgram(programTest);
@ -410,6 +444,7 @@ void init(GLFWwindow* window)
programDepth = shaderLoader.CreateProgram("shaders/shader_shadowap_sun.vert", "shaders/shader_shadowap_sun.frag"); programDepth = shaderLoader.CreateProgram("shaders/shader_shadowap_sun.vert", "shaders/shader_shadowap_sun.frag");
programSkybox = shaderLoader.CreateProgram("shaders/shader_skybox.vert", "shaders/shader_skybox.frag"); programSkybox = shaderLoader.CreateProgram("shaders/shader_skybox.vert", "shaders/shader_skybox.frag");
programWater = shaderLoader.CreateProgram("shaders/shader_water.vert", "shaders/shader_water.frag"); programWater = shaderLoader.CreateProgram("shaders/shader_water.vert", "shaders/shader_water.frag");
programBubble = shaderLoader.CreateProgram("shaders/shader_bubble.vert", "shaders/shader_bubble.frag");
water.readOBJ("./models/plane2.obj"); water.readOBJ("./models/plane2.obj");
texture::water = Core::LoadTexture("textures/test.png"); texture::water = Core::LoadTexture("textures/test.png");
loadModelToContext("./models/sphere.obj", sphereContext); loadModelToContext("./models/sphere.obj", sphereContext);
@ -429,8 +464,10 @@ void init(GLFWwindow* window)
loadModelToContext("./models/window.obj", models::windowContext); loadModelToContext("./models/window.obj", models::windowContext);
loadModelToContext("./models/test.obj", models::testContext); loadModelToContext("./models/test.obj", models::testContext);
loadModelToContext("./models/cube.obj", models::cubeContext); loadModelToContext("./models/cube.obj", models::cubeContext);
bubbleTexture0 = loadSkybox(facesBubble);
skyboxTexture = loadSkybox(faces); skyboxTexture = loadSkybox(faces);
bubbleTexture1 = Core::LoadTexture("textures/bubbleNoise.jpg");
//drawSkybox(models::cubeContext, transformation, skyboxTexture); //drawSkybox(models::cubeContext, transformation, skyboxTexture);
/*glUseProgram(programSkybox); /*glUseProgram(programSkybox);
glUniform1i(glGetUniformLocation(programSkybox, "skybox"), skyboxTexture); glUniform1i(glGetUniformLocation(programSkybox, "skybox"), skyboxTexture);

Binary file not shown.

After

Width:  |  Height:  |  Size: 446 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 91 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 115 KiB