Skip to content

Project 3 #16

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

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
17 changes: 16 additions & 1 deletion Part1/PROJ_WIN/Project3/Project3.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v110</PlatformToolset>
<PlatformToolset>v100</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand Down Expand Up @@ -71,12 +71,24 @@
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<AdditionalIncludeDirectories>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\include;C:/ProgramData/NVIDIA Corporation/CUDA Samples/v5.5/common/inc;../shared/glew/includes;../shared/freeglut/includes</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>cudart.lib; glew32.lib;glu32.lib;opengl32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>../shared/glew/lib;../shared/freeglut/lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<EntryPointSymbol>mainCRTStartup</EntryPointSymbol>
</Link>
<ProjectReference>
<LinkLibraryDependencies>true</LinkLibraryDependencies>
</ProjectReference>
<CudaCompile>
<Include>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\include;C:/ProgramData/NVIDIA Corporation/CUDA Samples/v5.5/common/inc;../shared/glew/includes;../shared/freeglut/includes</Include>
<CodeGeneration>compute_10,sm_10;compute_20,sm_20;compute_30,sm_30</CodeGeneration>
<CompileOut>$(ProjectDir)$(Platform)/$(Configuration)/%(Filename)%(Extension).obj</CompileOut>
</CudaCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\src\glslUtility.cpp" />
Expand All @@ -98,6 +110,9 @@
</ItemGroup>
<ItemGroup>
<None Include="shaders\heightFS.glsl" />
<None Include="shaders\heightGS.glsl" />
<None Include="shaders\heightTCS.glsl" />
<None Include="shaders\heightTES.glsl" />
<None Include="shaders\heightVS.glsl" />
<None Include="shaders\planetFS.glsl" />
<None Include="shaders\planetGS.glsl" />
Expand Down
9 changes: 9 additions & 0 deletions Part1/PROJ_WIN/Project3/Project3.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,14 @@
<None Include="shaders\planetVS.glsl">
<Filter>Resource Files</Filter>
</None>
<None Include="shaders\heightGS.glsl">
<Filter>Resource Files</Filter>
</None>
<None Include="shaders\heightTES.glsl">
<Filter>Resource Files</Filter>
</None>
<None Include="shaders\heightTCS.glsl">
<Filter>Resource Files</Filter>
</None>
</ItemGroup>
</Project>
46 changes: 44 additions & 2 deletions Part1/PROJ_WIN/Project3/shaders/heightFS.glsl
Original file line number Diff line number Diff line change
@@ -1,4 +1,46 @@
void main(void)
#version 400

in vec2 g_Texcoords;
in float g_height;

noperspective in vec3 g_PatchDistance;
noperspective in vec3 g_TriDistance;

// noperspective in vec3 dist;

out vec4 FragColor;

float amplify(float d, float scale, float offset)
{
gl_FragColor = vec4(0.05,0.15,0.3,1.0);
d = scale * d + offset;
d = clamp(d, 0, 1);
d = 1 - exp2(-2*d*d);
return d;
}

void main(void)
{

//float nearD = min(min(dist.x,dist.y),dist.z);
//float edgeIntensity = exp2(-1.0*nearD*nearD);

//vec4 edgeColor = vec4(0.1,0.1,0.1,1.0);
//color = edgeIntensity * edgeColor + (1-edgeIntensity) * color;


float shade = (1.0-2.0*sqrt(g_height));

float alpha = float(mod(g_Texcoords.x+0.025, 0.05) > 0.046 ||
mod(g_Texcoords.y+0.025, 0.05) > 0.046);
vec4 color;


float d1 = min(min(g_TriDistance.x, g_TriDistance.y), g_TriDistance.z);
float d2 = min(min(g_PatchDistance.x, g_PatchDistance.y), g_PatchDistance.z);
alpha = 2.0f * (0.5f - amplify(d1, 40, -0.5) * amplify(d2, 60, -0.5));

//color = amplify(d1, 40, -0.5) * amplify(d2, 60, -0.5) * color;
color = mix(vec4(0.05,0.15,0.3,1.0), vec4(0.05, 0.3, 0.4, 1.0), alpha);

FragColor = shade * color;
}
60 changes: 60 additions & 0 deletions Part1/PROJ_WIN/Project3/shaders/heightGS.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#version 400

layout (triangles) in;
layout (triangle_strip) out;
layout (max_vertices = 3) out;

in vec2 te_Texcoords[3];
in float te_height[3];
in vec3 te_PatchDistance[3];

out vec2 g_Texcoords;
out float g_height;
noperspective out vec3 g_PatchDistance;
noperspective out vec3 g_TriDistance;

uniform vec2 windowDim;
//noperspective out vec3 dist;

// Referencing
// http://www2.imm.dtu.dk/~janba/Wireframe/
// http://prideout.net/blog/?p=48

void main()
{
/*
vec2 p0 = windowDim * gl_in[0].gl_Position.xy / gl_in[0].gl_Position.w;
vec2 p1 = windowDim * gl_in[1].gl_Position.xy / gl_in[1].gl_Position.w;
vec2 p2 = windowDim * gl_in[2].gl_Position.xy / gl_in[2].gl_Position.w;

vec2 v0 = p2-p1;
vec2 v1 = p2-p0;
vec2 v2 = p1-p0;
float area = abs(v1.x*v2.y - v1.y * v2.x);
*/
// dist = vec3(area/length(v0),0,0);
g_Texcoords = te_Texcoords[0];
g_height = te_height[0];
g_PatchDistance = te_PatchDistance[0];
g_TriDistance = vec3(1,0,0);
gl_Position = gl_in[0].gl_Position;
EmitVertex();

// dist = vec3(0,area/length(v1),0);
g_Texcoords = te_Texcoords[1];
g_height = te_height[1];
g_PatchDistance = te_PatchDistance[1];
g_TriDistance = vec3(0,1,0);
gl_Position = gl_in[1].gl_Position;
EmitVertex();

// dist = vec3(0,0,area/length(v2));
g_Texcoords = te_Texcoords[2];
g_height = te_height[2];
g_PatchDistance = te_PatchDistance[1];
g_TriDistance = vec3(0,0,1);
gl_Position = gl_in[2].gl_Position;
EmitVertex();

EndPrimitive();
}
54 changes: 54 additions & 0 deletions Part1/PROJ_WIN/Project3/shaders/heightTCS.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#version 400

layout(vertices = 3) out;

uniform vec3 u_cameraPos;

in vec4 v_Position[];
in vec2 v_Texcoords[];

out vec4 tc_Position[];
out vec2 tc_Texcoords[];

uniform float tessLevelInner = 6.0;
uniform float tessLevelOuter = 6.0;

float GetTessLevel(float Distance0, float Distance1)
{
float AvgDistance = (Distance0 + Distance1) / 2.0;

if (AvgDistance <= 2.4) {
return 6.0;
}
else if (AvgDistance <= 3.25) {
return 4.0;
}
else {
return 2.0;
}
}

void main () {
tc_Position[gl_InvocationID] = v_Position[gl_InvocationID];
tc_Texcoords[gl_InvocationID] = v_Texcoords[gl_InvocationID];

// Calculate the distance from the camera to the three control points
float d0 = distance(u_cameraPos, v_Position[0].xyz);
float d1 = distance(u_cameraPos, v_Position[1].xyz);
float d2 = distance(u_cameraPos, v_Position[2].xyz);

// Calculate the tessellation levels
gl_TessLevelOuter[0] = GetTessLevel(d1, d2);
gl_TessLevelOuter[1] = GetTessLevel(d2, d0);
gl_TessLevelOuter[2] = GetTessLevel(d0, d1);
gl_TessLevelInner[0] = gl_TessLevelOuter[2];


/*
// Calculate the tessellation levels
gl_TessLevelInner[0] = tessLevelInner; // number of nested primitives to generate
gl_TessLevelOuter[0] = tessLevelOuter; // times to subdivide first side
gl_TessLevelOuter[1] = tessLevelOuter; // times to subdivide second side
gl_TessLevelOuter[2] = tessLevelOuter; // times to subdivide third side
*/
}
36 changes: 36 additions & 0 deletions Part1/PROJ_WIN/Project3/shaders/heightTES.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#version 400

uniform mat4 u_projMatrix;
uniform sampler2D u_height;

layout (triangles, equal_spacing, ccw) in;

in vec4 tc_Position[];
in vec2 tc_Texcoords[];

out vec2 te_Texcoords;
out float te_height;
out vec3 te_PatchDistance;


vec2 interpolate2D(vec2 v0, vec2 v1, vec2 v2)
{
return vec2(gl_TessCoord.x) * v0 + vec2(gl_TessCoord.y) * v1 + vec2(gl_TessCoord.z) * v2;
}
vec4 interpolate4D(vec4 v0, vec4 v1, vec4 v2)
{
return vec4(gl_TessCoord.x) * v0 + vec4(gl_TessCoord.y) * v1 + vec4(gl_TessCoord.z) * v2;
}

void main()
{
te_PatchDistance = gl_TessCoord;

te_Texcoords = interpolate2D(tc_Texcoords[0], tc_Texcoords[1], tc_Texcoords[2]);
vec4 Position = interpolate4D(tc_Position[0], tc_Position[1], tc_Position[2]);

te_height = texture2D(u_height, te_Texcoords).w;
Position.z = -0.01-clamp(te_height,0.0,2.0);

gl_Position = u_projMatrix * Position;
}
26 changes: 20 additions & 6 deletions Part1/PROJ_WIN/Project3/shaders/heightVS.glsl
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
uniform mat4 u_projMatrix;
attribute vec4 Position;
#version 400

in vec4 Position;
in vec2 Texcoords;

out vec4 v_Position;
out vec2 v_Texcoords;

void main(void)
{
vec4 pos = u_projMatrix * Position;
pos.z += 0.01;
gl_Position = pos;
}

v_Position = Position;
v_Texcoords = Texcoords;

/*
v_Texcoords = Texcoords;
vec4 pos = Position;
f_height = texture2D(u_height, Texcoords).w;
pos.z = -0.01-clamp(f_height,0.0,2.0);
pos = u_projMatrix * pos;
gl_Position = pos;
*/
}
33 changes: 30 additions & 3 deletions Part1/PROJ_WIN/Project3/shaders/planetFS.glsl
Original file line number Diff line number Diff line change
@@ -1,4 +1,31 @@
void main(void)
#version 330

in vec3 WorldCoord;
in vec3 ToCam;
in vec3 Up;
in vec3 Right;
in vec2 TexCoord;
out vec4 FragColor;

void main()
{
gl_FragColor = vec4(1.0);
}

vec4 ranCol = vec4(abs(ToCam.x),abs(ToCam.y),abs(ToCam.z),1.0);

vec2 coord = 2.01 * (TexCoord - vec2(0.5));
float r = length(coord);
if (r >= 1.0) { discard; }

float dist = length(WorldCoord);
if(dist <= 0.01)
{
FragColor = vec4(1.0);
return;
}

vec3 N = Right*-coord.x + Up*coord.y + ToCam*sqrt(1-r*r);
vec3 L = normalize(-WorldCoord);
float light = 0.1 + 0.9*clamp(dot(N,L),0.0, 1.0)*exp(-dist);
vec3 color = ranCol.xyz; //vec3(0.4, 0.1, 0.6);
FragColor = vec4(color*light,1.0);
}
48 changes: 44 additions & 4 deletions Part1/PROJ_WIN/Project3/shaders/planetGS.glsl
Original file line number Diff line number Diff line change
@@ -1,15 +1,55 @@
#version 330

uniform mat4 u_projMatrix;
uniform vec3 u_cameraPos;

layout (points) in;
layout (points) out;
layout (max_vertices = 1) out;
layout (triangle_strip) out;
layout (max_vertices = 4) out;

out vec3 WorldCoord;
out vec3 ToCam;
out vec3 Up;
out vec3 Right;
out vec2 TexCoord;

const float scale = 0.03;

#define screenFacing 1

void main()
{
vec3 Position = gl_in[0].gl_Position.xyz;
gl_Position = u_projMatrix * vec4(Position, 1.0);
WorldCoord = Position;

ToCam = normalize(u_cameraPos - Position);
Up = vec3(0.0, 0.0, 1.0);
Right = normalize(cross(ToCam, Up));
Up = normalize(cross(Right, ToCam));

vec3 Pos = Position + scale*Right - scale*Up;
gl_Position = u_projMatrix * vec4(Pos, 1.0);
//gl_Position = u_projMatrix * vec4(Position,1.0) + vec4(+scale,-scale,0,1);
TexCoord = vec2(0.0, 0.0);
EmitVertex();

Pos = Position + scale*Right + scale*Up;
gl_Position = u_projMatrix * vec4(Pos, 1.0);
//gl_Position = u_projMatrix * vec4(Position,1.0) + vec4(+scale,+scale,0,1);
TexCoord = vec2(0.0, 1.0);
EmitVertex();

Pos = Position - scale*Right - scale*Up;
gl_Position = u_projMatrix * vec4(Pos, 1.0);
//gl_Position = u_projMatrix * vec4(Position,1.0) + vec4(-scale,-scale,0,1);
TexCoord = vec2(1.0, 0.0);
EmitVertex();

Pos = Position - scale*Right + scale*Up;
gl_Position = u_projMatrix * vec4(Pos, 1.0);
//gl_Position = u_projMatrix * vec4(Position,1.0) + vec4(-scale,+scale,0,1);
TexCoord = vec2(1.0, 1.0);
EmitVertex();

EndPrimitive();
}
}
Loading