検索 - User list
Full Version: Camera Projections in Karma
Root » Solaris and Karma » Camera Projections in Karma
Tim Crowson
Could someone provide a quick summary of how one does camera projections in Karma? (projecting a texture onto a mesh from a camera).

Was looking for camera projection node for this, but either I'm underthinking it, or overthinking, or just looking in the wrong place.
Tim Crowson
(Bump)
jsmack
I don't think there's anything built in for that. What are you trying to use the camera projection for? For shader level projections, it's up to the renderer, and I think usd currently has no mechanism for shaders to reference cameras other than the render cam.

For projecting onto vertices/points, there's sops. There's not an easy way to access a usd camera from sops though. It might be better to use python to get the matrices for the camera and store them as primvars on the geometry. Karma can access matrix primvars to do the projection in shader using homogenous coordinates.
Tim Crowson
Yikes....


Camera projection is a pretty fundamental tool for us (and I'm sure for many in VFX). In this case I'm just asking about Karma. Redshift already has a working solution for this. I'm just curious what the solution in Karma would be.
jsmack
Tim Crowson
Camera projection is a pretty fundamental tool for us (and I'm sure for many in VFX). In this case I'm just asking about Karma.

There's already no way to do arbitrary projections in mantra, so it's not different in that regard. There's a convenient solution in VEX for building a perspective matrix given camera view parameters. It's not that hard to implement in either renderer. It's just annoying to have to grab all the channels from the camera in /obj or from all the properties in usd.

Tim Crowson
Redshift already has a working solution for this.

A solution in Solaris? As far as I know USD coordsys is still in the proposal stage.

https://graphics.pixar.com/usd/dev/wp_coordsys.html [graphics.pixar.com]
Tim Crowson
I don't know what approach they took, but I know their CameraMap shader takes a USD cam prim and spits out the right thing.
mark
In Karma CPU, you should be able to transform to NDC coordinates pretty trivially.
Tim Crowson
What I'm bumping on is how to query the USD camera in the shading graph... is this possible?

Does the toNDC node accept a USD camera directly?
jsmack
Tim Crowson
What I'm bumping on is how to query the USD camera in the shading graph... is this possible?

Does the toNDC node accept a USD camera directly?

There is no, 'a camera', there is only 'the camera'--the one being rendered from. toNDC/fromNDC use the rendering camera for calculations, they don't accept an arbitrary camera.
blakshep
Hello there,
not sure about karma but here is how you can achieve it in renderman under solaris.
https://renderman.pixar.com/answers/questions/21851/how-to-make-camera-projections-in-solaris.html [renderman.pixar.com]
marcosimonrbl
jsmack
Tim Crowson
What I'm bumping on is how to query the USD camera in the shading graph... is this possible?

Does the toNDC node accept a USD camera directly?

There is no, 'a camera', there is only 'the camera'--the one being rendered from. toNDC/fromNDC use the rendering camera for calculations, they don't accept an arbitrary camera.

That node cannot be used with materialX though, can it?

@Tim:
We created a tool that projects NDC coordinates on the points of meshes as array primvar and one can use in the shader to get what you're asking - not perfect if render has displacement (I imagine), but close enough for our purposes.
Mark Wallman
Hi. Could you upload an example of that please?
jsmack
Mark Wallman
Hi. Could you upload an example of that please?

The uvtexture sop can be used when pointed to a camera object (not usd prim though) in sopmodify LOP
Mark Wallman
Hi Thats pretty much what I do now (modify the UV's) Best. Mark
marcosimonrbl
Mark Wallman
Hi. Could you upload an example of that please?

Here you go.
Mark Wallman
Thanks ;-)
terry_williams
Very helpful thanks!
Tomek P
Take a look at this:
https://www.sidefx.com/docs/houdini/nodes/lop/coordsys.html [www.sidefx.com]
There's an example scene at the bottom. I have to admit, it took me a while to understand what's going on.
VFX_DOOD
marcosimonrbl
Mark Wallman
Hi. Could you upload an example of that please?

Here you go.

Hi Marsoc,

Can you please explain how you promoted the attribute ?
egert_kanep
Hello!

I am sharing my solution here. I use python script lop to get the matrix4 for projection camera and use that as a value override for mtlx constant node. Add python script anywhere after material network node and point it to the mtlxconstant node. In python script lop set attribute name to be value

Python script (I do not take credit for this, AI wrote this)

import hou
from pxr import Usd, UsdGeom, UsdShade, Gf, Sdf

node = hou.pwd()
stage = node.editableStage()
time = Usd.TimeCode(hou.frame())

CAM_PATH = node.parm("cam_path").eval()
SHADER_PATH = node.parm("shader_path").eval()
ATTR_NAME = node.parm("attr_name").eval()

# ── Camera ──────────────────────────────────────────────────────────────────
cam_prim = stage.GetPrimAtPath(CAM_PATH)
if not cam_prim.IsValid():
raise RuntimeError(f"Camera prim not found: {CAM_PATH}")

usd_cam = UsdGeom.Camera(cam_prim)
gf_cam = usd_cam.GetCamera(time)
frustum = gf_cam.frustum

# ── ViewProjection matrix — NO transpose, MaterialX uses row-major too ──────
view = frustum.ComputeViewMatrix()
proj = frustum.ComputeProjectionMatrix()
vp = view * proj

# ── Aspect ratio ─────────────────────────────────────────────────────────────
aspect = gf_cam.horizontalAperture / gf_cam.verticalAperture

# ── Write to shader ──────────────────────────────────────────────────────────
shader_prim = stage.GetPrimAtPath(SHADER_PATH)
if not shader_prim.IsValid():
raise RuntimeError(f"Shader prim not found: {SHADER_PATH}")

shader = UsdShade.Shader(shader_prim)

inp = shader.GetInput(ATTR_NAME)
if not inp:
inp = shader.CreateInput(ATTR_NAME, Sdf.ValueTypeNames.Matrix4d)

inp.Set(vp, time)

print(f"CAM_PATH: {CAM_PATH}")
print(f"SHADER_PATH: {SHADER_PATH}")
print(f"ATTR_NAME: {ATTR_NAME}")
print(f"Aspect: {aspect:.4f} (should be ~1.777 for 16:9)")
print(f"Matrix OK: {vp}")



This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB