Skip to content

Project 3 Submission #4

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 13 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
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion Part1/PROJ_WIN/Project3/Project3.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v100</PlatformToolset>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
Expand Down
11 changes: 9 additions & 2 deletions Part1/PROJ_WIN/Project3/shaders/heightFS.glsl
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
varying vec2 v_Texcoords;
varying float f_height;

void main(void)
{
gl_FragColor = vec4(0.05,0.15,0.3,1.0);
}
float shade = (1.0-2.0*sqrt(f_height));
float alpha = float(mod(v_Texcoords.x+0.025, 0.05) > 0.046 ||
mod(v_Texcoords.y+0.025, 0.05) > 0.046);
vec4 color = mix(vec4(0.05,0.15,0.3,1.0), vec4(0.05, 0.3, 0.4, 1.0), alpha);
gl_FragColor = shade*color;
}
17 changes: 13 additions & 4 deletions Part1/PROJ_WIN/Project3/shaders/heightVS.glsl
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
uniform mat4 u_projMatrix;
uniform sampler2D u_height;

attribute vec4 Position;
attribute vec2 Texcoords;

varying vec2 v_Texcoords;
varying float f_height;

void main(void)
{
vec4 pos = u_projMatrix * Position;
pos.z += 0.01;
gl_Position = pos;
}
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;
}
32 changes: 28 additions & 4 deletions Part1/PROJ_WIN/Project3/shaders/planetFS.glsl
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
void main(void)
{
gl_FragColor = vec4(1.0);
}
#version 330

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

void main()
{
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 = vec3(0.4, 0.1, 0.6);
FragColor = vec4(color*light,1.0);
}
42 changes: 38 additions & 4 deletions Part1/PROJ_WIN/Project3/shaders/planetGS.glsl
Original file line number Diff line number Diff line change
@@ -1,15 +1,49 @@
#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;

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 = cross(ToCam, Up);
Up = cross(Right, ToCam);

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

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

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

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

EndPrimitive();
}
}
517 changes: 215 additions & 302 deletions Part1/PROJ_WIN/src/kernel.cu.deps

Large diffs are not rendered by default.

45 changes: 42 additions & 3 deletions Part1/src/kernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -119,24 +119,63 @@ glm::vec3 calculateAcceleration(glm::vec4 us, glm::vec4 them)
//a = ------------- = --------
// m_us*r^2 r^2

return glm::vec3(0.0f);

glm::vec3 r((them.x-us.x), (them.y-us.y), (them.z-us.z));
float r2 = glm::dot(r,r);

if (r2 == 0)
return glm::vec3(0,0,0);

else {
float a = G*them.w / r2;
return a * (r/sqrt(r2));
}
}

//TODO: Core force calc kernel global memory
__device__
glm::vec3 naiveAcc(int N, glm::vec4 my_pos, glm::vec4 * their_pos)
{
// acceleration due to star
glm::vec3 acc = calculateAcceleration(my_pos, glm::vec4(0,0,0,starMass));
return acc;

// acceleration due to other planets
for (int i = 0; i < N; i++)
acc += calculateAcceleration(my_pos, their_pos[i]);

// return the total acceleration
return acc;
}


//TODO: Core force calc kernel shared memory
__device__
glm::vec3 sharedMemAcc(int N, glm::vec4 my_pos, glm::vec4 * their_pos)
{

__shared__ glm::vec4 them_shared[blockSize];

int tx = threadIdx.x;

// acceleration due to star
glm::vec3 acc = calculateAcceleration(my_pos, glm::vec4(0,0,0,starMass));
return acc;

// acceleration due to other planets
for (int m = 0; m < ceil((double)N/blockSize); ++m) {

// copy block of planets into shared memory
if (m*blockSize + tx < N)
them_shared[tx] = their_pos[m*blockSize + tx];
__syncthreads();

// compute acceleration contributions from block
for (int k = 0; k < blockSize; ++k)
if (m*blockSize + k < N) { acc += calculateAcceleration(my_pos, them_shared[k]); }
__syncthreads();
}

// total acceleration of my planet
return acc;
}

