rendering – Adding lighting to custom vertex shader in Unity

What’s the simplest way to add shadow functionality based on the modified vertices, nothing I’ve found online seems to work

 Shader "Unlit/HyperUnlit"
 {
     Properties
     {
         _MainTex ("Texture", 2D) = "white" {}
         _Color("Color", Color) = (1,1,1,1)
     }
     SubShader
     {
         Tags { "RenderType"="Opaque" }
         LOD 100
 
         Pass
         {
             CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
 
             #include "UnityCG.cginc"
             #include "Complex.cginc"
 
             struct appdata
             {
                 float4 vertex : POSITION;
                 float2 uv : TEXCOORD0;
             };
 
             struct v2f
             {
                 float2 uv : TEXCOORD0;
                 UNITY_FOG_COORDS(1)
                 float4 vertex : SV_POSITION;
             };
 
             sampler2D _MainTex;
             float4 _MainTex_ST;
             fixed4 _Color;
 
             //Params
             float Tscale;
             float3 Tpos;
             float klein;
             float Rscale;
                 
             //Mobius Transformation (a,b,c,d)
             float2 a;
             float2 b;
             float2 c;
             float2 d;
 
             v2f vert (appdata v)
             {            
                 v2f o;
                 //Reduce to float3
                 float3 worldPos = mul(unity_ObjectToWorld, float4(v.vertex.xyz, 1)).xyz;
 
                 //2. Apply linear transformations
                 worldPos *= Tscale;
                 worldPos += Tpos;
 
                 //3. Apply mobius transformation    
                 worldPos = MobiusXZ(a,b,c,d, worldPos);
 
                 //4. Klein?
                 if (klein==1)
                 {
                     worldPos = PoincareToKlein(worldPos);
                 }
 
                 //5. Scale to disk radius
                 worldPos *= Rscale;
 
                 //Convert back to ? space
                 o.vertex = mul(UNITY_MATRIX_VP, float4(worldPos, 1));
 
                 //transform position to clip space
                 //o.vertex = UnityObjectToClipPos(v.vertex);
                 o.uv = TRANSFORM_TEX(v.uv, _MainTex);
 
                 return o;
             }
 
             fixed4 frag (v2f i) : SV_Target
             {
                 // sample the texture
                 fixed4 col = tex2D(_MainTex, i.uv) * _Color;
                 return col;
             }
             ENDCG
         }
         UsePass "Legacy Shaders/VertexLit/SHADOWCASTER"
     }
 }

javascript – React Map GL not rendering using create-react-app

I would use React Mapbox GL using create react app helper, but I cannot render the map.

I’ve followed This example, using that code it works, but I don’t know how to build the App, so I’d prefer to use CRA.

In the console I don’t have any errors, and yeah, the token is correct.

I’ve read somewhere that i have to use <MapGL /> instead of <MapGL> ... </MapGL>, but as you will see, I do have other components inside the map, and even removing it, it gives me this error: TypeError: null is not an object (evaluating 'context.viewport.zoom')

How can I solve?

Here is my App component:


import MapGL, {
  Popup,
  NavigationControl,
  FullscreenControl,
  ScaleControl, GeolocateControl,

} from 'react-map-gl';

...

 const (viewport, setViewport) = useState({
    latitude: 40,
    longitude: -100,
    zoom: 3.5,
    bearing: 0,
    pitch: 0
  });
  const (popupInfo, setPopupInfo) = useState(null);


return (            
  <MapGL
              {...viewport}
              width="100%"
              height="100%"
              mapStyle="mapbox://styles/mapbox/dark-v9"
              onViewportChange={setViewport}
              mapboxApiAccessToken={TOKEN}
            >
              <Suspense fallback={<div>Loading Events</div>}>
                <Pins onClick={setPopupInfo} />
              </Suspense>


              {popupInfo && (
                <Popup
                  tipSize={5}
                  anchor="top"
                  longitude={popupInfo.location.longitude}
                  latitude={popupInfo.location.latitude}
                  closeOnClick={false}
                  onClose={setPopupInfo}
                >
                  <EventsInfo info={popupInfo} />
                </Popup>
              )}

              <GeolocateControl style={geolocateStyle} />
              <FullscreenControl style={fullscreenControlStyle} />
              <NavigationControl style={navStyle} />
              <ScaleControl style={scaleControlStyle} />

              <GeolocateControl
                style={geolocateStyle}
                positionOptions={positionOptions}
                trackUserLocation
                auto
              />
            </MapGL> 
)

Cuda API to render using Physically Based Rendering (PBR) in OpenGL-ES based project

