Skip to content

Commit edbd62e

Browse files
author
Fredrik Präntare
authored
Merge pull request #1 from jel-massih/feature/amd-support
Update fragment shaders to compile on AMD Cards
2 parents d228207 + cc49fd5 commit edbd62e

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

Shaders/Voxel Cone Tracing/voxel_cone_tracing.frag

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// ---------------------------------------------------------------------------------------------//
1+
//----------------------------------------------------------------------------------------------//
22
// A voxel cone tracing implementation for real-time global illumination, //
33
// refraction, specular, glossy and diffuse reflections, and soft shadows. //
44
// The implementation traces cones through a 3D texture which contains a //
@@ -80,8 +80,8 @@ in vec3 normalFrag;
8080

8181
out vec4 color;
8282

83-
const vec3 normal = normalize(normalFrag);
84-
const float MAX_DISTANCE = distance(vec3(abs(worldPositionFrag)), vec3(-1));
83+
vec3 normal = normalize(normalFrag);
84+
float MAX_DISTANCE = distance(vec3(abs(worldPositionFrag)), vec3(-1));
8585

8686
// Returns an attenuation factor given a distance.
8787
float attenuate(float dist){ dist *= DIST_FACTOR; return 1.0f / (CONSTANT + LINEAR * dist + QUADRATIC * dist * dist); }
@@ -97,7 +97,7 @@ vec3 orthogonal(vec3 u){
9797
vec3 scaleAndBias(const vec3 p) { return 0.5f * p + vec3(0.5f); }
9898

9999
// Returns true if the point p is inside the unity cube.
100-
bool isInsideCube(const vec3 p, float e = 0) { return abs(p.x) < 1 + e && abs(p.y) < 1 + e && abs(p.z) < 1 + e; }
100+
bool isInsideCube(const vec3 p, float e) { return abs(p.x) < 1 + e && abs(p.y) < 1 + e && abs(p.z) < 1 + e; }
101101

102102
// Returns a soft shadow blend by using shadow cone tracing.
103103
// Uses 2 samples per step, so it's pretty expensive.
@@ -112,7 +112,7 @@ float traceShadowCone(vec3 from, vec3 direction, float targetDistance){
112112

113113
while(dist < STOP && acc < 1){
114114
vec3 c = from + dist * direction;
115-
if(!isInsideCube(c)) break;
115+
if(!isInsideCube(c, 0)) break;
116116
c = scaleAndBias(c);
117117
float l = pow(dist, 2); // Experimenting with inverse square falloff for shadows.
118118
float s1 = 0.062 * textureLod(texture3D, c, 1 + 0.75 * l).a;
@@ -166,7 +166,7 @@ vec3 traceSpecularVoxelCone(vec3 from, vec3 direction){
166166
// Trace.
167167
while(dist < MAX_DISTANCE && acc.a < 1){
168168
vec3 c = from + dist * direction;
169-
if(!isInsideCube(c)) break;
169+
if(!isInsideCube(c, 0)) break;
170170
c = scaleAndBias(c);
171171

172172
float level = 0.1 * material.specularDiffusion * log2(1 + dist / VOXEL_SIZE);

Shaders/Voxelization/Visualization/voxel_visualization.frag

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ out vec4 color;
1919
vec3 scaleAndBias(vec3 p) { return 0.5f * p + vec3(0.5f); }
2020

2121
// Returns true if p is inside the unity cube (+ e) centered on (0, 0, 0).
22-
bool isInsideCube(vec3 p, float e = 0.2f) { return abs(p.x) < 1 + e && abs(p.y) < 1 + e && abs(p.z) < 1 + e; }
22+
bool isInsideCube(vec3 p, float e) { return abs(p.x) < 1 + e && abs(p.y) < 1 + e && abs(p.z) < 1 + e; }
2323

2424
void main() {
2525
const float mipmapLevel = state;
2626

2727
// Initialize ray.
28-
const vec3 origin = isInsideCube(cameraPosition) ?
28+
const vec3 origin = isInsideCube(cameraPosition, 0.2f) ?
2929
cameraPosition : texture(textureFront, textureCoordinateFrag).xyz;
3030
vec3 direction = texture(textureBack, textureCoordinateFrag).xyz - origin;
3131
const uint numberOfSteps = uint(INV_STEP_LENGTH * length(direction));

Shaders/Voxelization/voxelization.frag

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ vec3 calculatePointLight(const PointLight light){
4949

5050
vec3 scaleAndBias(vec3 p) { return 0.5f * p + vec3(0.5f); }
5151

52-
bool isInsideCube(const vec3 p, float e = 0) { return abs(p.x) < 1 + e && abs(p.y) < 1 + e && abs(p.z) < 1 + e; }
52+
bool isInsideCube(const vec3 p, float e) { return abs(p.x) < 1 + e && abs(p.y) < 1 + e && abs(p.z) < 1 + e; }
5353

5454
void main(){
5555
vec3 color = vec3(0.0f);
56-
if(!isInsideCube(worldPositionFrag)) return;
56+
if(!isInsideCube(worldPositionFrag, 0)) return;
5757

5858
// Calculate diffuse lighting fragment contribution.
5959
const uint maxLights = min(numberOfLights, MAX_LIGHTS);

Source/Graphic/Graphics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ void Graphics::initVoxelization()
140140
{
141141
voxelizationMaterial = MaterialStore::getInstance().findMaterialWithName("voxelization");
142142

143-
assert(voxelMaterial != nullptr);
143+
assert(voxelizationMaterial != nullptr);
144144

145145
const std::vector<GLfloat> texture3D(4 * voxelTextureSize * voxelTextureSize * voxelTextureSize, 0.0f);
146146
voxelTexture = new Texture3D(texture3D, voxelTextureSize, voxelTextureSize, voxelTextureSize, true);

voxel-cone-tracing.vcxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
<AdditionalOptions>/NODEFAULTLIB:libcmt.lib %(AdditionalOptions)</AdditionalOptions>
107107
</Link>
108108
<PostBuildEvent>
109-
<Command>copy /Y "$(TargetDir)$(ProjectName).dll" "$(SolutionDir)lib\$(ProjectName).dll"</Command>
109+
<Command>copy /Y "$(TargetDir)$(ProjectName).dll" "$(SolutionDir)lib\$(ProjectName).dll"</Command>
110110
</PostBuildEvent>
111111
</ItemDefinitionGroup>
112112
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@@ -236,4 +236,4 @@
236236
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
237237
<ImportGroup Label="ExtensionTargets">
238238
</ImportGroup>
239-
</Project>
239+
</Project>

0 commit comments

Comments
 (0)