ai_shader_util.h
Go to the documentation of this file.
1 // Copyright 2020 Autodesk, Inc. All rights reserved.
2 //
3 // Use of this software is subject to the terms of the Autodesk license
4 // agreement provided at the time of installation or download, or which
5 // otherwise accompanies this software in either electronic or hard copy form.
6 
12 #pragma once
13 #include "ai_bbox.h"
14 #include "ai_color.h"
15 #include "ai_vector.h"
16 #include "ai_api.h"
17 #include "ai_shaderglobals.h"
18 
19 // forward declaration
20 struct AtSampler;
21 struct AtNode;
22 
33 #define AI_WORLD_TO_OBJECT 1
34 #define AI_OBJECT_TO_WORLD 2
35 /* \}*/
36 
40 #define AI_WIREFRAME_TRIANGLES 0
41 #define AI_WIREFRAME_POLYGONS 1
42 #define AI_WIREFRAME_PATCHES 2
43 /* \}*/
44 
48 AI_API AI_DEVICE AI_GPU_FORCE_INLINE AtRGB AiOcclusion(const AtVector& N, const AtVector& Ng, AtShaderGlobals* sg, float mint, float maxt, float spread, float falloff, const AtSampler* sampler, AtVector* Nbent);
49 AI_API AI_DEVICE AI_GPU_FORCE_INLINE AtRGB AiSelfOcclusion(const AtVector& N, const AtVector& Ng, AtShaderGlobals* sg, float mint, float maxt, float spread, float falloff, const AtSampler* sampler, AtVector* Nbent);
50 AI_API AtRGB AiDirectDiffuse(const AtVector& N, AtShaderGlobals* sg);
51 AI_API AtRGB AiIndirectDiffuse(const AtVector& N, AtShaderGlobals* sg, const AtRGB& weight);
52 /* \} */
53 
57 AI_API AI_DEVICE AtVector AiReflect(const AtVector& I, const AtVector& N);
58 AI_API AtVectorDv AiReflectWithDerivs(const AtVectorDv& I, const AtVectorDv& N);
59 AI_API AI_DEVICE AtVector AiReflectSafe(const AtVector& I, const AtVector& N, const AtVector& Ng);
60 AI_API AI_DEVICE bool AiRefract(const AtVector& I, const AtVector& N, AtVector& T, float n1, float n2);
61 AI_API bool AiRefractWithDerivs(const AtVectorDv& I, const AtVectorDv& N, AtVectorDv& T, float n1, float n2);
62 
63 AI_API AI_DEVICE AI_CONST float AiSchlickFresnel(const AtVector& N, const AtVector& Rd, float Krn);
64 AI_API AI_CONST AtRGB AiSchlickFresnelRGB(const AtVector& N, const AtVector& Rd, const AtRGB& Krn);
65 AI_API AI_CONST AtRGB AiConductorFresnel(const AtVector& N, const AtVector& Rd, const AtRGB& n, const AtRGB& k);
66 AI_API AI_CONST float AiDielectricFresnel(const AtVector& N, const AtVector& Rd, float eta);
67 AI_API AI_DEVICE void AiArtisticToConductorFresnel(const AtRGB& reflectivity, const AtRGB& edgetint, AtRGB& n, AtRGB& k);
68 
69 AI_API AI_DEVICE void AiFaceForward(AtVector& N, const AtVector& I);
70 /* \}*/
71 
88 typedef float (*AtFloatBumpEvaluator)(AtShaderGlobals* sg, void* data);
89 /* \}*/
90 
94 AI_API bool AiShaderGlobalsGetTriangle(const AtShaderGlobals* sg, int key, AtVector p[3]);
95 AI_API bool AiShaderGlobalsGetVertexNormals(const AtShaderGlobals* sg, int key, AtVector n[3]);
96 AI_API bool AiShaderGlobalsGetVertexUVs(const AtShaderGlobals* sg, const AtString uvset, AtVector2 uv[3]);
97 AI_API uint32_t AiShaderGlobalsGetPolygon(const AtShaderGlobals* sg, int key, AtVector* p);
98 AI_API AI_DEVICE uint32_t AiShaderGlobalsGetUniformID(const AtShaderGlobals* sg);
99 AI_API void AiShaderGlobalsGetPositionAtTime(const AtShaderGlobals* sg, float time, AtVector& P, AtVector* N, AtVector* Ng, AtVector* Ns);
100 AI_API AI_PURE AtVector2 AiShaderGlobalsGetPixelMotionVector(const AtShaderGlobals* sg, float time0, float time1);
101 AI_API AI_PURE AtBBox AiShaderGlobalsGetBBoxLocal(const AtShaderGlobals* sg);
102 AI_API AI_PURE AtBBox AiShaderGlobalsGetBBoxWorld(const AtShaderGlobals* sg);
104 AI_API AI_DEVICE AI_PURE AtVector AiShaderGlobalsTransformNormal(const AtShaderGlobals* sg, AtVector N, int space);
105 AI_API AI_DEVICE AI_PURE AtVector AiShaderGlobalsTransformPoint(const AtShaderGlobals* sg, AtVector P, int space);
106 AI_API AI_DEVICE AI_PURE AtVector AiShaderGlobalsTransformVector(const AtShaderGlobals* sg, AtVector V, int space);
107 AI_API void AiShaderGlobalsSetTraceSet(AtShaderGlobals* sg, const AtString set, bool inclusive);
109 AI_API void* AiShaderGlobalsQuickAlloc(const AtShaderGlobals* sg, uint32_t size);
110 AI_API AI_PURE AtVector AiShaderGlobalsEvaluateBump(AtShaderGlobals* sg, AtFloatBumpEvaluator bump_func, void* data);
111 AI_API AI_DEVICE AtRGB AiShaderGlobalsStochasticOpacity(AtShaderGlobals *sg, const AtRGB& opacity);
112 AI_API AI_DEVICE AI_PURE float AiShaderGlobalsArea(const AtShaderGlobals* sg);
113 AI_API AI_PURE float AiShaderGlobalsEdgeLength(const AtShaderGlobals* sg);
114 AI_API AI_DEVICE AI_PURE float AiWireframe(const AtShaderGlobals* sg, float line_width, bool raster_space, int edge_type);
115 AI_API AI_PURE bool AiShaderGlobalsIsObjectMatte(const AtShaderGlobals *sg);
116 
126 AI_DEVICE inline AtVector AiFaceViewer(const AtShaderGlobals* sg)
127 {
128  return (AiV3Dot(sg->Ng, sg->Rd) > 0.0f) ? -sg->N : sg->N;
129 }
130 
131 /* \}*/
132 
136 AI_API AI_PURE float AiCameraGetShutterStart();
137 AI_API AI_PURE float AiCameraGetShutterEnd();
138 AI_API AI_DEVICE void AiCameraToWorldMatrix(const AtNode* node, float time, AtMatrix& out);
139 AI_API AI_DEVICE void AiWorldToCameraMatrix(const AtNode* node, float time, AtMatrix& out);
140 AI_API AI_DEVICE void AiWorldToScreenMatrix(const AtNode* node, float time, AtMatrix& out);
141 /* \}*/
142 
146 AI_API void AiMappingMirroredBall(const AtVector& dir, float& u, float& v);
147 AI_API void AiMappingAngularMap (const AtVector& dir, float& u, float& v);
148 AI_API void AiMappingLatLong (const AtVector& dir, float& u, float& v);
149 /* \}*/
150 
154 AI_API AI_DEVICE void AiMappingMirroredBallDerivs(const AtVector &dir, const AtVector &dDdx, const AtVector &dDdy, float &u, float &v, float &dudx, float &dudy, float &dvdx, float &dvdy);
155 AI_API AI_DEVICE void AiMappingAngularMapDerivs (const AtVector &dir, const AtVector &dDdx, const AtVector &dDdy, float &u, float &v, float &dudx, float &dudy, float &dvdx, float &dvdy);
156 AI_API AI_DEVICE void AiMappingLatLongDerivs (const AtVector &dir, const AtVector &dDdx, const AtVector &dDdy, float &u, float &v, float &dudx, float &dudy, float &dvdx, float &dvdy);
157 
158 /* \}*/
159 
160 /*\}*/
RGB color.
Definition: ai_color.h:31
AI_API AI_PURE bool AiShaderGlobalsIsObjectMatte(const AtShaderGlobals *sg)
Retrieve the matte setting for the current object.
Definition: ai_shaderglobals.cpp:930
AI_API AI_DEVICE AI_GPU_FORCE_INLINE AtRGB AiOcclusion(const AtVector &N, const AtVector &Ng, AtShaderGlobals *sg, float mint, float maxt, float spread, float falloff, const AtSampler *sampler, AtVector *Nbent)
Returns the ambient occlusion at a shading point.
Definition: ai_occlusion.cpp:199
AI_API AI_DEVICE void AiMappingLatLongDerivs(const AtVector &dir, const AtVector &dDdx, const AtVector &dDdy, float &u, float &v, float &dudx, float &dudy, float &dvdx, float &dvdy)
Derivative version of AiMappingLatLong().
Definition: ai_shaders.cpp:529
AI_API AI_DEVICE AtVector AiReflectSafe(const AtVector &I, const AtVector &N, const AtVector &Ng)
Returns specular direction from incident direction I and normal N.
Definition: ai_shaders.cpp:98
AI_API AtRGB AiIndirectDiffuse(const AtVector &N, AtShaderGlobals *sg, const AtRGB &weight)
Returns the indirect-lighting component of the irradiance at a shading point.
Definition: ai_shader_bsdf.cpp:105
AI_API AI_DEVICE void AiMappingAngularMapDerivs(const AtVector &dir, const AtVector &dDdx, const AtVector &dDdy, float &u, float &v, float &dudx, float &dudy, float &dvdx, float &dvdy)
Derivative version of AiMappingAngularMap().
Definition: ai_shaders.cpp:467
AI_API bool AiShaderGlobalsGetTriangle(const AtShaderGlobals *sg, int key, AtVector p[3])
Get triangle vertices at a given motion key.
Definition: ai_shaderglobals.cpp:66
AI_API AI_CONST AtRGB AiSchlickFresnelRGB(const AtVector &N, const AtVector &Rd, const AtRGB &Krn)
Optimized version of AiSchlickFresnel() for RGB reflectance.
Definition: ai_shaders.cpp:214
AI_API AI_DEVICE void AiWorldToScreenMatrix(const AtNode *node, float time, AtMatrix &out)
Computes world to screen matrix.
Definition: ai_camera.cpp:177
AI_API AI_DEVICE AI_GPU_FORCE_INLINE AtRGB AiSelfOcclusion(const AtVector &N, const AtVector &Ng, AtShaderGlobals *sg, float mint, float maxt, float spread, float falloff, const AtSampler *sampler, AtVector *Nbent)
Returns the ambient occlusion at a shading point, only considering the same object.
Definition: ai_occlusion.cpp:245
This represents a node in Arnold.
Axis-aligned bounding box types and utilities.
AI_API AI_DEVICE void AiCameraToWorldMatrix(const AtNode *node, float time, AtMatrix &out)
Computes camera to world matrix.
Definition: ai_camera.cpp:100
Vector math types, operators and utilities.
AI_API AI_PURE AtBBox AiShaderGlobalsGetBBoxLocal(const AtShaderGlobals *sg)
Get the object-space bounds of the current object.
Definition: ai_shaderglobals.cpp:281
Shader globals struct, methods and macros.
AtVector Ng
geometric normal
Definition: ai_shaderglobals.h:75
AI_API AI_DEVICE void AiArtisticToConductorFresnel(const AtRGB &reflectivity, const AtRGB &edgetint, AtRGB &n, AtRGB &k)
Convert artist friendly metalicl Fresnel parameters to complex refractive indices for conductor Fresn...
Definition: ai_shaders.cpp:263
AI_API void AiMappingLatLong(const AtVector &dir, float &u, float &v)
Maps a world-space direction vector to texture coordinates (u,v) based on the Latitude/Longitude mapp...
Definition: ai_shaders.cpp:511
AI_API void AiMappingMirroredBall(const AtVector &dir, float &u, float &v)
Maps a world-space direction vector to texture coordinates (u,v) based on the mirrored-ball mapping...
Definition: ai_shaders.cpp:350
Arnold String allows for fast string comparisons.
Definition: ai_string.h:46
3D point (single precision)
Definition: ai_vector.h:29
AI_DEVICE AtVector AiFaceViewer(const AtShaderGlobals *sg)
Make the surface normal face the viewer.
Definition: ai_shader_util.h:126
AI_API bool AiRefractWithDerivs(const AtVectorDv &I, const AtVectorDv &N, AtVectorDv &T, float n1, float n2)
Returns transmitted direction T from incident direction I and normal N, with derivatives.
Definition: ai_shaders.cpp:174
Color types and utilities.
Definition: ai_matrix.h:30
DLL export prefix for API functions (necessary for multi-platform development)
2D point
Definition: ai_vector.h:254
AI_API AI_DEVICE uint32_t AiShaderGlobalsGetUniformID(const AtShaderGlobals *sg)
Get unique per face, subdivision patch, curve or point ID.
Definition: ai_shaderglobals.cpp:571
AI_API void AiShaderGlobalsSetTraceSet(AtShaderGlobals *sg, const AtString set, bool inclusive)
Takes a trace-set string and assigns it to the shader globals.
Definition: ai_shaderglobals.cpp:621
AI_API AI_DEVICE AI_PURE float AiShaderGlobalsArea(const AtShaderGlobals *sg)
Computes the world space area being shaded or displaced.
Definition: ai_shaderglobals.cpp:947
AI_API AI_PURE float AiCameraGetShutterStart()
Fetch camera shutter start.
Definition: ai_camera.cpp:275
AI_API AI_DEVICE AI_CONST float AiSchlickFresnel(const AtVector &N, const AtVector &Rd, float Krn)
Computes Fresnel reflectance at an air-dielectric interface for given normal and viewing vectors...
Definition: ai_shaders.cpp:197
AI_API void AiShaderGlobalsUnsetTraceSet(AtShaderGlobals *sg)
Resets the trace-set for this shader globals.
Definition: ai_shaderglobals.cpp:641
AI_API AtVectorDv AiReflectWithDerivs(const AtVectorDv &I, const AtVectorDv &N)
Returns specular direction from incident direction I and normal N, with derivatives.
Definition: ai_shaders.cpp:77
AI_API AI_PURE AtBBox AiShaderGlobalsGetBBoxWorld(const AtShaderGlobals *sg)
Get the world-space bounds of the current object.
Definition: ai_shaderglobals.cpp:297
Shader globals data structure.
Definition: ai_shaderglobals.h:45
AI_API AI_PURE AtVector AiShaderGlobalsEvaluateBump(AtShaderGlobals *sg, AtFloatBumpEvaluator bump_func, void *data)
Computes and returns a normal based on the current shading point and the specified bump-function...
Definition: ai_shaderglobals.cpp:915
AI_API void * AiShaderGlobalsQuickAlloc(const AtShaderGlobals *sg, uint32_t size)
Allocates temporary memory for this ray-tree.
Definition: ai_shaderglobals.cpp:663
AI_API AI_CONST float AiDielectricFresnel(const AtVector &N, const AtVector &Rd, float eta)
Computes Fresnel reflectance at a dielectric interface for given normal and viewing vectors...
Definition: ai_shaders.cpp:245
AI_API bool AiShaderGlobalsGetVertexNormals(const AtShaderGlobals *sg, int key, AtVector n[3])
Get normal vectors for all triangle vertices.
Definition: ai_shaderglobals.cpp:121
AI_API AtNode * AiShaderGlobalsGetShader(const AtShaderGlobals *sg)
Get shader assigned to the object at the current shading point.
Definition: ai_shaderglobals.cpp:593
AI_DEVICE constexpr float AiV3Dot(const AtVector &a, const AtVector &b)
Dot product:
Definition: ai_vector.h:626
AI_API AI_CONST AtRGB AiConductorFresnel(const AtVector &N, const AtVector &Rd, const AtRGB &n, const AtRGB &k)
Computes Fresnel reflectance at a conductor interface for given normal and viewing vectors...
Definition: ai_shaders.cpp:230
AI_API AI_PURE AtVector2 AiShaderGlobalsGetPixelMotionVector(const AtShaderGlobals *sg, float time0, float time1)
Compute motion vector.
Definition: ai_shaderglobals.cpp:497
AI_API void AiShaderGlobalsGetPositionAtTime(const AtShaderGlobals *sg, float time, AtVector &P, AtVector *N, AtVector *Ng, AtVector *Ns)
Reproject the shading point to a different time.
Definition: ai_shaderglobals.cpp:333
AI_API AI_DEVICE void AiFaceForward(AtVector &N, const AtVector &I)
Make a normal vector face forward with respect to a given vector.
Definition: ai_shaders.cpp:277
AI_API AI_DEVICE bool AiRefract(const AtVector &I, const AtVector &N, AtVector &T, float n1, float n2)
Returns transmitted direction T from incident direction I and normal N.
Definition: ai_shaders.cpp:134
AI_API bool AiShaderGlobalsGetVertexUVs(const AtShaderGlobals *sg, const AtString uvset, AtVector2 uv[3])
Get UV coordinates for all triangle vertices.
Definition: ai_shaderglobals.cpp:172
AI_API uint32_t AiShaderGlobalsGetPolygon(const AtShaderGlobals *sg, int key, AtVector *p)
Get polygon vertices at a given motion key.
Definition: ai_shaderglobals.cpp:199
Opaque data type for a sampler.
float(* AtFloatBumpEvaluator)(AtShaderGlobals *sg, void *data)
This function pointer points to float-based bump-mapping function for use by AiShaderGlobalsEvaluateB...
Definition: ai_shader_util.h:88
AtVector Rd
ray direction (normalized)
Definition: ai_shaderglobals.h:53
AI_API AI_DEVICE void AiWorldToCameraMatrix(const AtNode *node, float time, AtMatrix &out)
Computes world to camera matrix.
Definition: ai_camera.cpp:137
AI_API AI_PURE float AiShaderGlobalsEdgeLength(const AtShaderGlobals *sg)
Computes the maximum (for now) edge length of a given polygon.
Definition: ai_wireframe.cpp:249
AI_API AI_DEVICE AtRGB AiShaderGlobalsStochasticOpacity(AtShaderGlobals *sg, const AtRGB &opacity)
Performs some optimizations and returns a modified opacity value which allows for increased performan...
Definition: ai_shaderglobals.cpp:697
3D axis-aligned bounding box (uses single-precision)
Definition: ai_bbox.h:32
AI_API AI_DEVICE void AiMappingMirroredBallDerivs(const AtVector &dir, const AtVector &dDdx, const AtVector &dDdy, float &u, float &v, float &dudx, float &dudy, float &dvdx, float &dvdy)
Derivative version of AiMappingMirroredBall().
Definition: ai_shaders.cpp:368
AtVector N
shading normal (in object space during displacement)
Definition: ai_shaderglobals.h:73
Vector with differentials.
Definition: ai_vector.h:515
AI_API AI_DEVICE AI_PURE float AiWireframe(const AtShaderGlobals *sg, float line_width, bool raster_space, int edge_type)
Computes wireframe shading for a mesh.
Definition: ai_wireframe.cpp:29
AI_API AI_DEVICE AtVector AiReflect(const AtVector &I, const AtVector &N)
Returns specular direction from incident direction I and normal N.
Definition: ai_shaders.cpp:61
AI_API AI_PURE float AiCameraGetShutterEnd()
Fetch camera shutter end.
Definition: ai_camera.cpp:291
AI_API AtRGB AiDirectDiffuse(const AtVector &N, AtShaderGlobals *sg)
Returns the direct-lighting component of the irradiance at a shading point.
Definition: ai_shaders.cpp:46
AI_API void AiMappingAngularMap(const AtVector &dir, float &u, float &v)
Maps a world-space direction vector to texture coordinates (u,v) based on an angular mapping...
Definition: ai_shaders.cpp:449

© 2020 Autodesk, Inc. · All rights reserved · www.arnoldrenderer.com