MCPcopy
hub / github.com/g3n/engine / Render

Method Render

renderer/renderer.go:99–208  ·  view source on GitHub ↗

Render renders the specified scene using the specified camera. Returns an an error.

(scene core.INode, cam camera.ICamera)

Source from the content-addressed store, hash-verified

97
98// Render renders the specified scene using the specified camera. Returns an an error.
99func (r *Renderer) Render(scene core.INode, cam camera.ICamera) error {
100
101 // Updates world matrices of all scene nodes
102 scene.UpdateMatrixWorld()
103
104 // Build RenderInfo
105 cam.ViewMatrix(&r.rinfo.ViewMatrix)
106 cam.ProjMatrix(&r.rinfo.ProjMatrix)
107
108 // Clear stats and scene arrays
109 r.stats = Stats{}
110 r.ambLights = r.ambLights[0:0]
111 r.dirLights = r.dirLights[0:0]
112 r.pointLights = r.pointLights[0:0]
113 r.spotLights = r.spotLights[0:0]
114 r.others = r.others[0:0]
115 r.graphics = r.graphics[0:0]
116 r.grmatsOpaque = r.grmatsOpaque[0:0]
117 r.grmatsTransp = r.grmatsTransp[0:0]
118 r.zLayers = make(map[int][]gui.IPanel)
119 r.zLayers[0] = make([]gui.IPanel, 0)
120 r.zLayerKeys = r.zLayerKeys[0:1]
121 r.zLayerKeys[0] = 0
122
123 // Prepare for frustum culling
124 var proj math32.Matrix4
125 proj.MultiplyMatrices(&r.rinfo.ProjMatrix, &r.rinfo.ViewMatrix)
126 frustum := math32.NewFrustumFromMatrix(&proj)
127
128 // Classify scene and all scene nodes, culling renderable IGraphics which are fully outside of the camera frustum
129 r.classifyAndCull(scene, frustum, 0)
130
131 // Set light counts in shader specs
132 r.specs.AmbientLightsMax = len(r.ambLights)
133 r.specs.DirLightsMax = len(r.dirLights)
134 r.specs.PointLightsMax = len(r.pointLights)
135 r.specs.SpotLightsMax = len(r.spotLights)
136
137 // Pre-calculate MV and MVP matrices and compile initial lists of opaque and transparent graphic materials
138 for _, gr := range r.graphics {
139 // Calculate MV and MVP matrices for all non-GUI graphics to be rendered
140 gr.CalculateMatrices(r.gs, &r.rinfo)
141 // Append all graphic materials of this graphic to lists of graphic materials to be rendered
142 materials := gr.Materials()
143 for i := range materials {
144 r.stats.GraphicMats++
145 if materials[i].IMaterial().GetMaterial().Transparent() {
146 r.grmatsTransp = append(r.grmatsTransp, &materials[i])
147 } else {
148 r.grmatsOpaque = append(r.grmatsOpaque, &materials[i])
149 }
150 }
151 }
152
153 // TODO: If both GraphicMaterials belong to same Graphic we might want to keep their relative order...
154 // Z-sort graphic materials back to front
155 if r.sortObjects {
156 zSort(r.grmatsOpaque)

Callers

nothing calls this directly

Calls 15

MultiplyMatricesMethod · 0.95
classifyAndCullMethod · 0.95
renderGraphicMaterialMethod · 0.95
NewFrustumFromMatrixFunction · 0.92
zSortFunction · 0.85
CalculateMatricesMethod · 0.80
MaterialsMethod · 0.80
TransparentMethod · 0.80
IMaterialMethod · 0.80
UpdateMatrixWorldMethod · 0.65
ViewMatrixMethod · 0.65
ProjMatrixMethod · 0.65

Tested by

no test coverage detected