Thanks for contributing an answer to Game Development Stack Exchange!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

Use MathJax to format equations. MathJax reference.

To learn more, see our tips on writing great answers.

views – HOOK_views_pre_render() not rendering the updated results arraycorrectly

I have a D8 view with the main page display and created an embed display to get another dataset. I want to merge the result of both displays and make the embed display result sit at the very bottom, but, I don’t want to create an attachment instead of the embed display. So I wrote this piece of code to achieve this task:

function test_views_pre_render(ViewExecutable $view) {
  if($view->id() == 'courses' && $view->current_display == 'page_1') {
    $view2 = views_get_view_result('courses', 'embed_1');
    if(empty($view2)){
      return;
    }
    $view->result = array_merge($view->result, $view2);
  }
} 

When I check the result through xDebug I can see the view output contains the merged data. But, in the preview, I can only see 3 dots, which represent 3 items merged from the embed display onto the main display.

enter image description here

Surely a problem with rendering. Does anyone can see if I’m doing anything wrong here?. Thanks in advance for your help. Please excuse me about the question title.

An ECS rendering system – Game Development Stack Exchange

Thanks for contributing an answer to Game Development Stack Exchange!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

Use MathJax to format equations. MathJax reference.

To learn more, see our tips on writing great answers.

rendering – Java AWT drawing tiles laves gap

I am trying to make a tile based game in Java and I have noticed a problem with the drawing. There is about a one pixel gap between some of the tiles and I am not sure what is causing it.

Here is a screenshot of it:
https://i.stack.imgur.com/UbJ2B.png

Here is my code so far:

Main class:

package Game.main;

import javax.swing.JFrame;

public class Main {
    public static JFrame window;
    public static void main(String() args) {
        window = new JFrame();
        window.setVisible(true);
        window.setSize(1280, 720);
        window.setTitle("Game");
        window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Game game = new Game();
        window.add(game);
    }
}

Game class:

package Game.main;

import javax.swing.JPanel;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Color;

import java.util.ArrayList;

import Game.tile.Tile;

public class Game extends JPanel implements Runnable {

    public Game() {
        start();
    }

    boolean running = false;

    int width,height;

    ArrayList<Tile> tiles = new ArrayList<>();

    public void paint(Graphics g1) {
        //cast to graphics2d
        Graphics2D g = (Graphics2D)g1;
        //fill background
        g.setColor(Color.CYAN);
        g.fillRect(0, 0, width, height);
        //draw tiles
        for(int i = 0; i < tiles.size(); i++) {
            tiles.get(i).render(g, width, height);
        }
    }

    private void start() {
        Thread gameThread = new Thread(this);
        gameThread.start();
        //create start tiles
        for(int x = 0; x < 1000; x+=10) {
            for(int y = 700; y < 1000; y+=20) {
                Tile tile = new Tile(x, y);
                tiles.add(tile);
            }
        }
    }

    @Override
    public void run() {
        running = true;
        while(running) {
            //get window width and height
            requestFocus();
            width = Main.window.getWidth();
            height = Main.window.getHeight();
            //redraw current frame
            repaint();
        }
    }
}

Tile class:

package Game.tile;

import java.awt.Graphics2D;
import java.awt.Color;

public class Tile {
    public int x,y;
    public int w,h;
    public Tile(int x, int y) {
        this.x = x;
        this.y = y;
        this.w = 10;
        this.h = this.w*2;
    }
    public void render(Graphics2D g, int width, int height) {
        g.setColor(Color.GRAY);
        g.fillRect(this.x*width/1000, this.y*height/1000, this.w*width/1000, this.h*height/1000);
    }
}

