-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
185 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Simplified Blinn-Phong shading assuming the ambient and diffuse color are equal and the specular color is white. | ||
* Additionaly, Fresnel shading is used to enhance the outlines. | ||
* Assumes the following global variables are given: cameraPosition. | ||
* The camera position is assumed to be the source of a point light. | ||
*/ | ||
vec3 blinnPhongShadingSurface( | ||
in vec3 baseColor, in vec3 fragmentPositionWorld, in vec3 fragmentNormal) { | ||
// Blinn-Phong Shading | ||
const vec3 lightColor = vec3(1.0); | ||
const vec3 ambientColor = baseColor; | ||
const vec3 diffuseColor = ambientColor; | ||
vec3 phongColor = vec3(0.0); | ||
|
||
const float kA = 0.4; | ||
const vec3 Ia = kA * ambientColor; | ||
const float kD = 0.6; | ||
const float kS = 0.2; | ||
const float s = 30; | ||
|
||
const vec3 n = normalize(fragmentNormal); | ||
const vec3 v = normalize(cameraPosition - fragmentPositionWorld); | ||
const vec3 l = v;//normalize(lightDirection); | ||
const vec3 h = normalize(v + l); | ||
|
||
vec3 Id = kD * clamp(abs(dot(n, l)), 0.0, 1.0) * diffuseColor; | ||
vec3 Is = kS * pow(clamp(abs(dot(n, h)), 0.0, 1.0), s) * lightColor; | ||
|
||
phongColor = Ia + Id + Is; | ||
|
||
return phongColor; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#ifdef USE_ISOSURFACE_RENDERING | ||
vec3 isosurfaceRendering(vec3 x, vec3 w, out ScatterEvent firstEvent) { | ||
firstEvent = ScatterEvent(false, x, 0.0, w, 0.0, 0.0, 0.0); | ||
|
||
vec3 weights = vec3(1, 1, 1); | ||
float lastScalarSign, currentScalarSign; | ||
bool isFirstPoint = true; | ||
|
||
ivec3 voxelGridSize = textureSize(gridImage, 0); | ||
vec3 boxDelta = parameters.boxMax - parameters.boxMin; | ||
vec3 voxelSize3d = boxDelta / voxelGridSize; | ||
float t = max(voxelSize3d.x, max(voxelSize3d.y, voxelSize3d.z)) * parameters.isoStepWidth; | ||
|
||
bool foundHit = false; | ||
int i = 0; | ||
float tMin, tMax; | ||
if (rayBoxIntersect(parameters.boxMin, parameters.boxMax, x, w, tMin, tMax)) { | ||
x += w * tMin; | ||
float d = tMax - tMin; | ||
while (t <= d) { | ||
vec3 xNew = x + w * t; | ||
float scalarValue = sampleCloudDirect(xNew); | ||
|
||
currentScalarSign = sign(scalarValue - parameters.isoValue); | ||
if (isFirstPoint) { | ||
isFirstPoint = false; | ||
lastScalarSign = currentScalarSign; | ||
} | ||
|
||
if (lastScalarSign != currentScalarSign) { | ||
if (!firstEvent.hasValue) { | ||
firstEvent.x = x; | ||
firstEvent.pdf_x = 0; | ||
firstEvent.w = vec3(0.); | ||
firstEvent.pdf_w = 0; | ||
firstEvent.hasValue = true; | ||
firstEvent.density = parameters.extinction.x; | ||
firstEvent.depth = tMax - d + t; | ||
} | ||
refineIsoSurfaceHit(xNew, x, currentScalarSign); | ||
x = xNew; | ||
foundHit = true; | ||
break; | ||
} | ||
|
||
x = xNew; | ||
d -= t; | ||
} | ||
} | ||
|
||
if (foundHit) { | ||
vec3 surfaceNormal; | ||
vec3 color = getIsoSurfaceHitDirect(x, w, surfaceNormal); | ||
weights *= color; | ||
x += surfaceNormal * 1e-4; | ||
|
||
vec3 surfaceTangent; | ||
vec3 surfaceBitangent; | ||
ComputeDefaultBasis(surfaceNormal, surfaceTangent, surfaceBitangent); | ||
mat3 frame = mat3(surfaceTangent, surfaceBitangent, surfaceNormal); | ||
|
||
const int numAoSamples = 4; | ||
const float MAX_DIST = 0.05; | ||
float weight = 1.0; | ||
|
||
for (int i = 0; i < numAoSamples; i++) { | ||
w = frame * sampleHemisphere(vec2(random(), random())); | ||
|
||
if (rayBoxIntersect(parameters.boxMin, parameters.boxMax, x, w, tMin, tMax)) { | ||
x += w * tMin; | ||
float d = tMax - tMin; | ||
d = max(d, MAX_DIST); | ||
while (t <= d) { | ||
vec3 xNew = x + w * t; | ||
float scalarValue = sampleCloudDirect(xNew); | ||
|
||
currentScalarSign = sign(scalarValue - parameters.isoValue); | ||
if (isFirstPoint) { | ||
isFirstPoint = false; | ||
lastScalarSign = currentScalarSign; | ||
} | ||
|
||
if (lastScalarSign != currentScalarSign) { | ||
weight -= 1.0 / float(numAoSamples); | ||
break; | ||
} | ||
|
||
x = xNew; | ||
d -= t; | ||
} | ||
} | ||
} | ||
|
||
return weights * weight; | ||
//return surfaceNormal; | ||
} | ||
|
||
return sampleSkybox(w) + sampleLight(w); | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters