A textmesh pro based emissive light method
By expanding the character vertex coordinates and correcting the sampling, the gap between the inner and outer frames is formed, which solves the problems of the unsmooth outer glow effect and limited display range in TextMeshPro, and achieves a soft outer glow effect that extends beyond the character outline.
Patent Information
- Application Number
- CN202210964214.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-11
- Publication Date
- 2025-12-19
- Estimated Expiration
- 2042-08-11
AI Technical Summary
TextMeshPro's external glow effect has harsh edges, is not soft enough, and has a limited display area, failing to meet user needs.
By expanding the vertex coordinates of the original characters, the gap between the inner and outer frames is formed as the outer glow area. The transparency value is calculated by performing two corrections and samplings to achieve a soft outer glow effect.
It achieves a soft outer glow effect, extending beyond the character outline and improving the softness and display range of the outer glow.
Smart Images

Figure CN115239867B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, in particular to a TextMeshPro-based outer light emitting method. BACKGROUND
[0002] TextMeshPro is a text special effect plug-in in Unity, which realizes different text special effects by rendering text, such as character outer light emitting and character flickering. However, in actual application, it is found that the edge of the outer light emitting effect of TextMeshPro is very hard and not soft enough, and the display range is limited and cannot exceed the outline of the character, which cannot meet the needs of users. In order to obtain a more soft and farther display outer light emitting effect beyond the outline of the character, a method different from the implementation method of TextMeshPro outer light emitting is needed to realize a more soft outer light emitting effect than TextMeshPro. SUMMARY
[0003] To solve the above problems, the present application provides a TextMeshPro-based outer light emitting method.
[0004] The present application adopts the following technical scheme:
[0005] A TextMeshPro-based outer light emitting method, comprising the following steps:
[0006] S1, extending the vertex coordinates of the original character, writing the uv coordinates and width and height of the original character;
[0007] S2, the frame formed by the uv coordinates of the original character is an inner frame, the vertex range of each original character is enlarged to form an outer frame, and the gap between the inner frame and the outer frame is an outer light emitting area;
[0008] S3, twice correction and sampling are performed on the surrounding pixel points of the current original character to obtain the transparency value of each sampling point;
[0009] S31, the uv coordinates of the original character are corrected for the first time, the frame of the original character is enlarged to coincide with the outer frame, thereby obtaining an enlarged character, and then the entire character body is sampled according to the corrected uv coordinates to obtain the transparency value of the character body;
[0010] S32, the uv coordinates corrected for the first time are corrected for the second time to restore the character to the size of the original character, and the outer light emitting area is sampled to obtain the transparency value of the outer light emitting area;
[0011] S4. Take the average value of the transparency value of the character body and the transparency value of the outer glowing area obtained by sampling to obtain the final transparency value of the character body and the transparency value of the outer glowing area.
[0012] S5. Set the color of the outer glow and render the outer glow area according to the transparency value of the outer glow area to obtain the outer glow effect;
[0013] S6. Set the color of the character and render the character area according to the transparency value of the character itself to obtain the final character with an outer glow effect.
[0014] Further, step S2 specifically involves adding an outer glow area parameter to the text material of the character. The unit of the outer glow area parameter is pixels, which is used to expand the display range of each character.
[0015] Further, in step S3, the sampling rule is as follows: sample N sampling points around the current pixel, where the number of sampling points N = 2 × sampling times × 2 × sampling step, and the sampling step represents the distance between the current pixel and the sampling points.
[0016] Furthermore, the first correction specifically involves adding a character gap parameter 'a' to the character material. The unit of this parameter is pixels, and it represents the character gap. The UV coordinates after the first correction are as follows: Where u and v represent the uv coordinates of the original character, normal.x represents the display width of the character, normal.y represents the display height of the character, and a represents the character spacing parameter.
[0017] Furthermore, the character spacing parameter a is set to 0.11.
[0018] Furthermore, for the second correction, the corrected uv coordinates are as follows:
[0019] u2 = remap(u, uv3.x + (uv3.y - uv3.x) × GlowScale / (2 × GlowScale + normal.x), uv3.y - (uv3.y - uv3.x) × GlowScale / (2 × GlowScale + normal.x), uv3.x, uv3.y); where u and v represent the uv coordinates of the original character, remap represents the remapping function, uv3.x represents the u coordinate of the lower left corner of the character, uv3.y represents the u coordinate of the lower right corner of the character, GlowScale represents the outer glow area parameter, and normal.x represents the display width of the character;
[0020] v2 = remap(u, uv4.x + (uv4.y - uv4.x) × GlowScale / (2 × GlowScale + normal.x), uv4.y - (uv4.y - uv4.x) × GlowScale / (2 × GlowScale + normal.y), uv4.x, uv4.y); where u and v represent the uv coordinates of the original character, remap represents the remapping function, uv4.x represents the v coordinate of the lower left corner of the character, uv4.y represents the v coordinate of the upper left corner of the character, GlowScale represents the outer glow area parameter, and normal.y represents the display height of the character.
[0021] Further, step S5 specifically involves adding an outer glow color parameter to the text material to specify an outer glow color that is different from the text.
[0022] By adopting the above technical solution, the present invention has the following advantages compared with the prior art:
[0023] This invention expands the character vertex range and combines it with modified sampling coordinates to keep the character display size unchanged. It then applies transparency values to the character area and the outer glow area respectively. Finally, through a two-level rendering method of outer glow rendering and character body rendering, it achieves a softer outer glow effect that extends further beyond the character outline. Attached Figure Description
[0024] Figure 1 This is a flowchart of the method of the present invention. Detailed Implementation
[0025] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.
[0026] Example
[0027] like Figure 1 As shown, an external glow method based on TextMeshPro is characterized by the following steps:
[0028] S1. Expand the vertex coordinates of the original characters and write the uv coordinates and width and height of the original characters; for example: write the u coordinates of the lower left and lower right corners of each character into one set of uv coordinates in the vertex data, and write the v coordinates of the lower left and upper left corners of each character into another set of uv coordinates in the vertex data, and write the display width and display height of each character into the normal of the vertex data; these vertex coordinates are used for the identification and correction of the original and expanded areas of subsequent characters;
[0029] S2, the edge frame formed by the uv coordinates of the original character is an inner frame, the vertex range of each original character is enlarged to form an outer frame, and the gap between the inner frame and the outer frame is an outer light-emitting area; the outer light-emitting can be outside the original character outline, that is, the outer light-emitting can be displayed outside the character outline (i.e. the outer light-emitting area);
[0030] Step S2 is specifically: adding an outer light-emitting area parameter (GlowScale parameter) to the text material of the character, the unit of the outer light-emitting area parameter is pixel, which is used to enlarge the display range of each character. For example: the display width and height of a single character is 40x40, the outer light-emitting area parameter is 10, then the center point position of the character does not change, and is enlarged by 10 pixels up, down, left and right, and the final display width and height is 60x60, the 10 pixels at the outermost periphery is the enlarged area, and the 40 pixels at the innermost periphery is the original area, that is, the character area. u and v are the coordinates of the picture in the horizontal and vertical directions of the display, the values are generally 0-1, that is, the u-th pixel in the horizontal direction / picture width, and the v-th pixel in the vertical direction / picture height.
[0031] S3, the surrounding pixel points of the current original character are corrected and sampled twice to obtain the transparency value of each sampling point;
[0032] S31, the uv coordinates of the original character are corrected for the first time, the edge frame of the original character is enlarged to coincide with the outer frame, thereby obtaining the enlarged character, and then the entire character body is sampled according to the corrected uv coordinates to obtain the transparency value of the character body; the uv coordinates of the original character are obtained from the uv coordinates in the vertex data in step S1.
[0033] The first correction is specifically: adding a character gap parameter (GlowGap) to the character material, the unit of the character gap parameter is pixel, which is used to represent the character gap, and the corrected uv coordinates after the first correction are respectively: Wherein, u, v represent the uv coordinates of the original character, normal.x represents the display width of the character; normal.y represents the display height of the character, and the character gap parameter takes a value of 0.11.
[0034] S32, the uv coordinates after the first correction are corrected for the second time to restore the character to the size of the original character, and the outer light-emitting area is sampled to obtain the transparency value of the outer light-emitting area;
[0035] For the second correction, the corrected uv coordinates are respectively:
[0036] u2 = remap(u, uv3.x + (uv3.y - uv3.x) * GlowScale / (2 * GlowScale + normal.x), uv3.y - (uv3.y - uv3.x) * GlowScale / (2 * GlowScale + normal.x), uv3.x, uv3.y); wherein, u, v represent the uv coordinates of the original character, remap represents a remapping function, uv3.x represents the u coordinate of the lower left corner of the character, uv3.y represents the u coordinate of the lower right corner of the character, GlowScale represents the outer glow area parameter, and normal.x represents the display width of the character.
[0037] v2 = remap(u, uv4.x + (uv4.y - uv4.x) * GlowScale / (2 * GlowScale + normal.x), uv4.y - (uv4.y - uv4.x) * GlowScale / (2 * GlowScale + normal.y), uv4.x, uv4.y); wherein, u, v represent the uv coordinates of the original character, remap represents a remapping function, uv4.x represents the v coordinate of the lower left corner of the character, uv4.y represents the v coordinate of the upper left corner of the character, GlowScale represents the outer glow area parameter, and normal.y represents the display height of the character.
[0038] In step S3, the sampling rule is that a sampling number parameter (GlowCount) and a sampling step parameter (GlowStep) are added to the text material, and then N sampling points around the current pixel point are sampled, and the number of sampling points N = 2 * sampling number * 2 * sampling step, wherein the sampling step represents the distance between the current pixel point and the sampling point. For example, the sampling number is 2, and the sampling step is 2, so the number of sampling points N is 16.
[0039] S4, the transparency values of the character body and the outer glow area obtained by sampling are averaged respectively to obtain the final character body transparency value and the outer glow area transparency value.
[0040] S5, set the color of the outer glow, and render the outer glow area according to the outer glow area transparency value to obtain the outer glow effect.
[0041] Step S5 is specifically: adding an outer glow color parameter (GlowColor) to the text material, which is used to specify a color different from the text.
[0042] S6, set the color of the character, and render the character area according to the character body transparency value to obtain the final character with the outer glow effect.
[0043] The above description is only preferred specific embodiments of the present application, but the protection scope of the present application is not limited thereto, any person skilled in the art can easily think of changes or replacements within the technical range disclosed by the present application, which should be covered in the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.
Claims
1. A TextMeshPro-based emissive light method, characterized in that: The method comprises the following steps: S1, extending the vertex coordinates of the original character, writing the uv coordinates and width and height of the original character; S2, the edge frame formed by the uv coordinates of the original character is an inner frame, the vertex range of each original character is expanded to form an outer frame, and the gap between the inner frame and the outer frame is an outer light-emitting area; S3, twice correction and sampling are performed on the surrounding pixel points of the current original character to obtain the transparency values of the sampling points; S31, the uv coordinates of the original character are corrected for the first time, the edge frame of the original character is expanded to coincide with the outer frame, thereby obtaining an expanded character, and then the entire character body is sampled according to the corrected uv coordinates to obtain the transparency value of the character body; S32, the uv coordinates corrected for the first time are corrected for the second time, the character is restored to the size of the original character, and the outer light-emitting area is sampled to obtain the transparency value of the outer light-emitting area; S4, the transparency values of the character body and the outer light-emitting area obtained by sampling are averaged respectively to obtain the final character body transparency value and the outer light-emitting area transparency value; S5, the color of the outer light-emitting is set, and the outer light-emitting area is rendered according to the outer light-emitting area transparency value to obtain the outer light-emitting effect; S6, the color of the character is set, and the character area is rendered according to the character body transparency value to obtain the final character with the outer light-emitting effect.
2. The TextMeshPro-based emissive light method of claim 1, wherein: Step S2 specifically is: adding an outer light-emitting area parameter to the text material of the character, the unit of the outer light-emitting area parameter is pixel, and the outer light-emitting area parameter is used to expand the display range of each character.
3. A TextMeshPro-based emissive light method as claimed in claim 2, wherein: In step S3, the sampling rule is: sampling N sampling points around the current pixel point, the number of sampling points N=2×sampling times×2×sampling step, wherein the sampling step represents the distance between the current pixel point and the sampling point.
4. The TextMeshPro-based emissive light method of claim 3, wherein: The first modification specifically adds a character gap parameter a to the character material, the unit of the character gap parameter is pixel, which is used to represent the character gap, and the first modified uv coordinates are respectively: Wherein, u, v represent the uv coordinates of the original character, normal.x represents the display width of the character; normal.y represents the display height of the character, and a represents the character gap parameter.
5. The TextMeshPro-based emissive light method of claim 4, wherein: The character gap parameter a takes a value of 0.
11.
6. The TextMeshPro-based emissive light method of claim 4, wherein: For the second correction, the corrected uv coordinates are respectively: u2=remap(u, uv3.x+(uv3.y-uv3.x)×GlowScale / (2×GlowScale+normal.x), uv3.y-(uv3.y-uv3.x)×GlowScale / (2×GlowScale+normal.x), uv3.x, uv3.y); wherein u and v represent the uv coordinates of the original character, remap represents a remapping function, uv3.x represents the u coordinate of the lower left corner of the character, uv3.y represents the u coordinate of the lower right corner of the character, GlowScale represents the outer light-emitting area parameter, and normal.x represents the display width of the character. v2 = remap(u, uv4.x + (uv4.y - uv4.x) * GlowScale / (2 * GlowScale + normal.x), uv4.y - (uv4.y - uv4.x) * GlowScale / (2 * GlowScale + normal.y), uv4.x, uv4.y); wherein, u, v represent the uv coordinates of the original character, remap represents a remapping function, uv4.x represents the v coordinate of the left lower corner of the character, uv4.y represents the v coordinate of the left upper corner of the character, GlowScale represents an emitted light area parameter, and normal.y represents the display height of the character.
7. The TextMeshPro-based emissive light method of claim 5, wherein: The step S5 specifically comprises: adding an emitted light color parameter to the text material, which is used to specify an emitted light color different from the text.
Citation Information
Patent Citations
Image processing method and device
CN112836467A
Electro-optic slate for direct entry and display and / or storage of hand-entered textual and graphic information
US5194852A