```

Unity Project Settings: What is the difference between “Graphics -> SRP settings” and “Quality -> Rendering -> URP Asset”

As the title says, I am a bit confused about the aspect that the URP asset is referenced from two different settings:

  • Project Settings -> Graphics -> SRP settings
  • Project Settings -> Quality -> Rendering -> URP Asset

In a blank URP Project, “Project Settings -> Graphics -> SRP settings” references the HighQuality URP asset, and “Project Settings -> Quality -> Rendering -> URP Asset” has three different tiers, all of which reference their respective URP assed (i.e., either LowQuality, MediumQuality, or HighQuality.

Switching from one quality tier to another applies the respective URP asset, i.e., if I switch the quality tier to Low, the LowQuality URP asset is applied, even though the HighQuality is still set in “Project Settings -> Graphics -> SRP settings“.

So now the question: Why do I have to set a URP asset in “Project Settings -> Graphics -> SRP settings” if it seems that it is overridden by the URP asset defined in the quality tab?

How to use conditional rendering in Tsx file (React +Typescript)

I want to use condition in my Task -Status if value is 0 then "Not-Started" elseif value is 50 then in "In-progress" else "Completed"

Now I am using TaskStatus with value like 0,50,100

I am fetching the data through Graph API

enter image description here

Here is my code "item.percentcomplete" is having the value of tasks-status as 0,50,100

<h2>All Planner Tasks </h2>
    <table id="customers">
      <tr>
        <td>Task-Status</td>
        <td>Task-Name</td>
        <td>Start Date</td>
         <td>End Date</td>

      </tr>
      
      {
      
        this.state.events.map((item, key) =>
          <tr>
            <td id = "status">{item.percentComplete}</td>
            <td><a href ='https://tasks.office.com/credentinfotech.com/en-GB/Home/Planner/#/userboard '>{item.title}</a></td>
            <td>{moment(item.startDateTime).format('MM/DD/YYYY ')}</td>
            <td>{moment(item.dueDateTime).format('MM/DD/YYYY')}</td>
          </tr> )
      
      }

    </table>

javascript – Images not rendering correctly on render component from Slick

I have an issue whenever I click on a product that rendering a product view component, images keeps showing previous product images until I refresh the page!

productView.vue

<div 
   v-if="product.similar_products && product.similar_products.length > 0"
   id="similar-products-tab"
   role="tabpanel"
   class="tab-pane active"
>
   <SimilarProducts
     :data="product.similar_products"
     :listing="'similar_products'">
   </SimilarProducts>
</div>

SimilarProducts.vue

<template>
    <section class="similar-products" :class="'section-'+listing">
        <div class="container">
            <div class="text-center">
                <div class="similar-products-wrapper">
                    <slick
                        ref="similarProductsSlick"
                        :options="slickOptions"
                        v-if="show"
                        @beforeChange="handleBeforeChange"
                    >
                        <div
                            v-for="(item, index) in data"
                            :key="item.id"
                        >
                            <div class="panel panel-default product">
                                <div class="panel-body">
                                    <ProductCard v-bind:product="item"
                                        :listing="listing"
                                        :lazy-load="lazyLoadCard(index)"
                                        :id="listing+'-'+item.id">
                                    </ProductCard>
                                </div>
                            </div>
                        </div>
                    </slick>
                </div>
            </div>
        </div>
    </section>
</template>

<script>
    import Slick from 'Slick/Slick.vue';
    import {slick_mixins} from 'appUtl';
    import similar_products_mixins from '../mixins/similar_products';
    import ProductCard from './ProductCard.vue';

    export default {
        props: ('data', 'listing'),
        mixins:(slick_mixins, similar_products_mixins),
        components: {
            Slick,
            ProductCard,
        },
        data() {
            return {
                show: true,
                slickOptions: {
                    dots: false,
                    infinite: false,
                    adaptiveHeight: true,
                    autoplay: false,
                    slidesToShow: 4,
                    slidesToScroll: 4,
                    responsive: (
                        {
                            breakpoint: 992,
                            device:'tablet',
                            settings: {
                                slidesToShow: 3,
                                slidesToScroll: 3
                            }
                        },
                        {
                            breakpoint: 768,
                            device:'mobile',
                            settings: {
                                slidesToShow: 2,
                                slidesToScroll: 2
                            }
                        }
                    )
                },
                minLazyLoadIndex: (window.matchMedia("(max-width: 480px)").matches) ? 1 : 3
            };
        }
    }
</script>

similar_products_mixins.js

export default {
    methods: {
        next() {
            this.$refs.similarProductsSlick.next();
        },
        prev() {
            this.$refs.similarProductsSlick.prev();
        },
        reInit() {
            this.$nextTick(() => {
                this.$refs.similarProductsSlick.reSlick();
            });
        },
        getItems:function () {
            if(!this.data)
                return ();
        },
        reRenderSlick(){
            this.show = false
            this.$nextTick(() => {
                this.show = true
                this.$nextTick(() => {
                    $(".unveil-img").unveil();
                })
            })
        },
        lazyLoadCard:function (index) {
            return (index > this.minLazyLoadIndex && this.data.lazy_load);
        },
        handleBeforeChange(event, slick, currentSlide, nextSlide){
            if(nextSlide <= this.minLazyLoadIndex || !this.data.lazy_load)
                return;

            let slidId = '.product-item-card-'+this.listing+'-'+nextSlide+' .lazy-unveil-img';
            if($(slidId).attr('data-src') && $(slidId).attr('data-src').trim().length > 0) {
                $(slidId).attr('src', $(slidId).attr('data-src'));
                $(slidId).attr('data-src', null);
            }
        }
    },
    updated() {
        if(this.$store.getters.isEditingMode) {
            if (this.data.reSize) {
                this.data.reSize = false;
                this.reRenderSlick();
            } else {
                this.reInit();
            }
        }
    },
    mounted() {
        if(!this.$store.getters.isEditingMode) {
            setTimeout(() => {
                this.$refs.similarProductsSlick.play();
            }, 600);
        }
    }
}

I was having same issue in another component, and solved by commenting this.$refs.similarProductsSlick.play(); + using v-once to render the SimilarProducts component as it was having multiple rendering. However, I tried to fix the similar issue here but nothing worked.

javascript – Rendering delay in Three.js

We are trying to build a web application for hand tracking and then rendering the results in three.js.

Hand tracking part is returning a frame almost every 40 ms (30 fps). We are using these results to change positions of created cubes in three.js.

The issue is that we are having a delay between the changing of the position and rendering the new position on the screen. Are we missing something here? or is it the normal expected performance from three.js

below are some description snapshots for the issue:

full js code:

import React from "react";
import * as THREE from "three";

interface ContainerProps {
  results: Object() | any;
}


class ThreeJSCanvas extends React.Component<ContainerProps> {
  state = {
    results: Object(),
    prevResults: Object(),
  };

  scene: THREE.Scene;
  camera: THREE.Camera;
  raycaster: THREE.Raycaster | undefined;
  mouse: THREE.Vector2 | undefined;
  renderer: THREE.WebGLRenderer | undefined;
  handObjects: Array<number>;
  canvasWidth: number = 1280;
  canvasHeight: number = 720;

  private constructor(props: any) {
    super(props);
    this.scene = new THREE.Scene();
    this.camera = new THREE.PerspectiveCamera(75, 1280 / 720, 0.1, 1000);
    this.handObjects = new Array<number>();
  }

  componentDidMount() {
    this.initialize();
    this.createCubes();
  }

  componentDidUpdate() {
    if (this.props.results !== this.state.results) {
      this.setState({
        prevResults: this.state.results,
        results: this.props.results,
      });
      this.updateCubesPosition();
    }
  }
  initialize() {
    this.scene = new THREE.Scene();
    this.raycaster = new THREE.Raycaster();

    this.camera = new THREE.OrthographicCamera(
      this.canvasWidth / -2,
      this.canvasWidth / 2,
      this.canvasHeight / 2,
      this.canvasHeight / -2,
      0.1,
      1000
    );
    let canvas = document.getElementById("threeJS-canvas") as HTMLCanvasElement;

    this.renderer = new THREE.WebGLRenderer({ canvas, alpha: true });
    this.renderer.setSize(1280, 720);
    document.body.appendChild(this.renderer.domElement);

    this.camera.position.z = 10;
    this.animate();
  }

  animate() {
    requestAnimationFrame(this.animate.bind(this));
    this.renderer?.render(this.scene, this.camera);
  }

  createCubes() {
    for (let i = 0; i < 21; i++) {
      let cube = this.addObject(1, 0, 0);
      this.handObjects?.push(cube);
    }
  }

  updateCubesPosition() {
    for (let i = 0; i < this.state.results?.length; i++) {
      let obj = this.scene.getObjectById(this.handObjects(i));
      let pos = this.state.results(i);
      let x = pos.x * this.canvasWidth - this.canvasWidth / 2.0;
      let y = this.canvasHeight / 2.0 - pos.y * this.canvasHeight;
      obj?.position.set(x, y, 1);
    }
  }

  addObject(x: number, y: number, z: number): number {
    let box = new THREE.BoxGeometry(5, 5, 5);
    let mat = new THREE.MeshBasicMaterial({ color: this.randomColor() });
    let newCube = new THREE.Mesh(box, mat);
    newCube.position.x = x;
    newCube.position.y = y;
    newCube.position.z = z;
    this.scene.add(newCube);
    return newCube.id;
  }

  rand(min: any, max: any) {
    if (max === undefined) {
      max = min;
      min = 0;
    }
    return min + (max - min) * Math.random();
  }
  randomColor() {
    return `hsl(${this.rand(0, 360) | 0}, ${this.rand(50, 100) | 0}%, 50%)`;
  }

  render() {
    return (
      <div>
        <canvas className="bottom" id="threeJS-canvas"></canvas>
      </div>
    );
  }
}
export default ThreeJSCanvas;