private void RenderBoundingBox(RenderingContext rc) { rc.PushMatricies(); bbox.Render(this, rc); rc.PopMatricies(); }
public override void Render(RenderingContext rc) { base.Render(rc); rc.PushMatricies(); // following code below doesnt work because of depth first traversal //rc.Translate(this.Translation); //rc.Scale(this.Scale, this.ScaleOrientation); //rc.Rotate(this.Rotation); }
private void RenderSkybox(RenderingContext rc) { rc.PushMatricies(); // Inner cubemapped skybox //this._shapeInnerCube.Render(rc); _shaderInnerCube.Use(); #if APPLY_BACKDROP Matrix4 mat4 = rc.cam.GetWorldOrientation(); _shaderInnerCube.SetFieldValue("modelview", ref mat4); #endif _shaderInnerCube.SetFieldValue("scale", scaleCube); _shaderInnerCube.SetFieldValue("size", size); _shaderInnerCube.SetFieldValue("coloringEnabled", 0); _shaderInnerCube.SetFieldValue("texturingEnabled", 1); _shaderInnerCube.SetFieldValue("lightingEnabled", 0); _shaderInnerCube.SetFieldValue("projection", ref rc.matricies.projection); _shaderInnerCube.SetFieldValue("camscale", rc.cam.Scale.X); _shaderInnerCube.SetFieldValue("X3DScale", rc.matricies.Scale); texture2d = GL.IsEnabled(EnableCap.Texture2D); if (!texture2d) { GL.Enable(EnableCap.Texture2D); } #if APPLY_BACKDROP GL.DepthMask(false); #endif GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.TextureCubeMap, tex_cube); GL.BindBuffer(BufferTarget.ArrayBuffer, cubeHandle.vbo3); Buffering.ApplyBufferPointers(_shaderInnerCube); GL.DrawArrays(PrimitiveType.Triangles, 0, cubeHandle.NumVerticies3); #if APPLY_BACKDROP GL.DepthMask(true); #endif if (!texture2d) { GL.Disable(EnableCap.Texture2D); } rc.PopMatricies(); }
private void RenderSkydome(RenderingContext rc) { rc.PushMatricies(); texture2d = GL.IsEnabled(EnableCap.Texture2D); if (texture2d) { GL.Disable(EnableCap.Texture2D); } Matrix4 mat4; // Outer sky Sphere //this._shapeOuter.Render(rc); _shaderOuter.Use(); #if APPLY_BACKDROP mat4 = rc.cam.GetWorldOrientation(); _shaderOuter.SetFieldValue("modelview", ref mat4); #endif //_shaderOuter.SetFieldValue("scale", scaleSky); _shaderOuter.SetFieldValue("scale", size); _shaderOuter.SetFieldValue("size", size); if (skydomeColors != null && skydomeColors.Length > 0) { _shaderOuter.SetFieldValue("skyColors", this.skydomeColors.Length);//_shaderOuter.SetFieldValue("skyColors", this.colors.Length); _shaderOuter.SetFieldValue("skyColor", this.skydomeColors, 255 * 3); } //_shaderOuter.SetFieldValue("skyColor", this.colors, 255 * 3); _shaderOuter.SetFieldValue("skyAngle", this.angles, 255); _shaderOuter.SetFieldValue("isGround", 0); _shaderOuter.SetFieldValue("bbox", bboxOuter); _shaderOuter.SetFieldValue("max", max); _shaderOuter.SetFieldValue("min", min); _shaderOuter.SetFieldValue("projection", ref rc.matricies.projection); _shaderOuter.SetFieldValue("camscale", rc.cam.Scale.X); _shaderOuter.SetFieldValue("X3DScale", rc.matricies.Scale); #if APPLY_BACKDROP GL.DepthMask(false); #endif if (skydomeComputed) { GL.BindTexture(TextureTarget.Texture2D, skydomeTexture); } GL.BindBuffer(BufferTarget.ArrayBuffer, outerHandle.vbo4); Buffering.ApplyBufferPointers(_shaderOuter); GL.DrawArrays(PrimitiveType.Quads, 0, outerHandle.NumVerticies4); if (skydomeComputed) { GL.BindTexture(TextureTarget.Texture2D, 0); } #if APPLY_BACKDROP GL.DepthMask(true); #endif rc.PopMatricies(); // rc.PushMatricies(); // // Inner ground Hemisphere // //RenderCube(rc); // _shaderInner.Use(); //#if APPLY_BACKDROP // mat4 = rc.cam.GetWorldOrientation(); // _shaderInner.SetFieldValue("modelview", ref mat4); //#endif // _shaderInner.SetFieldValue("scale", scaleGround); // _shaderInner.SetFieldValue("size", size); // _shaderOuter.SetFieldValue("skyColor", this.skydomeColors, 255 * 3); // //_shaderInner.SetFieldValue("skyColor", this.colors, 255 * 3); // _shaderInner.SetFieldValue("skyAngle", this.angles, 255); // _shaderInner.SetFieldValue("skyColors", this.colors.Length); // _shaderInner.SetFieldValue("isGround", 1); // _shaderInner.SetFieldValue("bbox", bboxInner); // _shaderInner.SetFieldValue("projection", ref rc.matricies.projection); // _shaderInner.SetFieldValue("camscale", rc.cam.Scale.X); // _shaderInner.SetFieldValue("X3DScale", rc.matricies.Scale); //#if APPLY_BACKDROP // GL.DepthMask(false); //#endif // GL.BindBuffer(BufferTarget.ArrayBuffer, innerHandle.vbo4); // Buffering.ApplyBufferPointers(_shaderInner); // GL.DrawArrays(PrimitiveType.Quads, 0, innerHandle.NumVerticies4); //#if APPLY_BACKDROP // GL.DepthMask(true); //#endif // rc.PopMatricies(); if (texture2d) { GL.Enable(EnableCap.Texture2D); } }
private void RenderShape(RenderingContext rc) { // Refactor tessellation var shader = CurrentShader; if (shader != null) { shader.Use(); if (bbox != null) { shader.SetFieldValue("bboxMaxWidth", bbox.Width); shader.SetFieldValue("bboxMaxHeight", bbox.Height); shader.SetFieldValue("bboxMaxDepth", bbox.Depth); shader.SetFieldValue("bbox_x", bbox.Width); shader.SetFieldValue("bbox_y", bbox.Height); shader.SetFieldValue("bbox_z", bbox.Depth); } shader.SetFieldValue("coloringEnabled", coloring ? 1 : 0); if (typeof(ElevationGrid).IsInstanceOfType(geometry)) { shader.SetFieldValue("lightingEnabled", 0); shader.SetFieldValue("texturingEnabled", 1); } Vector3 tmp = rc.matricies.Scale; if (typeof(Text).IsInstanceOfType(geometry)) { rc.PushMatricies(); rc.matricies.Scale *= 200f; } if (depthMask == false) { //REFACTOR!! Matrix4 mat4 = Matrix4.Identity; //Quaternion qRotFix = QuaternionExtensions.EulerToQuat(rc.cam.calibOrient.X, rc.cam.calibOrient.Y, rc.cam.calibOrient.Z); //mat4 *= Matrix4.CreateTranslation(rc.cam.calibTrans) * Matrix4.CreateFromQuaternion(qRotFix); Quaternion qRotFix = QuaternionExtensions.EulerToQuat(0.15f, 3.479997f, 0f); mat4 *= Matrix4.CreateTranslation(new Vector3(0f, 0f, -0.29f)) * Matrix4.CreateFromQuaternion(qRotFix); // test weapon/gun rendering fixed in front of player //TODO: port this to X3D shader.SetFieldValue("modelview", ref mat4); if (quadShader != null) { quadShader.SetFieldValue("modelview", ref mat4); } //GL.DepthMask(false); } shader.SetFieldValue("size", size); shader.SetFieldValue("scale", scale); if (loadedGeometry) { if (shader.IsTessellator) { RenderTessellator(rc); } else { if (typeof(PointSet).IsInstanceOfType(geometry)) { RenderPoints(rc); } else if (typeof(IndexedLineSet).IsInstanceOfType(geometry) || typeof(LineSet).IsInstanceOfType(geometry)) { RenderLines(rc); } else { RenderTriangles(rc); RenderQuads(rc); } } } if (depthMask == false) { //GL.DepthMask(true); } if (typeof(Text).IsInstanceOfType(geometry)) { rc.PopMatricies(); rc.matricies.Scale = tmp; } } }
public override void Render(RenderingContext rc) { base.Render(rc); rc.PushMatricies(); //if (!loadedGeometry) return; // PREPARE shape for rendering NormalMatrix = new Matrix3(rc.matricies.modelview); // NormalMatrix = M4GetUpper3x3(ModelviewMatrix); var shader = CurrentShader; if (shader != null) { // CurrentShader = linkedShaders; shader.Use(); if (shader.IsTessellator) { if (shader.IsBuiltIn) { // its a built in system shader so we are using the the fixed parameter inbuilt tesselator CurrentShader.SetFieldValue("TessLevelInner", this.tessLevelInner); CurrentShader.SetFieldValue("TessLevelOuter", this.tessLevelOuter); } } shader.SetFieldValue("lightingEnabled", 1); shader.SetFieldValue("headlightEnabled", 0); shader.SetFieldValue("calib1", rc.cam.calibTrans); shader.SetFieldValue("calib2", rc.cam.calibOrient); if (depthMask) { Matrix4 MVP = ApplyGeometricTransformations(rc, shader, this); Vector3 lookat = QuaternionExtensions.Rotate(rc.cam.Orientation, Vector3.UnitZ); Vector3 forward = new Vector3(lookat.X, 0, lookat.Z).Normalized(); Vector3 up = Vector3.UnitY; Vector3 left = up.Cross(forward); Vector2 orient; Vector3 position; orient = QuaternionExtensions.ExtractPitchYawRoll(rc.cam.Orientation.Inverted()).Xy; // pitch and yaw only position = rc.cam.Position; shader.SetFieldValue("headlightEnabled", NavigationInfo.HeadlightEnabled ? 1 : 0); shader.SetFieldValue("sceneCameraPosition", position); shader.SetFieldValue("model", ref MVP); shader.SetFieldValue("orientation", orient); shader.SetFieldValue("lookat", rc.cam.Direction); shader.SetFieldValue("forward", forward); shader.SetFieldValue("up", up); shader.SetFieldValue("left", left); } else { //REFACTOR!! RefreshDefaultUniforms(shader); if (shader.IsTessellator) { RefreshTessUniforms(shader); } //Matrix4 MVP = rc.cam.GetWorldOrientation() ; //shader.SetFieldValue("modelview", ref MVP); //shader.SetFieldValue("modelview", ref MVP); //GL.UniformMatrix4(uniformModelview, false, ref rc.matricies.modelview); shader.SetFieldValue("projection", ref rc.matricies.projection); shader.SetFieldValue("camscale", rc.cam.Scale.X); //GL.Uniform1(uniformCameraScale, rc.cam.Scale.X); shader.SetFieldValue("X3DScale", rc.matricies.Scale); //GL.Uniform3(uniformX3DScale, rc.matricies.Scale); shader.SetFieldValue("coloringEnabled", coloring ? 1 : 0); shader.SetFieldValue("texturingEnabled", this.texturingEnabled ? 1 : 0); //GL.Uniform1(uniforms.a_texturingEnabled, this.texturingEnabled ? 1 : 0); shader.SetFieldValue("normalmatrix", ref NormalMatrix); } ApplyAppearance(rc); // RENDER shape RenderShape(rc); } if (drawBoundingBox && bbox != null) { RenderBoundingBox(rc); } }