private void GUI_SetCullingMode(Material material) { int cullMode = material.GetInt("_CullMode"); if ((int)CullingMode.CullingOff == cullMode) { cullingMode = CullingMode.CullingOff; } else if ((int)CullingMode.FrontCulling == cullMode) { cullingMode = CullingMode.FrontCulling; } else { cullingMode = CullingMode.BackCulling; } cullingMode = (CullingMode)EditorGUILayout.EnumPopup("Culling Mode", cullingMode); if (cullingMode == CullingMode.CullingOff) { material.SetInt("_CullMode", 0); } else if (cullingMode == CullingMode.FrontCulling) { material.SetInt("_CullMode", 1); } else { material.SetInt("_CullMode", 2); } }
public void setCullingMode(CullingMode mode) { OgrePINVOKE.Technique_setCullingMode(swigCPtr, (int)mode); if (OgrePINVOKE.SWIGPendingException.Pending) { throw OgrePINVOKE.SWIGPendingException.Retrieve(); } }
/// <summary> /// Function to set the culling mode. /// </summary> /// <param name="cullMode">The current culling mode.</param> /// <param name="isFrontCounterClockwise">[Optional] <b>true</b> if vertices that are ordered counter-clockwise are considered front facing, <b>false</b> if not.</param> /// <returns>The fluent interface for this builder.</returns> public GorgonRasterStateBuilder CullMode(CullingMode cullMode, bool?isFrontCounterClockwise = null) { WorkingState.CullMode = cullMode; if (isFrontCounterClockwise != null) { WorkingState.IsFrontCounterClockwise = isFrontCounterClockwise.Value; } return(this); }
public static void SetCulling(CullingMode cullingMode) { if (cullingMode == CullingMode.SHOW_BOTH) { GL.Disable(EnableCap.CullFace); return; } GL.Enable(EnableCap.CullFace); GL.CullFace(cullingMode switch { CullingMode.SHOW_FRONT_ONLY => CullFaceMode.Back, CullingMode.SHOW_BACK_ONLY => CullFaceMode.Front, CullingMode.SHOW_NEITHER => CullFaceMode.FrontAndBack, _ => throw new ArgumentOutOfRangeException( nameof(cullingMode), cullingMode, null) });
public static CullMode Convert(CullingMode mode, bool flip) { switch (mode) { case CullingMode.None: return(CullMode.None); case CullingMode.Clockwise: return(flip ? CullMode.CullCounterClockwiseFace : CullMode.CullClockwiseFace); case CullingMode.CounterClockwise: return(flip ? CullMode.CullClockwiseFace : CullMode.CullCounterClockwiseFace); } return(0); }
void DoCullingMode() { MaterialProperty type = FindProperty("_Cull"); CullingMode mode = (CullingMode)type.floatValue; EditorGUI.BeginChangeCheck(); mode = (CullingMode)EditorGUILayout.EnumPopup( MakeLabel("Culling Mode"), mode); if (EditorGUI.EndChangeCheck()) { RecordAction("Culling Mode"); CullSettings settings = CullSettings.modes[(int)mode]; foreach (Material m in editor.targets) { m.SetInt("_Cull", (int)settings.cull); } } }
public void setCullingMode(CullingMode mode) { Material_setCullingMode(resource, mode); }
static void Render <T>(Canvas canvas, IReadOnlyList <Triangle> triangles, PixelShader <T> pixelShader, CullingMode culling, T[] vertices, Vector4[] positions) where T : unmanaged { int width = canvas.Width; int height = canvas.Height; Rectangle viewport = new Rectangle(0, 0, height, width); var colorBuffer = canvas.ColorBuffer; var depthBuffer = canvas.DepthBuffer; var interpolator = InterpolatorCache <T> .Instance; Parallel.ForEach(triangles, triangle => { ref var vertex0 = ref vertices[triangle.FaceIndex0]; ref var vertex1 = ref vertices[triangle.FaceIndex1];
public static void Render <T>(Canvas canvas, IReadOnlyList <Face> faces, IReadOnlyList <Triangle> triangles, VertexShader <T> vertexShader, PixelShader <T> pixelShader, CullingMode culling) where T : unmanaged { T[] vertices = ArrayPool <T> .Shared.Rent(faces.Count); try { Vector4[] positions = ArrayPool <Vector4> .Shared.Rent(faces.Count); try { Parallel.For( 0, faces.Count, i => vertexShader(faces[i], out vertices[i], out positions[i]) ); Render(canvas, triangles, pixelShader, culling, vertices, positions); } finally { ArrayPool <Vector4> .Shared.Return(positions); } } finally { ArrayPool <T> .Shared.Return(vertices); } }
public static bool FaceRaycast(Ray worldRay, Mesh mesh, Transform meshTransform, out RaycastHit hit, CullingMode cullingMode = CullingMode.Back) { // Transform ray into model space worldRay.origin -= meshTransform.position; // Why doesn't worldToLocalMatrix apply translation? worldRay.origin = meshTransform.worldToLocalMatrix * worldRay.origin; worldRay.direction = meshTransform.worldToLocalMatrix * worldRay.direction; Vector3[] positions = mesh.vertices; int[] indexes = mesh.triangles; float outDistance = Mathf.Infinity; int outHitFace = -1; Vector3 outNrm = Vector3.zero; for (int i = 0; i < indexes.Length; i += 3) { Vector3 a = positions[indexes[i + 0]]; Vector3 b = positions[indexes[i + 1]]; Vector3 c = positions[indexes[i + 2]]; Vector3 nrm = Vector3.Cross(b - a, c - a); float dot = Vector3.Dot(worldRay.direction, nrm); bool skip = false; switch (cullingMode) { case CullingMode.Front: if (dot < 0f) { skip = true; } break; case CullingMode.Back: if (dot > 0f) { skip = true; } break; } var dist = 0f; Vector3 point; if (!skip && MathHelper.RayIntersectsTriangle(worldRay, a, b, c, out dist, out point)) { if (dist > outDistance || dist > outDistance) { continue; } outNrm = nrm; outHitFace = i; outDistance = dist; } } hit = new RaycastHit(outDistance, worldRay.GetPoint(outDistance), outNrm, outHitFace); return(outHitFace > -1); }
public static CullMode Convert( CullingMode mode, bool flip ) { switch ( mode ) { case CullingMode.None: return CullMode.None; case CullingMode.Clockwise: return flip ? CullMode.CullCounterClockwiseFace : CullMode.CullClockwiseFace; case CullingMode.CounterClockwise: return flip ? CullMode.CullClockwiseFace : CullMode.CullCounterClockwiseFace; } return 0; }
/// <summary> /// Base constructor. /// </summary> public RenderSystem() { // default to true isVSync = true; // default to true depthWrite = true; // This means CULL clockwise vertices, i.e. front of poly is counter-clockwise // This makes it the same as OpenGL and other right-handed systems cullingMode = Axiom.Graphics.CullingMode.Clockwise; }
public void setCullingMode(CullingMode mode) { Technique_setCullingMode(technique, mode); }
/// <summary> /// Find the nearest face intersected by InWorldRay on this pb_Object. /// </summary> /// <param name="worldRay">A ray in world space.</param> /// <param name="mesh">The ProBuilder object to raycast against.</param> /// <param name="hit">If the mesh was intersected, hit contains information about the intersect point in local coordinate space.</param> /// <param name="distance">The distance from the ray origin to the intersection point.</param> /// <param name="cullingMode">Which sides of a face are culled when hit testing. Default is back faces are culled.</param> /// <param name="ignore">Optional collection of faces to ignore when raycasting.</param> /// <returns>True if the ray intersects with the mesh, false if not.</returns> internal static bool FaceRaycast(Ray worldRay, ProBuilderMesh mesh, out RaycastHit hit, float distance, CullingMode cullingMode, HashSet <Face> ignore = null) { // Transform ray into model space worldRay.origin -= mesh.transform.position; // Why doesn't worldToLocalMatrix apply translation? worldRay.origin = mesh.transform.worldToLocalMatrix * worldRay.origin; worldRay.direction = mesh.transform.worldToLocalMatrix * worldRay.direction; var positions = mesh.positionsInternal; var faces = mesh.facesInternal; float OutHitPoint = Mathf.Infinity; int OutHitFace = -1; Vector3 OutNrm = Vector3.zero; // Iterate faces, testing for nearest hit to ray origin. Optionally ignores backfaces. for (int i = 0, fc = faces.Length; i < fc; ++i) { if (ignore != null && ignore.Contains(faces[i])) { continue; } int[] indexes = mesh.facesInternal[i].indexesInternal; for (int j = 0, ic = indexes.Length; j < ic; j += 3) { Vector3 a = positions[indexes[j + 0]]; Vector3 b = positions[indexes[j + 1]]; Vector3 c = positions[indexes[j + 2]]; Vector3 nrm = Vector3.Cross(b - a, c - a); float dot = Vector3.Dot(worldRay.direction, nrm); bool skip = false; switch (cullingMode) { case CullingMode.Front: if (dot < 0f) { skip = true; } break; case CullingMode.Back: if (dot > 0f) { skip = true; } break; } var dist = 0f; Vector3 point; if (!skip && Math.RayIntersectsTriangle(worldRay, a, b, c, out dist, out point)) { if (dist > OutHitPoint || dist > distance) { continue; } OutNrm = nrm; OutHitFace = i; OutHitPoint = dist; } } } hit = new RaycastHit(OutHitPoint, worldRay.GetPoint(OutHitPoint), OutNrm, OutHitFace); return(OutHitFace > -1); }
public void setCullingMode(CullingMode mode) { Pass_setCullingMode(pass, mode); }
private static extern void Pass_setCullingMode(IntPtr pass, CullingMode mode);
private static extern void Technique_setCullingMode(IntPtr technique, CullingMode mode);
/// <summary> /// Find the all faces intersected by InWorldRay on this pb_Object. /// </summary> /// <param name="InWorldRay">A ray in world space.</param> /// <param name="mesh">The ProBuilder object to raycast against.</param> /// <param name="hits">If the mesh was intersected, hits contains all intersection point RaycastHit information.</param> /// <param name="cullingMode">What sides of triangles does the ray intersect with.</param> /// <param name="ignore">Optional collection of faces to ignore when raycasting.</param> /// <returns>True if the ray intersects with the mesh, false if not.</returns> internal static bool FaceRaycast( Ray InWorldRay, ProBuilderMesh mesh, out List <RaycastHit> hits, CullingMode cullingMode, HashSet <Face> ignore = null) { // Transform ray into model space InWorldRay.origin -= mesh.transform.position; // Why doesn't worldToLocalMatrix apply translation? InWorldRay.origin = mesh.transform.worldToLocalMatrix * InWorldRay.origin; InWorldRay.direction = mesh.transform.worldToLocalMatrix * InWorldRay.direction; Vector3[] vertices = mesh.positionsInternal; hits = new List <RaycastHit>(); // Iterate faces, testing for nearest hit to ray origin. Optionally ignores backfaces. for (int CurFace = 0; CurFace < mesh.facesInternal.Length; ++CurFace) { if (ignore != null && ignore.Contains(mesh.facesInternal[CurFace])) { continue; } int[] indexes = mesh.facesInternal[CurFace].indexesInternal; for (int CurTriangle = 0; CurTriangle < indexes.Length; CurTriangle += 3) { Vector3 a = vertices[indexes[CurTriangle + 0]]; Vector3 b = vertices[indexes[CurTriangle + 1]]; Vector3 c = vertices[indexes[CurTriangle + 2]]; var dist = 0f; Vector3 point; if (Math.RayIntersectsTriangle(InWorldRay, a, b, c, out dist, out point)) { Vector3 nrm = Vector3.Cross(b - a, c - a); float dot; // vars used in loop switch (cullingMode) { case CullingMode.Front: dot = Vector3.Dot(InWorldRay.direction, nrm); if (dot > 0f) { goto case CullingMode.FrontBack; } break; case CullingMode.Back: dot = Vector3.Dot(InWorldRay.direction, nrm); if (dot < 0f) { goto case CullingMode.FrontBack; } break; case CullingMode.FrontBack: hits.Add(new RaycastHit(dist, InWorldRay.GetPoint(dist), nrm, CurFace)); break; } continue; } } } return(hits.Count > 0); }
private static extern void Material_setCullingMode(IntPtr material, CullingMode mode);
/// <summary> /// Default constructor. /// </summary> /// <param name="parent">Technique that owns this Pass.</param> /// <param name="index">Index of this pass.</param> public Pass( Technique parent, int index ) { this._parent = parent; this._index = index; lock ( passLock ) { this.passId = nextPassId++; } // color defaults _ambient = ColorEx.White; _diffuse = ColorEx.White; _specular = ColorEx.Black; _emissive = ColorEx.Black; // by default, don't override the scene's fog settings _fogOverride = false; _fogMode = FogMode.None; _fogColor = ColorEx.White; _fogStart = 0; _fogEnd = 1; _fogDensity = 0.001f; // default blending (overwrite) _sourceBlendFactor = SceneBlendFactor.One; _destinationBlendFactor = SceneBlendFactor.Zero; // depth buffer settings _depthCheck = true; _depthWrite = true; _colorWriteEnabled = true; _depthFunction = CompareFunction.LessEqual; // cull settings _cullingMode = CullingMode.Clockwise; _manualCullingMode = ManualCullingMode.Back; // light settings _lightingEnabled = true; _runOnlyForOneLightType = true; _onlyLightType = LightType.Point; _shadingMode = Shading.Gouraud; // Default max lights to the global max _maxSimultaneousLights = Config.MaxSimultaneousLights; _name = index.ToString(); IterationCount = 1; DirtyHash(); }
/// <summary> /// Default constructor. /// </summary> /// <param name="parent">Technique that owns this Pass.</param> /// <param name="index">Index of this pass.</param> public Pass(Technique parent, int index) { this.parent = parent; this.index = index; lock (passLock) { this.passId = nextPassId++; } // color defaults ambient = ColorEx.White; diffuse = ColorEx.White; specular = ColorEx.Black; emissive = ColorEx.Black; // by default, don't override the scene's fog settings fogOverride = false; fogMode = FogMode.None; fogColor = ColorEx.White; fogStart = 0; fogEnd = 1; fogDensity = 0.001f; // default blending (overwrite) sourceBlendFactor = SceneBlendFactor.One; destBlendFactor = SceneBlendFactor.Zero; // depth buffer settings depthCheck = true; depthWrite = true; colorWrite = true; alphaRejectFunction = CompareFunction.AlwaysPass; alphaRejectValue = 0; depthFunc = CompareFunction.LessEqual; depthBiasConstant = 0f; depthBiasSlopeScale = 0f; // cull settings cullMode = CullingMode.Clockwise; manualCullMode = ManualCullingMode.Back; // light settings lightingEnabled = true; runOnlyForOneLightType = true; lightsPerIteration = 1; runOncePerLight = false; onlyLightType = LightType.Point; shadeOptions = Shading.Gouraud; // Default max lights to the global max maxLights = Config.MaxSimultaneousLights; // Starting light index startLight = 0; // Default to solid sceneDetail = SceneDetailLevel.Solid; // Iteration count of 1 passIterationCount = 1; // pointSize, etc. pointSize = 1.0f; pointMinSize = 0f; pointMaxSize = 0f; pointSpritesEnabled = false; pointAttenuationEnabled = false; pointAttenuationConstant = 1.0f; pointAttenuationLinear = 0f; pointAttenuationQuadratic = 0f; contentTypeLookupBuilt = false; name = index.ToString(); DirtyHash(); }