Skip to content

Commit

Permalink
Inside view: Adding texture to eyeball.
Browse files Browse the repository at this point in the history
  • Loading branch information
unhyperbolic committed Nov 7, 2023
1 parent f99f2f6 commit 766446f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 18 deletions.
24 changes: 17 additions & 7 deletions opengl/CyOpenGL.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1615,6 +1615,7 @@ ELSE:
raise RuntimeError("Length of rgba_data not matching")

glGenTextures(1, &self._textureName)
glActiveTexture(GL_TEXTURE0)
glBindTexture(GL_TEXTURE_2D, self._textureName)

glTexImage2D(GL_TEXTURE_2D, 0,
Expand All @@ -1633,6 +1634,14 @@ ELSE:
GL_TEXTURE_MAG_FILTER,
GL_LINEAR)

glBindTexture(GL_TEXTURE_2D, 0)

def bind(self):
glBindTexture(GL_TEXTURE_2D, self._textureName)

def unbind(self):
glBindTexture(GL_TEXTURE_2D, 0)

def delete_resource(self):
glDeleteTextures(1, &self._textureName)
self._textureName = 0
Expand Down Expand Up @@ -2280,7 +2289,7 @@ ELSE:
for texture in self.textures:
texture.delete_resource()

textures = []
self.textures = []
for texture_file in texture_files:
texture = None
try:
Expand All @@ -2289,7 +2298,7 @@ ELSE:
print("Warning could not read texture %s" % texture_file)
print(e)

textures.append(texture)
self.textures.append(texture)

def set_fragment_shader_source(self,
source,
Expand Down Expand Up @@ -2458,10 +2467,10 @@ ELSE:

if self.image_shader.is_valid():
for i, texture in enumerate(self.textures):
glActiveTexture(GL_TEXTURE0 + i)
if texture:
glBindTexture(GL_TEXTURE_2D, texture._textureName)

glActiveTexture(GL_TEXTURE0 + i)
texture.bind()

self.image_shader.use_program()
self.image_shader.bind_uniforms(
self.get_uniform_bindings(width, height))
Expand All @@ -2470,8 +2479,9 @@ ELSE:
glDrawArrays(GL_TRIANGLES, 0, 3)

for i, texture in enumerate(self.textures):
glActiveTexture(GL_TEXTURE0 + i)
glBindTexture(GL_TEXTURE_2D, 0)
if texture:
glActiveTexture(GL_TEXTURE0 + i)
texture.unbind()
glActiveTexture(GL_TEXTURE0)

if self.report_time_callback:
Expand Down
1 change: 1 addition & 0 deletions python/raytracing/ideal_raytracing_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ def get_uniform_bindings(self):
d['insphereRadiusParams'] = ('float[]', insphereRadiusParams)
d['isNonGeometric'] = ('bool', isNonGeometric)
d['nonGeometricTexture'] = ('int', 0)
d['eyeTexture'] = ('int', 1)

return d

Expand Down
Binary file added python/raytracing/shaders/Eye.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion python/raytracing/shaders/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

def get_texture_paths():
return [ os.path.join(_base_path[0], name)
for name in ['NonGeometric.png'] ]
for name in ['NonGeometric.png',
'Eye.png'] ]

def _replace_compile_time_constants(shader_source, constants_dict):
for name, value in constants_dict.items():
Expand Down
17 changes: 7 additions & 10 deletions python/raytracing/shaders/fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ const vec4 lightSourcePosition = vec4(1.0, 0.0, 0.7, 0.0);

uniform bool isNonGeometric;
uniform sampler2D nonGeometricTexture;
uniform sampler2D eyeTexture;

const int num_tets = ##num_tets##;
const int num_edges = ##num_edges##;
Expand Down Expand Up @@ -1305,17 +1306,13 @@ material_params(RayHit ray_hit)

#if eyeball_type == 0
vec4 pt = ray_hit.ray.point * eyeballInvEmbeddings[ray_hit.object_index];
result.ambient = normalize(pt.yzw);

result.diffuse = vec3(0.0);
vec3 d = normalize(pt.yzw);

vec2 tex_coords = vec2(0.5) + vec2(atan(d.x, -d.z) / 2, asin(d.y)) / radians(180);

result.diffuse = texture(eyeTexture, tex_coords).xyz;
result.ambient = 0.5 * result.diffuse;
#else
if (ray_hit.object_subindex == 0) {
result.diffuse = vec3(1.0, 1.0, 0.0);
} else if (ray_hit.object_subindex == 1) {
result.diffuse = vec3(1.0, 0.0, 0.0);
} else {
result.diffuse = vec3(0.0, 1.0, 0.0);
}
result.diffuse = vec3(0.7, 0.7, 0.7);
result.ambient = 0.8 * result.diffuse;
#endif
Expand Down

0 comments on commit 766446f

Please sign in to comment.