//Simple Euler integration scheme
Expand Down
2 changes: 1 addition & 1 deletion Part1/src/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <cutil_math.h>
#endif

#define blockSize 128
#define blockSize 32
#define checkCUDAErrorWithLine(msg) checkCUDAError(msg, __LINE__)
#define SHARED 0

Expand Down
2 changes: 1 addition & 1 deletion Part1/src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ glm::vec3 cameraPosition(1.75,1.75,1.35);
//----------CUDA STUFF-----------
//-------------------------------

int width=1000; int height=1000;
int width=750; int height=750;

//-------------------------------
//-------------MAIN--------------
Expand Down
33 changes: 33 additions & 0 deletions Part2/PROJ_NIX/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#All cuda paths are for v5.0+

NVCC = nvcc -m64
CC = gcc -m64
CPPC = g++ -m64

CUDA_FLAGS = -I/usr/local/cuda/samples/common/inc -I/usr/local/cuda/include

LFLAGS = -lglut -lGL -lGLEW

all: 565simulator

kernel.o: ../src/kernel.cu
$(NVCC) $(CUDA_FLAGS) -c ../src/kernel.cu

glslUtility.o: ../src/glslUtility.cpp
$(CPPC) $(CUDA_FLAGS) ../src/glslUtility.cpp -c

utilities.o: ../src/utilities.cpp
$(CPPC) $(CUDA_FLAGS) ../src/utilities.cpp -c

main.o: ../src/main.cpp ../src/glslUtility.h ../src/kernel.h ../src/utilities.h ../src/main.h
$(CPPC) $(CUDA_FLAGS) ../src/main.cpp -c

565simulator: main.o kernel.o glslUtility.o utilities.o
$(NVCC) $(LFLAGS) main.o kernel.o glslUtility.o utilities.o -o 565simulator

clean:
rm *.o
rm 565simulator

test: 565simulator
./565simulator
4 changes: 4 additions & 0 deletions Part2/PROJ_NIX/shaders/heightFS.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
void main(void)
{
gl_FragColor = vec4(0.05,0.15,0.3,1.0);
}
9 changes: 9 additions & 0 deletions Part2/PROJ_NIX/shaders/heightVS.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
uniform mat4 u_projMatrix;
attribute vec4 Position;

void main(void)
{
vec4 pos = u_projMatrix * Position;
pos.z += 0.01;
gl_Position = pos;
}
4 changes: 4 additions & 0 deletions Part2/PROJ_NIX/shaders/planetFS.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
void main(void)
{
gl_FragColor = vec4(1.0);
}
15 changes: 15 additions & 0 deletions Part2/PROJ_NIX/shaders/planetGS.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#version 330

uniform mat4 u_projMatrix;

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

void main()
{
vec3 Position = gl_in[0].gl_Position.xyz;
gl_Position = u_projMatrix * vec4(Position, 1.0);
EmitVertex();
EndPrimitive();
}
8 changes: 8 additions & 0 deletions Part2/PROJ_NIX/shaders/planetVS.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#version 330

in vec4 Position;

void main(void)
{
gl_Position = Position;
}
20 changes: 20 additions & 0 deletions Part2/PROJ_WIN/Project3.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Project3", "Project3\Project3.vcxproj", "{D7BEFF7A-4902-4B7E-922B-B0417A66864C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D7BEFF7A-4902-4B7E-922B-B0417A66864C}.Debug|Win32.ActiveCfg = Debug|Win32
{D7BEFF7A-4902-4B7E-922B-B0417A66864C}.Debug|Win32.Build.0 = Debug|Win32
{D7BEFF7A-4902-4B7E-922B-B0417A66864C}.Release|Win32.ActiveCfg = Release|Win32
{D7BEFF7A-4902-4B7E-922B-B0417A66864C}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Loading